Quite possibly the most useful vim shortcut I have
I use these every single day:
noremap <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR> noremap <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR> noremap <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR> noremap <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
These make it much easier to open files next to the file in the current buffer. For instance, if I run the command “vi /etc/puppet/manifests/modules/foo/bar.pp” and I need to edit a file in the same directory as bar.pp, I just type ,ew and at the bottom of my vim window this appears:
With the cursor at the end, waiting for me to type the filename or just hit enter so I can use NERDTree to select a file visually. The other mappings open splits or tabs, allowing me to easily select where new file shows up.
This morning, I discovered an interesting side effect to this command. I ran “vi http://mbostock.github.com/d3/ex/unemployment.json" to see what the json data for this cloropleth was. Then, to see what the us-counties.json file had in it, I just hit ,ew and the following showed up at the bottom of my vim window:
One more thing. These mappings are directly from this vimcasts episode. If you haven’t watched all the vimcasts episodes, then you’re missing out on some great content.