My .vimrc

For those of you who are not familiar with vim (shame on you), it is a marvelously powerful text editor, which I use for coding and text editing in general (Latex, html, rails, ruby, etc). The only exception is scheme, for which I use DrScheme, but that is another story.

Anyway, .vimrc is the file that sits on your home directory and configures the state your vim will be. Here is mine for the curious.

  1 " An example for a gvimrc/vimrc file.
  2 " The commands in this are executed when the GUI or vim is started.
  3 "
  4 " Maintainer:   Bram Moolenaar <Bram@vim.org>
  5 " Last change:  2001 Sep 02
  6 "
  7 " To use it, copy it to
  8 "     for Unix and OS/2:  ~/.gvimrc
  9 "             for Amiga:  s:.gvimrc
 10 "  for MS-DOS and Win32:  $VIM\_gvimrc
 11 "           for OpenVMS:  sys$login:.gvimrc
 12
 13 " Make external commands work through a pipe instead of a pseudo-tty
 14 "set noguipty
 15
 16 " set the X11 font to use
 17 " set guifont=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1
 18
 19 " Switch on syntax highlighting if it wasn't on yet.
 20 if !exists("syntax_on")
 21     syntax on
 22 endif
 23
 24 "SETTINGS
 25 "
 26 set ch=2                " Make command line two lines high
 27 set mousehide           " Hide the mouse when typing text
 28
 29 "sets the default grepping engine to be ack-grep with the -a flag
 30 "change this to --ruby or some other stuff for searching only ruby
 31 "use it like this
 32 ":grep Dumper perllib
 33
 34 set grepprg=ack-grep\ -a 
 35
 36
 37 " Switch on search pattern highlighting.
 38 set hlsearch
 39
 40 "display current info all the time
 41 set ruler
 42
 43 colorscheme twilight
 44
 45 "prettier font...
 46 set guifont=Liberation\ Mono\ 12 
 47
 48 " those next 2 commands are taken from a tip in http://vim.sourceforge.net/tips/tip.php?tip_id=259
 49 " They basically map to keys F1 -> toogle menu; F2 -> toggle toolbar
 50
 51 " get rid of toolbar
 52 set guioptions-=T
 53 :let g:toggleTool = 0
 54 map <silent> <S-F2> :if g:toggleTool == 1<CR>:set guioptions-=T<CR>:set lines+=3<CR>:let g:toggleTool = 0<CR>:else<CR>:set lines-=3<CR>:set guioptions+=T<CR>:let g:toggleTool = 1<CR>:endif<CR> 
 55
 56 " get rid of menu
 57 set guioptions-=m
 58 :let g:toggleMenu = 0
 59 map <silent> <S-F1> :if g:toggleMenu == 1<CR>:set guioptions-=m<CR>:set lines+=1<CR>:let g:toggleMenu = 0<CR>:else<CR>:set guioptions+=m<CR>:let g:toggleMenu = 1<CR>:endif<CR>
 60
 61 "line numbers please...
 62 set number
 63
 64 "set the incremental search
 65 set incsearch
 66
 67 "remember more history
 68 set history=500
 69
 70 "Generally the :substitute command changes only the first occurrence of the word
 71 "unless you use the 'g' option.To make the 'g' option the default use this:
 72 set gdefault
 73
 74 "this is for vim omni completion of ruby code. Check out :help new-omni-completion or :help ft-ruby-omni
 75 let g:rubycomplete_buffer_loading = 1
 76 let g:rubycomplete_classes_in_global = 1
 77 let g:rubycomplete_rails = 1
 78
 79
 80 "*****************************************************************************************************
 81 "*****************************************************************************************************
 82 "*****************************************************************************************************
 83 "
 84 "MAPPINGS
 85 "
 86 "
 87 " Make shift-insert work like in Xterm
 88 map  <S-Insert> <MiddleMouse>
 89 map! <S-Insert> <MiddleMouse>
 90 "this pastes what's copied, not what is selected
 91 map  <leader><ESC>"+gp
 92 map  <leader>c "+y
 93
 94 map  <leader>n :vnew<CR>
 95
 96 "reload vim configuration automatically whenever I edit it
 97 "found here http://dailyvim.blogspot.com/2008/11/reload-vimrc.html?showComment=1228044660000#c2642014041159858949
 98 au! BufWritePost $MYVIMRC source %
 99
100 "this maps to James Buick's FuzzyFinder: TextMate plugin
101 "Found here http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim
102 map <leader>t :FuzzyFinderTextMate<CR>
103
104 "minibufexpl plugin http://www.vim.org/scripts/script.php?script_id=159
105 let g:miniBufExplMapWindowNavVim=1
106 let g:miniBufExplMapWindowNavArrows=1
107 let g:miniBufExplMapCTabSwitchBufs=1
108 set hid "Hide abandoned buffers in order to not loose undo history (taken from http://heykevinle.blogspot.com/2007/06/vim-minibufexpl.html)
109
110 " this is a shortcut to the minibufexplorer
111 map <Leader>b :MiniBufExplorer<cr>
112             
113 " SPELLING OPTIONS
114 "
115 "set the spell checker for txt, html, README and tex files
116 autocmd BufNewFile,BufRead *.txt,*.html,README,*.tex,*.story setlocal spell spelllang=en_us
117 "autocmd BufNewFile,BufRead *.txt,*.html,README,*.tex setlocal spell spelllang=pt
118
119 map <F2> :setlocal spell spelllang=en_us<CR>
120 map <F3> :setlocal spell spelllang=pt<CR>
121
122 "popup the a menu on mispelled words with the mouse
123 set mousemodel=popup
124
125 set textwidth=80
126
127 "found those on http://wiki.rubyonrails.org/rails/pages/HowtoUseVimWithRails
128 filetype plugin indent on " Enable filetype-specific indenting and plugins
129 augroup myfiletypes
130     " Clear old autocmds in group
131     autocmd!
132     " autoindent with two spaces, always expand tabs. For other types of
133     " identation, add new file types.
134     autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 bs=2 et
135     " if not any of those files, fall to the default
136     set ai sw=2 sts=2 bs=2 et
137 augroup END
138
139 "Autoidenting ruby code using the kode gem. Found on http://antono.info/en/50
140 nmap <leader>rci :%!ruby-code-indenter<cr>
141
142 "map the leader c key to the buffer delete
143 nmap <leader>d :bd<cr>
144
145 "write the buffer
146 nmap <leader>w :w<cr>
147
148 "write all the  buffers
149 nmap <leader>wa :wa<cr>