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.
- Download it from http://www.vim.org/scripts/download_script.php?src_id=17123
- Unzip into your .vim directory
- 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.
- Download the vim plugin for cscope from http://cscope.sourceforge.net/cscope_maps.vim
- Place the plugin in your .vim/plugin directory
- 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
- Download the plugin from http://www.vim.org/scripts/script.php?script_id=3150
- Place it in your .vim/plugin directory
- 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