Saturday 26 November 2011

My .vimrc file

My .vimrc file is below. I use the following plugins: ack.vim, color_sample_pack.vim, easytags.vim, endwise.vim, external.vim, matchit.vim, mru.vim, NERD_commenter.vim, ragtag.vim, rails.vim, repeat.vim, SearchComplete.vim, session.vim, shell.vim, supertab.vim, surround.vim, taglist.vim, yankring.vim.

  1  " Praful's .vimrc file. Used in Windows gvim mainly. 
  2  " I got this initially from 
  3  "   Maintainer: www.swaroopch.com/contact/
  4  "   Reference: Initially based on http://dev.gentoo.org/~ciaranm/docs/vim-guide/
  5  "   se current buffer
  6  "   License: www.opensource.org/licenses/bsd-license.php
  7  " but have since made many changes.
  8  "
  9  " History (Praful):
 10  "   20110429 - commented out "set number" since it conflicts with "set relativenumber"
 11  "   20110710 - add easytag options
 12  "            - disable relativenumber: it's annoying
 13  "   20110918 - change colour scheme to "evening"
 14  "            - remove /v substituion for grep since it doesn't always work well.
 15  "            - use yankring function to map Y to y$ since prev def was being overridden.
 16  "            - add mappings for tab windows
 17  "            - remove reference to vimrc_example.vim since commands now moved into here
 18  "   20110920 - add autosave on losing focus
 19  "            - change leader key from \ to ,
 20  "            - change font to DejaVu Sans Mono pt9
 21  "   20110925 - Restructure and add more options from Steve Losh's vimrc file
 22  "              https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc
 23  "
 24  "
 25  "
 26  " Basic options --------------------------------------------------------------- 
 27  set nocompatible
 28  set encoding=utf-8
 29  set modelines=0
 30  set autoindent
 31  set smartindent
 32  set showmode
 33  set showcmd
 34  "set hidden
 35  set visualbell
 36  set cursorline
 37  set ttyfast
 38  set ruler
 39  set backspace=indent,eol,start "backspace over these places
 40  set nonumber
 41  set norelativenumber
 42  set laststatus=2
 43  set history=1000
 44  set undofile " Allow undos even after file has been closed and reopened
 45  set undoreload=10000
 46  set cpoptions+=J
 47  set nolist
 48  set listchars=tab:▸\ ,eol:¬,extends:,precedes:
 49  "set shell=/bin/bash
 50  set lazyredraw
 51  set matchtime=3 " Tenths of a second to show the matching paren, when 'showmatch' is set
 52  set showbreak=↪ " show this char at beginning of line when it is wraps with previous line
 53  set splitbelow
 54  set splitright
 55  set fillchars=diff:\ 
 56  set ttimeout
 57  set notimeout
 58  set nottimeout
 59  set autowrite
 60  set shiftround
 61  "set dictionary=/usr/share/dict/words
 62  set backup  " keep a backup file
 63  set nospell "enable spell checking
 64  "set spell "enable spell checking
 65
 66  "Don't use this if "set relativenumber" is being used.
 67  set number
 68  " set relativenumber
 69
 70  set autoread "Automatically reload a file if it changes - useful for logs
 71
 72  " redefine leader character
 73  let mapleader = ","
 74
 75  " alternative to ESC, I personally use jj to exit back to normal mode. The only time I’ve ever actually tried to hit two j‘s in a row is just now while writing this entry, so it doesn’t conflict with my normal typing at all:
 76  inoremap jj <ESC>
 77
 78  "use confirm instead of aborting an action
 79  set confirm
 80
 81  set autochdir " current directory is always matching the content of the active window
 82
 83  " remember some stuff after quiting vim:
 84  " marks, registers, searches, buffer list
 85  set viminfo='20,<50,s10,h,%
 86
 87  " Show autocomplete menus.
 88  set wildmenu
 89  set wildmode=list:longest,full
 90
 91  " Any selected text is auto copied to Windows clipboard
 92  " set guioptions+=a "PK 20101013 don't autocopy because we want to select text
 93  " and replace selected text from clipboard.
 94
 95  " Use Windows clipboard as default register for yank, delete, change and put.
 96  " This make * the default register, which is used to access the Windows
 97  " clipboard.
 98  set clipboard+=unnamed
 99
100  " Tabs, spaces, wrapping ========================================= {{{
101
102  set smarttab
103  set tabstop=2
104  set shiftwidth=2
105  set softtabstop=2
106  set expandtab
107  "set wrap
108  set textwidth=85 "was 999
109  set formatoptions=qrn1
110  "set colorcolumn=+1
111  "
112  set display=lastline "show next line instead of @ symbols
113
114  syntax on
115
116  set whichwrap+=<,>,h,l "cursor keys wrap
117  " }}}
118
119  " Quickreturn
120  "add new line from anywhere in line in insert mode
121  inoremap <c-cr> <esc>A<cr> 
122  "
123  "as above but append colon on line first
124  inoremap <s-cr> <esc>A:<cr> 
125
126  " Searching ============================================== {{{
127  set incsearch
128  set hlsearch
129  set showmatch
130  set ignorecase " First ignore case when searching.
131  set smartcase " Search is case-sensitive if an uppercase character appears in search string
132  set gdefault " subst all occurences on line by default
133
134  " Keep search matches in the middle of the window.
135  nnoremap n nzzzv
136  nnoremap N Nzzzv
137
138  " }}}
139
140  " Movement, buffers and windows ================================================ {{{
141  " Minimal number of screen lines to keep above and below the cursor.
142  set scrolloff=5
143
144  " Easy buffer navigation
145
146  map <C-h> <C-w>h
147  map <C-j> <C-w>j
148  map <C-k> <C-w>k
149  map <C-l> <C-w>l
150
151  "close current buffer
152  map <leader>q :bd<CR> 
153
154  "Ctrl-{up,down} to scroll.
155  "The following only works in gvim?
156  nmap <C-up> <C-y>
157  imap <C-up> <C-o><C-y>
158  nmap <C-down> <C-e>
159  imap <C-down> <C-o><C-e>
160
161  "vertically split window and switch over to it
162  map <leader>w <C-w>v<C-w>l
163
164  "keys for tab windows
165  map <leader>n :tabnew<CR>
166  map <leader>j :tabprevious<CR>
167  map <leader>k :tabnext<CR>
168
169  "let j and k work in wrapped long lines.
170  nnoremap <DOWN> gj
171  nnoremap <UP> gk
172  nnoremap j gj
173  nnoremap k gk
174  " }}}
175  "
176  " ---------------- start of selective copy from vimrc_example.vim
177  " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
178  " let &guioptions = substitute(&guioptions, "t", "", "g")
179
180  " Don't use Ex mode, use Q for formatting
181  map Q gq
182
183  " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
184  " so that you can undo CTRL-U after inserting a line break.
185  inoremap <C-U> <C-G>u<C-U>
186
187  " In many terminal emulators the mouse works just fine, thus enable it.
188  if has('mouse')
189    set mouse=a
190  endif
191
192  " Switch syntax highlighting on, when the terminal has colors
193  " Also switch on highlighting the last used search pattern.
194  if &t_Co > 2 || has("gui_running")
195    syntax on
196    set hlsearch
197  endif
198
199  " Auto-commands --------------------------------------------------------------- 
200  " Only do this part when compiled with support for autocommands.
201  if has("autocmd")
202
203    " Enable file type detection.
204    " Use the default filetype settings, so that mail gets 'tw' set to 72,
205    " 'cindent' is on in C files, etc.
206    " Also load indent files, to automatically do language-dependent indenting.
207    filetype plugin indent on
208
209    " Put these in an autocmd group, so that we can delete them easily.
210    augroup vimrcEx
211    au!
212    
213    "Autosave file when focus is lost; the silent! ignores the error
214    "message that appears when a buffer has never been saved before.
215     autocmd BufLeave,FocusLost * silent! wall
216     "au FocusLost * :wa
217
218    " For all text files set 'textwidth' to 78 characters.
219    autocmd FileType text setlocal textwidth=78
220
221    " When editing a file, always jump to the last known cursor position.
222    " Don't do it when the position is invalid or when inside an event handler
223    " (happens when dropping a file on gvim).
224    " Also don't do it when the mark is in the first line, that is the default
225    " position when opening a file.
226    autocmd BufReadPost *
227      \ if line("'\"") > 1 && line("'\"") <= line("$") |
228      \   exe "normal! g`\"" |
229      \ endif
230
231    augroup END
232
233  else
234    set autoindent    " always set autoindenting on
235  endif " has("autocmd")
236
237  " Convenient command to see the difference between the current buffer and the
238  " file it was loaded from, thus the changes you made.
239  " Only define it when not defined already.
240  if !exists(":DiffOrig")
241    command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
242        \ | wincmd p | diffthis
243  endif
244  " ---------------- end of copy from vimrc_example.vim
245  "
246  filetype plugin on
247
248  " For Ruby
249  autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
250  autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
251  autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
252  autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
253
254
255  "source $HOME/vimrc_example.vim
256  source $HOME/mswin.vim
257  behave mswin
258
259
260  " leader keys --------------------------------------
261
262  map <leader>s :update<CR>
263  map <leader>t :TlistToggle<CR>
264  map <leader>y :YRShow<CR>
265
266  " toggle visible whitespace
267  nmap <silent> <leader>l :set list!<CR> 
268
269  " write session
270  map <leader>ss :mksession! ~/vim_session <cr> 
271  " restore session
272  map <leader>rs :source ~/vim_session <cr>     
273
274  "underline current line
275  nnoremap <leader>1 yypVr- 
276
277  "reselect the text that was just pasted so I can perform commands (like indentation) on it:
278  nnoremap <leader>v V`]
279
280  " quickly open up my ~/.vimrc file in a vertically split window so I can add new things to it on the fly.
281  nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
282
283  " end of leader keys -------------------------------
284  "
285  " Map ; to : since it’s one less key to hit 
286  "nnoremap ; :
287
288
289  " Set color scheme 
290  if has("gui_running")
291    set gfn=DejaVu_Sans_Mono:h9:cANSI
292    "set gfn=Consolas:h9
293    set lines=50
294    set columns=150
295    "colorscheme evening
296    colorscheme neon-PK
297
298  else
299  "    colorscheme darkblue
300  endif
301
302  " Status line ----------------------------------------------------------------- {{{
303  set laststatus=2
304  set statusline=
305  set statusline+=%-3.3n\                      " buffer number
306  set statusline+=%f\                          " filename
307  set statusline+=%h%m%r%w                     " status flags
308  set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type
309  set statusline+=%=                           " right align remainder
310  set statusline+=0x%-8B                       " character value
311  set statusline+=%-14(%l,%c%V%)               " line, character
312  set statusline+=%<%P                         " file position
313
314  set statusline=%F%m%r%h%w\[%{strlen(&ft)?&ft:'none'}]\ (%{&ff}/%Y)\ %=line\ %l\/%L,\ col\ %c:\ 0x%-8B\ %<%P
315
316  " Show line number, cursor position.
317  set ruler
318  " }}}
319  "
320
321  " To insert timestamp, press F3.
322  " nmap <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
323  " imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
324
325  " Define F3 to paste the results of the last search into a new window
326  nmap <F3> :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>:put! a<CR><CR>
327
328  " To save, press ctrl-s.
329  nmap <c-s> :w<CR>
330  imap <c-s> <Esc>:w<CR>a
331
332  " unhighlight search results
333  :map \\ :noh<return>
334
335
336  " To close file, press ctrl-w
337  " nmap <c-w> :close<CR>
338  " imap <c-w> <Esc>:close<CR>
339
340  " Grep without special vim characters
341  " PK this doesn't always work: so remove
342  "nnoremap / /\v
343  "vnoremap / /\v
344  "cnoremap %s/ %s/\v
345
346
347
348  " Plugins ========================================================= }}}
349  " Tell taglist where Exuberant Tags is installed and map F8 to toggle tag list
350  "
351  " on and off.
352  let Tlist_Ctags_Cmd="C:\\apps\\ctags58\\ctags.exe"
353  let Tlist_GainFocus_On_ToggleOpen=1
354  let Tlist_Use_Right_Window = 1
355  let Tlist_Close_On_Select = 1
356  noremap <silent> <F8> :TlistToggle<CR>
357  "Easytags (enables CTRL=] and CTRL-T) by autotagging  
358  set tags=./.tags;,~/.vimtags
359  let g:easytags_cmd = "C:\\apps\\ctags58\\ctags.exe"
360  "   use local tag files instead of the global .vimtags
361  let g:easytags_dynamic_files = 1
362  "   disable highlighting
363  let g:easytags_auto_highlight = 0
364
365  " yankring shortcut
366  nnoremap <silent> <F12> :YRShow<CR>
367  inoremap <silent> <F12> <ESC>:YRShow<cr>
368  let g:yankring_n_keys = 'Y D x X'
369
370  " Make Y behave like D and C
371  "nnoremap Y y$ "PK this doesn't work with Yankring; use function below
372
373  let g:session_autoload = "yes"
374  let g:session_autosave = "yes"
375  let g:session_default_to_last = 1
376
377  " tell yankring to set Y to y$
378  function! YRRunAfterMaps()
379    nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
380  endfunction
381
382  " Ack {{{
383
384  map <leader>a :Ack! 
385
386  " Ack for the last search.
387  nnoremap <silent> <leader>? :execute "Ack! '" . substitute(substitute(substitute(@/, "\\\\<", "\\\\b", ""), "\\\\>", "\\\\b", ""), "\\\\v", "", "") . "'"<CR>
388  " }}}
389  "
390  " }}}
391  "
392  set diffexpr=MyDiff()
393  function MyDiff()
394    let opt = '-a --binary '
395    if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
396    if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
397    let arg1 = v:fname_in
398    if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
399    let arg2 = v:fname_new
400    if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
401    let arg3 = v:fname_out
402    if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
403    let eq = ''
404    if $VIMRUNTIME =~ ' '
405      if &sh =~ '\<cmd'
406        let cmd = '""' . $VIMRUNTIME . '\diff"'
407        let eq = '"'
408      else
409        let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
410      endif
411    else
412      let cmd = $VIMRUNTIME . '\diff'
413    endif
414    silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
415  endfunction
416
417

Vim colour theme - neon-PK

I uploaded my version of the Vim neon color theme to the Vim site. When using the DejaVu Sans Mono font on Windows, it looks like this: