Workspace efficiency - Vim tip 1 of 3
This is my first tip for advance usage of the Vim editor. It's meant for people that are already comfortable with Vim.
Check out Vim documentation if you need help.
The general idea is to have a workspace! This is crucial if you use one Vim window. You can use multiple Vim windows, but this has a number of drawbacks:
Here is how my Vim looks like and what we are aiming at:
Getting mini buffer explorer
This is a little script that lets you explore your buffers. I use it to have an overview over what files are currently open.
Download from Vim's site minibufexpl.vim. There is a guide on how to install it. My configuration of this script (place this inside your .vimrc file):
let g:miniBufExplModSelTarget = 1 let g:miniBufExplorerMoreThanOne = 0 let g:miniBufExplModSelTarget = 0 let g:miniBufExplUseSingleClick = 1 let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplVSplit = 25 let g:miniBufExplSplitBelow=1 map <c-w><c-t> :WMToggle<cr>
It's crucial that you know how to delete (close) buffers - without closing the window. If you don't: Deleting a buffer without closing the window...
I use Vim tabs when I am working on different parts of the same problem domain. For C you would have one tab for a header and another for the actual code. In MVC architecure you could have 3 tabs: view, controller and model. Etc.
To make it convinient here are my tab hotkeys:
map <leader>tn :tabnew %<cr> map <leader>tc :tabclose<cr> map <leader>tm :tabmove
Now to open a new tab you just type ,tn in normal mode. My mapleader is ,.
Command line surfing
Vim command line is very powerful. I only use the command line to locate files, and I am pretty happy with the efficiency.
An animation (and introduction) of how I locate files and directories:
Command line completion
Vim has excellent documentation, read about command line compeltion here. Ok, you read it? Well, notice Ctrl-D hotkey... This one is really nice :)
Before I come with an example, put this in your .vimrc:
This will display command-line results in a wild menu :) After this is done go to command line mode and do this:
CTRL-D is of course Control and D pressed togheter. Watch the result and I think you will have a pretty good understanding why CTRL-D is useful.
Notice: CTRL-D isn't the same as tab completion. Tab completions completes, CTRL-D shows you the available completions.
To speed things up I use some mappings, here are some really simple and useful command line mappings:
cno $h e ~/ cno $d e ~/Desktop/ cno $$ e ./
I.e. pressing $d prints out e ~/Desktop/! Notice: I have remapped the key below ESC to $, so pressing $ is lighting fast!
9. Aug 2006 • VIM Editor