Vim Fun

Last month I attended VimChi which is the Vim users group based here in Chicago. I was using Vim in earnest for a few months before the meeting, I love it and I was excited to go. I met some great people, all with a love of using Vim and figuring out it’s quirks. We discussed tags as well as using buffers. Tags are still somewhat of a mystery to me but I have been using buffers pretty frequently now.

The beauty about buffers and using Vim’s built in netrw is that it somewhat eliminates the need for NerdTree or other such tools and encourages you to jump around between files vs focusing on navigating multiple tabs. Being able to reopen files via a buffer is quite handy, and I am happy to say this is all I use at this point. Github user jbranchaud has a nice gist based on his presentation related to buffers:

This coupled with using vertical splits in Vim have been pretty useful. As I played around here are some things I learned regarding split windows:

So far, I prefer a vertical split.

From within vim you could always do :vsp FILENAME/DIRECTORY. This will open the new file or directory in a split window alongsid your current file.

In netrw, highlight the name of the file or directory and hit v.

To open an existing buffer in a split try :vert sb BUFFER NUMBER/NAME.

Note on window width: I like to keep my line length at 80 (though i’m considering 100). What I typically do is start my terminal window at 160 width, then when I vertical split I do Ctrl + w = to set both windows to equal length(80 each).

Some .vimrc changes to consider

By default, the split opens to the left of the current window, which I dont find as intuitive. Adding the following to .vimrc will make it open to the right:

set splitright

Normally to navigate between split windows you would have to do Ctrl + W then h, j, k, or l depending on which direction you’re going. With this remap, it would be a matter of just doing Ctrl + l to go to the right panel or Ctrl + h to go back to the left panel.

nnoremap <C-J> <C-W><C-J>

nnoremap <C-K> <C-W><C-K>

nnoremap <C-L> <C-W><C-L>

nnoremap <C-H> <C-W><C-H>

As I continue to play around and hit my head against other tricks I’ll do more updates, so far splitting windows and buffers have been a great step towards happy Vimming!

Written on April 17, 2015