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.

Requirements:

  • You are using Vim 7
  • You know how to install plugins
  • You know how to configure Vim (via .vimrc)
  • You know and have chosen a mapleader

Check out Vim documentation if you need help.

The idea

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:

  • Every Vim window has its own session. Vim yanking and pasting isn't possible.
  • Buffer completion gets useless since you only have one buffer open.
  • Every Vim window has its own undo session.
  • Most O/S window managers suck...
  • etc.

Here is how my Vim looks like and what we are aiming at:

General idea

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...

Using tabs

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:

Intro to cmd surfing

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:

set wildmenu

This will display command-line results in a wild menu :) After this is done go to command line mode and do this:

:e ~/Desktop/<CTRL-D>

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.

Lovely mappings

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
© Amir Salihefendic