I love Vim – 4 Tips when using Vim

I love Vim. It is my favorite text editor. In fact, there are times where it makes editing code a lot of fun. It is difficult to learn at first, but there are a ton of great resources to get you started. A few can be found at:

The first two links will help you get started moving around and editing within Vim. The other two will give you tips and hints to do common tasks quickly. Here are a few tips that I find myself constantly using these days when working. I also think these are good tips for people who are starting out with Vim.

1) Use the Wildmenu

set wildmenu

When this option is turned on the using tab for command-line completion will also display all the possible matches on your status line. You can then tab through those matches and select the one you are looking for. It can match on just about anything you can type as a command. For example type “:col” and hitting tab will display colder and colorscheme. Typing “:colorscheme a” and hitting tab will list all the colorschemes that start with a. This gets really handy when typing out long directory paths as it will list files and directories of the current path you are typing (and save you from having to type the entire thing out yourself).

2) Easily open files in the same directory

cabbr <expr> %% expand('%:p:h')

This will make %% expand to the current path of the file you are editing. This keeps you from having navigate the full path when the files you are editing are not in the current directory, but are in the same directory as each other. Take a look at the Vim Tips Wiki for more details about this.

3) Enable Ctrl-V and Ctrl-C for the clipboard

map <C-V> "+gP
cmap <C-V> <C-R>+
vnoremap <C-C> "+y

This makes it easy to cut and paste to and from Vim to other applications using the standard Ctrl-C and Ctrl-V shortcuts

4) Extensions to make life better

Mini Buffer Explorer – This extension will list your open buffers in a window for you allowing you to glance at the buffer number and ‘:b#’ to change the current file you’re editing. This extension alone has reduced my reliance on the mouse more than any other. Before I started using this extension I would open all of my files in tabs and use the mouse to switch to different tabs.

SuperTab – Autocomplete is about the only feature I would say that I miss from not using a “true” IDE. Fortunately this extension provides very similar functionality, and for my purposes it improves on it. Whenever you are typing a word/variable if you hit tab it will find the nearest match and/or display a list of possible completions. It quick, stays out of my way unless called upon, and does not require some crazy indexing/tracking of all files in my current project to work.

These are probably the most important things I use beyond the basic movements and commands already provided in Vim. Hopefully they will help out anyone who is new to Vim or for anyone looking on how to make Vim easier to work in.

2 Responses to “I love Vim – 4 Tips when using Vim”

  1. Brad says:

    Do you use mouse-mode with copy/paste, or visual mode in vim?

    I’m getting by with shift-v, d, p to move blocks of code, but ctrl-c and ctrl-v would be much better, especially with other apps.

  2. John says:

    I use the keyboard for vim. If I a m planning on using a cut/paste action inside of vim I will use shift-V, p, y, whatever fits the situation best. I only use Ctrl-V and Ctrl-C to paste into or copy out of vim. This is because y and d only copy to vim’s internal set of copy/paste registers and not the system’s clipboard (so shift-v, y and then ctrl-v in another application does not work).

Leave a Reply