Some useful vim plugins and keymaps

Over the years I have used couple of fancy plugins and key mappings but here I am listing a few which are almost always required. Everytime setting it up from scratch becomes a pain so I am listing it here so that I can just do copy paste directly from my blog and in general if it is useful to anyone else.

  • NerdTree
    1. Download it from http://www.vim.org/scripts/download_script.php?src_id=17123
    2. Unzip into your .vim directory
    3. In your .vimrc you can have the following key maps
map <F2> :NERDTree<CR>
let NERDTreeIgnore = ['\.pyc$', '\.lo$', '\.o$', '\.la$']

The first one maps F2 key to open up the NerdTree Browser and the second one does not show the binary object, .pyc files.

nnoremap <silent> <C-Right> <c-w> l
nnoremap <silent> <C-Right> <c-w> h 
nnoremap <silent> <C-Right> <c-w> k 
nnoremap <silent> <C-Right> <c-w> j

These keymaps make it easier to do move from one window to another when multiple windows are open. I find it an extra key to be pressed for moving using ctrl + w and then pressing the arrows or jklh keys. Moreover due to overuse (specially because of ALT + Tab) my thumbs start to ache and pressing CTRL + w requires pressing CTRL from my thumb and w using one of my finger. So to avoid using my thumb I find this mapping quite better.

  • Cscope
      1. Download the vim plugin for cscope from http://cscope.sourceforge.net/cscope_maps.vim
      2. Place the plugin in your .vim/plugin directory
      3. Now you can generate the files for which you want to search in and build the database. I generally store the cscope database and generated files in a separate directory in home. And then I run the cscope pointing to the cscope.files or the projectname.files and generate the cscope database files also in the ~/cscope directory. Finally I create a couple of scripts in my ~/bin directory to set the CSCOPE_DB environment variable to point to the cscope database file for each project.
mkdir ~/cscope
find full-path-to-project -name "*.[ch]" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.hpp" > ~/cscope/projectname.files
cscope -i ~/cscope/projectname.files -q -k -b -f ~/csope/projectname.out
export CSCOPE_DB=~/cscope/projectname.out
  • Session Saver plugin
    1. Download the plugin from http://www.vim.org/scripts/script.php?script_id=3150
    2. Place it in your .vim/plugin directory
    3. That’s all. Everytime you open vim without specifying file, it will ask you to open your last saved session and when you quit vim, it will ask you to save your session. If you don’t want it to automatically load or save your session then you can set the following in your .vimrc
let g:session_autosave = 'no'
let g:session_autoload = 'no'

Apart from this some of the settings that I generally keep in my .vimrc are:

syntax on
filetype plugin indent on
set expandtab
set sw=4
set ts=4
set textwidth=80
set autoindent
autocmd BufEnter * lcd %:p:h

set wildignore=*.o,*.swp,*.pyc,*.svn,*.git
set title
Advertisements

One thought on “Some useful vim plugins and keymaps

  1. Pingback: Links 2/6/2013: Arch Linux 2013.06.01, Slackpkg | Techrights

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s