Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

A Custom Vim Mapping to Copy a Buffer's File Path to Your Clipboard

blog/cards/a-custom-vim-mapping-to-copy-a-buffers-file-path-to-your-clipboard.jpg

Sometimes quickly copying a file's relative path is exactly what you need. Here's one way to do that.

Quick Jump: Demo Video

You can use this for a lot of things but my primary use case is around cross linking blog posts on this site which uses Jekyll (a static site generator).

Jekyll provides a {% post_url %} template tag where you pass in the relative file path of the post you want to link. Whenever I want to cross link a post I open the file, quickly hit this new cp mapping and paste it into the tag’s value with a minor amount of touching up.

Here’s the mapping: nmap cp :let @+ = expand("%")<CR>.

The video below goes into a bit more details on how it works and how I’m using it.

Demo Video

Timestamps

  • 0:10 – Demonstrating 1 potential use case with Jekyll
  • 1:33 – Going over the Vim mapping in my vimrc file

How do you quickly copy file paths in Vim? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments