My Custom .vimrc file for VIM [updated]

Vim (text editor) in a terminal emulator, with...

Image via Wikipedia

Vim is a good editor, made great with a custom .vimrc file.

My .vimrc file adds syntax highlighting, autocomplete with tab, folding and highlights the line you are on.

Feel free to use or modify it for your needs.

Original Post, June 2 2008, Updated Oct 1 2009

VIM

I have a love hate relationship with VIM. I am extremely productive using it, yet I still think there must be a better editor out there. Despite years of trying out other editors, I always come back to vim. Quanta Plus was close, and notepad++ works well on windows, but I always ending up typing a lot of unnecessary j’s and k’s ;)

My .vimrc

Updated July 30, 2008

  1. " ****************** <span class="caps">INITIALIZE</span> *******************
  2. set nocompatible " must be first line
  3. filetype plugin indent on " Automatically detect file types.
  4. syntax on " syntax highlighting
  5.  
  6. " ****************** <span class="caps">VISUAL</span> *******************
  7. color ir_black " load a colorscheme
  8.  
  9. set cursorline " highlight current line
  10. hi cursorline guibg=#333333 " highlight bg color of current line
  11. hi CursorColumn guibg=#333333 " highlight cursor
  12.  
  13. if has('cmdline_info')
  14. set ruler " show the ruler
  15. set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " a ruler on steroids
  16. set showcmd " show partial commands in status line and
  17. " selected characters/lines in visual mode
  18. endif
  19.  
  20. if has('statusline')
  21. set laststatus=1 " show statusline only if there are &gt; 1 windows
  22. set statusline=%&lt;%f\ %=\:\b%n%y%m%r%w\ %l,%c%V\ %P " a statusline, also on steroids
  23. endif
  24.  
  25. " <span class="caps">GVIM</span>- (here instead of .gvimrc)
  26. if has('gui_running')
  27. set guioptions-=T " remove the toolbar
  28. set lines=40 " 40 lines of text instead of 24,
  29. endif
  30.  
  31. " ****************** <span class="caps">ENVIRONMENT</span> *******************
  32. set backspace=indent,eol,start " backspace for dummys
  33. set showmatch " show matching brackets/parenthesis
  34. set wildmenu " show list instead of just completing
  35. set wildmode=list:longest,full " comand <tab> completion, list matches, then longest common part, then all.
  36. set shortmess+=filmnrxoOtT " abbrev. of messages (avoids 'hit enter')
  37. set showmode " display the current mode
  38. " set spell " spell checking on
  39. set nu " Line numbers on
  40. set tabpagemax=15 " only show 15 tabs
  41. set incsearch " find as you type search
  42. set hlsearch " highlight search terms
  43. set winminheight=0 " windows can be 0 line high
  44. set autowrite
  45. set whichwrap=b,s,h,l,&lt;,&gt;,[,] " backspace and cursor keys wrap to
  46. set ignorecase " case insensitive search
  47. set smartcase " case sensitive when uc present
  48. set backup " backups are nice
  49. set backupdir=$<span class="caps">HOME</span>/.backup " but they clog cwd
  50. set backupdir=~/.backup,~/tmp,.,/tmp"}}}
  51. set scrolljump=5 " lines to scroll when cursor leaves screen
  52. set scrolloff=3 " minimum lines to keep above and below cursor
  53. set foldenable " auto fold code
  54. "set foldmethod=marker " type of folding
  55. "set foldclose=all
  56. "set writebackup
  57.  
  58. " ****************** <span class="caps">FORMATTING</span> *******************
  59. " Formatting
  60. set nowrap " wrap long lines
  61. set autoindent " indent at the same level of the previous line
  62. set shiftwidth=4 " use indents of 4 spaces
  63. set noexpandtab " tabs are tabs, not spaces
  64. set tabstop=4 " an indentation every four columns
  65. "set matchpairs+=&lt;:&gt; " match, to be used with %
  66. set pastetoggle=<f12> " pastetoggle (sane indentation on pastes)
  67. "set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks
  68.  
  69. " ****************** <span class="caps">GENERAL</span> <span class="caps">SHORTCUTS</span> *******************
  70. map <c-l> <c-w>_
  71. map <c-j> <c-w>j<c-w>_
  72. map <c-k> <c-w>k<c-w>_
  73. map <s-h> gT
  74. map <s-l> gt
  75.  
  76. " Stupid shift key fixes
  77. map:W :w
  78. map:<span class="caps">WQ</span> :wq
  79. map:wQ :wq
  80. map:Q :q
  81.  
  82. autocmd BufEnter * lcd %:p:h " change directory the current file's
  83. "autocmd BufWritePost .vimrc source %
  84.  
  85. " ****************** <span class="caps">CODING</span> *******************
  86.  
  87. if has("autocmd") &amp;&amp; exists("+omnifunc")
  88. autocmd Filetype *
  89. \if &amp;omnifunc == "" |
  90. \setlocal omnifunc=syntaxcomplete#Complete |
  91. \endif
  92. endif
  93.  
  94. set completeopt+=menuone " show preview of function prototype
  95.  
  96. " ****************** <span class="caps">PLUGINS</span> *******************
  97. :map <c-f10> <esc>:vsp<cr>:VTree<cr>
  98. " map Control + F10 to Vtree
  99.  
  100. let g:checksyntax_auto = 0
  101.  
  102. "comment out line(s) in visual mode
  103. vmap o :call NERDComment(1, 'toggle')<cr>
  104. let g:NERDShutUp=1
  105.  
  106. let b:match_ignorecase = 1
  107.  
  108.  
  109.  
  110. </cr></cr></cr></esc></c-f10></s-l></s-h></c-w></c-w></c-k></c-w></c-w></c-j></c-w></c-l></f12></tab>

See Also

External Resources