Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 425 lines (384 sloc) 12.918 kb
9c88d4dc »
2010-10-21 Added VisIncr plugin.
1 " Folding cheet sheet
926b0dad »
2010-03-18 Added folding cheet sheet for noobs.
2 " zR open all folds
3 " zM close all folds
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
4 " za toggle fold at cursor position
5 " zj move down to start of next fold
6 " zk move up to end of previous fold
3959bcb9 »
2010-03-18 Enable autocommands in ftdetect/*.vim files.
7 " Manage plugins. {{{1
8 runtime macros/matchit.vim
9 call pathogen#runtime_append_all_bundles()
10 call pathogen#helptags()
11 let g:GetLatestVimScripts_allowautoinstall=1
eeb8c5a7 »
2010-03-18 Added fold markers to vimrc.
12 " An example for a vimrc file. {{{1
84d14ea9 »
2010-03-18 Added .vimrc copied from vimrc_example.vim
13 "
14 " Maintainer: Bram Moolenaar <Bram@vim.org>
15 " Last change: 2008 Jul 02
16 "
17 " To use it, copy it to
18 " for Unix and OS/2: ~/.vimrc
19 " for Amiga: s:.vimrc
20 " for MS-DOS and Win32: $VIM\_vimrc
21 " for OpenVMS: sys$login:.vimrc
22
23 " When started as "evim", evim.vim will already have done these settings.
24 if v:progname =~? "evim"
25 finish
26 endif
27
28 " Use Vim settings, rather then Vi settings (much better!).
29 " This must be first, because it changes other options as a side effect.
30 set nocompatible
31
32 " allow backspacing over everything in insert mode
33 set backspace=indent,eol,start
34
35 if has("vms")
36 set nobackup " do not keep a backup file, use versions instead
37 else
38 set backup " keep a backup file
39 endif
40 set history=50 " keep 50 lines of command line history
41 set ruler " show the cursor position all the time
42 set showcmd " display incomplete commands
43 set incsearch " do incremental searching
44
45 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
46 " let &guioptions = substitute(&guioptions, "t", "", "g")
47
48 " Don't use Ex mode, use Q for formatting
49 map Q gq
50
51 " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
52 " so that you can undo CTRL-U after inserting a line break.
53 inoremap <C-U> <C-G>u<C-U>
54
55 " In many terminal emulators the mouse works just fine, thus enable it.
56 if has('mouse')
57 set mouse=a
58 endif
59
60 " Switch syntax highlighting on, when the terminal has colors
61 " Also switch on highlighting the last used search pattern.
62 if &t_Co > 2 || has("gui_running")
63 syntax on
64 set hlsearch
65 endif
66
67 " Only do this part when compiled with support for autocommands.
68 if has("autocmd")
69
70 " Enable file type detection.
71 " Use the default filetype settings, so that mail gets 'tw' set to 72,
72 " 'cindent' is on in C files, etc.
73 " Also load indent files, to automatically do language-dependent indenting.
74 filetype plugin indent on
75
76 " Put these in an autocmd group, so that we can delete them easily.
77 augroup vimrcEx
78 au!
79
80 " For all text files set 'textwidth' to 78 characters.
81 autocmd FileType text setlocal textwidth=78
82
83 " When editing a file, always jump to the last known cursor position.
84 " Don't do it when the position is invalid or when inside an event handler
85 " (happens when dropping a file on gvim).
86 " Also don't do it when the mark is in the first line, that is the default
87 " position when opening a file.
88 autocmd BufReadPost *
89 \ if line("'\"") > 1 && line("'\"") <= line("$") |
90 \ exe "normal! g`\"" |
91 \ endif
92
93 augroup END
94
95 else
96
97 set autoindent " always set autoindenting on
98
99 endif " has("autocmd")
100
101 " Convenient command to see the difference between the current buffer and the
102 " file it was loaded from, thus the changes you made.
103 " Only define it when not defined already.
104 if !exists(":DiffOrig")
105 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
106 \ | wincmd p | diffthis
f403de86 »
2010-03-18 Fixed typo: (e -> endif).
107 endif
eeb8c5a7 »
2010-03-18 Added fold markers to vimrc.
108
b4992d49 »
2010-03-18 Added vimrc sections for preferences and mappings.
109 " Preferences {{{1
4c820ae4 »
2010-04-30 Switched off the irritating bell
110 set visualbell t_vb=
b4992d49 »
2010-03-18 Added vimrc sections for preferences and mappings.
111 set number
112 set cursorline
113 set tabstop=4
114 set softtabstop=4
115 set shiftwidth=4
116 set expandtab
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
117 set hidden
6b7dc80b »
2011-01-21 set nojoinspaces - at last!
118 set nojoinspaces
b4992d49 »
2010-03-18 Added vimrc sections for preferences and mappings.
119 set listchars=tab:▸\ ,eol
21465d26 »
2011-02-10 set wildmode=longest,list
120 set wildmode=longest,list
87d722af »
2010-05-11 Set spelling region to British English by default.
121 "set spelllang=en_gb
51f7097d »
2010-04-03 Set the dir for backup/swap files to ~/tmp
122 " Put swap files in /tmp file
123 set backupdir=~/tmp
124 set directory=~/tmp
125 if has("autocmd")
61dd2d97 »
2011-02-10 Setup whitespace for yaml and coffee files.
126 autocmd FileType html,css,scss,ruby,pml,yaml,coffee setlocal ts=2 sts=2 sw=2 expandtab
980112ae »
2010-05-12 Added whitespace prefs for ruby+javascript.
127 autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
3f3f96c6 »
2010-11-09 Enable linebreak for markdown files.
128 autocmd FileType markdown setlocal wrap linebreak nolist
cdfbc49f »
2010-04-05 vimrc: set filetype for .rss files to xml.
129 autocmd BufNewFile,BufRead *.rss setfiletype xml
f749e77c »
2011-01-25 Auto-correct 'initialise' to 'initialize' in ruby files.
130 autocmd FileType ruby :Abolish -buffer initialise initialize
51f7097d »
2010-04-03 Set the dir for backup/swap files to ~/tmp
131 endif
132
8e17b15e »
2010-03-18 Set mapleader and make .vimrc easier to edit.
133 " Toggles & Switches (Leader commands) {{{1
134 let mapleader = ","
b6171dff »
2010-04-29 Added `,s` map to toggle spellchecker.
135 nmap <silent> <leader>l :set list!<CR>
136 nmap <silent> <leader>w :set wrap!<CR>
4fdbf041 »
2011-01-13 Make spelling toggle apply only to current buffer.
137 nmap <silent> <buffer> <leader>s :set spell!<CR>
8e17b15e »
2010-03-18 Set mapleader and make .vimrc easier to edit.
138 nmap <silent> <leader>n :silent :nohlsearch<CR>
614de0c3 »
2011-01-15 Install indent-guides plugin.
139 nmap <silent> <leader>c :IndentGuidesToggle<CR>
a28930c1 »
2010-04-19 :Wrap command runs: set wrap linebreak nolist
140 command! -nargs=* Wrap set wrap linebreak nolist
51867d99 »
2010-11-17 Add :Maxsize command to use full window.
141 command! -nargs=* Maxsize set columns=1000 lines=1000
9c02cacf »
2010-12-19 Customizations for ctags/taglist.
142 " CTags {{{1
143 map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
144 let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"
145 let tlist_markdown_settings='markdown;h:Headings'
0bffbb03 »
2011-02-13 Make taglist only show symbols for current file.
146 let Tlist_Show_One_File=1
6a451870 »
2011-01-14 Update PML plugin.
147 nmap <Leader>/ :TlistToggle<CR>
8e17b15e »
2010-03-18 Set mapleader and make .vimrc easier to edit.
148
b4992d49 »
2010-03-18 Added vimrc sections for preferences and mappings.
149 " Mappings {{{1
51f7097d »
2010-04-03 Set the dir for backup/swap files to ~/tmp
150 " Speed up buffer switching {{{2
b4992d49 »
2010-03-18 Added vimrc sections for preferences and mappings.
151 map <C-k> <C-W>k
152 map <C-j> <C-W>j
153 map <C-h> <C-W>h
154 map <C-l> <C-W>l
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
155 " Speed up tab switching {{{2
156 map <D-S-]> gt
157 map <D-S-[> gT
158 map <D-1> 1gt
159 map <D-2> 2gt
160 map <D-3> 3gt
161 map <D-4> 4gt
162 map <D-5> 5gt
163 map <D-6> 6gt
164 map <D-7> 7gt
165 map <D-8> 8gt
166 map <D-9> 9gt
167 map <D-0> :tablast<CR>
00fe2313 »
2010-04-03 Added mappings for easy j/k/$/0/^ on wrapped lines.
168 " Shortcuts to make it easier to explore wrapped lines {{{2
169 " These come in handy when the following settings are enabled:
170 " :set linebreak wrap nolist
171 vmap <D-j> gj
172 vmap <D-k> gk
173 vmap <D-4> g$
174 vmap <D-6> g^
175 vmap <D-0> g^
176 nmap <D-j> gj
177 nmap <D-k> gk
178 nmap <D-4> g$
179 nmap <D-6> g^
180 nmap <D-0> g^
c3d95312 »
2010-04-03 Added shortcuts to :e file in same dir as current file.
181 " Shortcuts for opening file in same directory as current file {{{2
182 map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
183 map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
184 map <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR>
185 map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
9c88d4dc »
2010-10-21 Added VisIncr plugin.
186 " Shortcuts for visual selections {{{2
187 nmap gV `[v`]
70e18814 »
2011-01-17 Add mappings to trigger :Tabularize for common tokens.
188 " Alignment commands {{{1
189 if exists(":Tabularize")
190 nmap <Leader>a= :Tabularize /=<CR>
191 vmap <Leader>a= :Tabularize /=<CR>
192 nmap <Leader>a: :Tabularize /:\zs<CR>
193 vmap <Leader>a: :Tabularize /:\zs<CR>
194 endif
92009f67 »
2010-11-09 Added :Refactor command, for dictionary-based substitutions.
195 " TextObject tweaks {{{1
b8294956 »
2010-12-04 Switch out `Va/it` for `va/iT` mappings.
196 nnoremap viT vitVkoj
197 nnoremap vaT vatV
e84cb018 »
2010-11-07 Add insert mode ctrl-e jump to end of line.
198 " Insert mode mappings {{{1
92009f67 »
2010-11-09 Added :Refactor command, for dictionary-based substitutions.
199 " emacs style jump to end of line
e84cb018 »
2010-11-07 Add insert mode ctrl-e jump to end of line.
200 imap <C-e> <C-o>A
be24c35c »
2010-11-09 Create cmd-enter mapping to 'o' in insert mode.
201 imap <C-a> <C-o>I
92009f67 »
2010-11-09 Added :Refactor command, for dictionary-based substitutions.
202 " Open line above (ctrl-shift-o much easier than ctrl-o shift-O)
be24c35c »
2010-11-09 Create cmd-enter mapping to 'o' in insert mode.
203 imap <C-Enter> <C-o>o
204 imap <C-S-Enter> <C-o>O
8e17b15e »
2010-03-18 Set mapleader and make .vimrc easier to edit.
205 " Easily modify vimrc {{{1
206 nmap <leader>v :e $MYVIMRC<CR>
207 " http://stackoverflow.com/questions/2400264/is-it-possible-to-apply-vim-configurations-without-restarting/2400289#2400289
208 if has("autocmd")
209 augroup myvimrchooks
210 au!
211 autocmd bufwritepost .vimrc source ~/.vimrc
212 augroup END
213 endif
214
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
215 " Custom commands and functions {{{1
e924edf4 »
2011-02-13 Add quickfix to arglist functions/commands.
216 " Create a :Quickfixdo command, to match :argdo/bufdo/windo
217 " Define a command to make it easier to use
218 command! -nargs=* Qargs call QuickfixFilenames()
219 function! QuickfixFilenames()
220 " Building a hash ensures we get each buffer only once
221 let buffer_numbers = {}
222 for quickfix_item in getqflist()
223 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
224 endfor
225 return join(values(buffer_numbers))
226 endfunction
227
228 command! -nargs=+ QFDo call QFDo(<q-args>)
229 " Function that does the work
230 function! QFDo(command)
231 " Create a dictionary so that we can get the list of buffers rather than
232 " the list of lines in buffers (easy way to get unique entries)
233 let buffer_numbers = {}
234 " For each entry, use the buffer number as a dictionary key (won't get
235 " repeats)
236 for fixlist_entry in getqflist()
237 let buffer_numbers[fixlist_entry['bufnr']] = 1
238 endfor
239 " Make it into a list as it seems cleaner
240 let buffer_number_list = keys(buffer_numbers)
241
242 " For each buffer
243 for num in buffer_number_list
244 " Select the buffer
245 exe 'buffer' num
246 " Run the command that's passed as an argument
247 exe a:command
248 " Save if necessary
249 update
250 endfor
251 endfunction
252 " http://stackoverflow.com/questions/4792561/how-to-do-search-replace-with-ack-in-vim
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
253 " Show syntax highlighting groups for word under cursor {{{2
254 " Tip: http://stackoverflow.com/questions/1467438/find-out-to-which-highlight-group-a-particular-keyword-symbol-belongs-in-vim
255 nmap <C-S-P> :call <SID>SynStack()<CR>
256 function! <SID>SynStack()
257 if !exists("*synstack")
258 return
259 endif
260 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
261 endfunc
abe4af41 »
2010-07-05 Added command `:Only` which closes hidden buffers.
262 " Wipe all buffers which are not active (i.e. not visible in a window/tab) {{{2
263 " http://stackoverflow.com/questions/2974192/how-can-i-pare-down-vims-buffer-list-to-only-include-active-buffers
264 " http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
265 command! -nargs=* Only call CloseHiddenBuffers()
266 function! CloseHiddenBuffers()
267 " figure out which buffers are visible in any tab
268 let visible = {}
269 for t in range(1, tabpagenr('$'))
270 for b in tabpagebuflist(t)
271 let visible[b] = 1
272 endfor
273 endfor
274 " close any buffer that are loaded and not visible
275 let l:tally = 0
276 for b in range(1, bufnr('$'))
277 if bufloaded(b) && !has_key(visible, b)
278 let l:tally += 1
279 exe 'bw ' . b
280 endif
281 endfor
282 echon "Deleted " . l:tally . " buffers"
283 endfun
284
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
285 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
286 " From http://vimcasts.org/episodes/tabs-and-spaces/
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
287 command! -nargs=* Stab call Stab()
288 function! Stab()
289 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
290 if l:tabstop > 0
291 let &l:sts = l:tabstop
292 let &l:ts = l:tabstop
293 let &l:sw = l:tabstop
294 endif
295 call SummarizeTabs()
296 endfunction
297
298 function! SummarizeTabs()
299 try
300 echohl ModeMsg
301 echon 'tabstop='.&l:ts
302 echon ' shiftwidth='.&l:sw
303 echon ' softtabstop='.&l:sts
304 if &l:et
305 echon ' expandtab'
306 else
307 echon ' noexpandtab'
308 end
309 finally
310 echohl None
311 endtry
312 endfunction
313
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
314 " Strip trailing whitespaces {{{2
ac460919 »
2010-04-03 Refactored StripTrailingWhitespaces() to Preserve().
315 function! Preserve(command)
316 " Preparation: save last search, and cursor position.
317 let _s=@/
318 let l = line(".")
319 let c = col(".")
320 " Do the business:
321 execute a:command
322 " Clean up: restore previous search history, and cursor position
323 let @/=_s
324 call cursor(l, c)
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
325 endfunction
ac460919 »
2010-04-03 Refactored StripTrailingWhitespaces() to Preserve().
326 nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
327 nmap _= :call Preserve("normal gg=G")<CR>
328
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
329 " Search for current visual selection with */# {{{2
330 " Tip tip from: http://amix.dk/blog/viewEntry/19334
331 function! CmdLine(str)
332 exe "menu Foo.Bar :" . a:str
333 emenu Foo.Bar
334 unmenu Foo
335 endfunction
336
337 function! VisualSearch(direction) range
338 let l:saved_reg = @"
339 execute "normal! vgvy"
340
341 let l:pattern = escape(@", '\\/.*$^~[]')
342 let l:pattern = substitute(l:pattern, "\n$", "", "")
343
344 if a:direction == 'b'
345 execute "normal ?" . l:pattern . "^M"
346 elseif a:direction == 'gv'
347 call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
348 elseif a:direction == 'f'
349 execute "normal /" . l:pattern . "^M"
350 endif
351
352 let @/ = l:pattern
353 let @" = l:saved_reg
354 endfunction
92009f67 »
2010-11-09 Added :Refactor command, for dictionary-based substitutions.
355 " Swap words in a single substitution command {{{2
356 " http://stackoverflow.com/questions/765894/can-i-substitute-multiple-items-in-a-single-regular-expression-in-vim-or-perl/766093#766093
357 function! Refactor(dict) range
358 execute a:firstline . ',' . a:lastline . 's/\C\<\%(' . join(keys(a:dict),'\|'). '\)\>/\='.string(a:dict).'[submatch(0)]/ge'
359 endfunction
360 command! -range=% -nargs=1 Refactor :<line1>,<line2>call Refactor(<args>)
361
362 " Running :Refactor {'quick':'slow', 'lazy':'energetic'} will change the following text:
363 " The quick brown fox ran quickly next to the lazy brook.
364 "into:
365 " The slow brown fox ran slowly next to the energetic brook.
366
367 " TODO: create a :Swap command, which turns:
368 " :Swap(portrait,landscape)
369 " into
370 " :Refactor {'portrait':'landscape', 'landscape':'portrait'}
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
371
372 "Basically you press * or # to search for the current selection
373 "then 'n' should search forward, 'N' should search backwards.
374 vnoremap <silent> * :call VisualSearch('f')<CR>
375 vnoremap <silent> # :call VisualSearch('b')<CR>
376 vnoremap <silent> gv :call VisualSearch('gv')<CR>
377
378 " Status line {{{1
379 " Good article on setting a statusline:
380 " http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
70b5a188 »
2010-11-20 Make status line always visible.
381 " Always show the status line (even if no split windows)
382 set laststatus=2
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
383 " Mappings for a recovering TextMate user {{{1
384 " Indentation {{{2
385 nmap <D-[> <<
386 nmap <D-]> >>
387 vmap <D-[> <gv
388 vmap <D-]> >gv
ff45eb97 »
2010-03-18 Added visual star command, and TextMate/NERD comment toggle.
389
390 " Commenting {{{2
391 " requires NERDCommenter plugin
392 vmap <D-/> ,c<space>gv
393 map <D-/> ,c<space>
394
529cd6f2 »
2011-02-13 Add then comment out a line-duplication mapping.
395 " Duplicate selection {{{2
396 "vmap <S-C-D> :copy'> <CR>V`[o
397 "nmap <S-C-D> :copy .<CR>
79be99fc »
2010-03-18 Added section for custom functions, and TextMate maps.
398 " Move selection {{{2
9c88d4dc »
2010-10-21 Added VisIncr plugin.
399 " Move current line down/up
400 map <C-Down> ]e
401 map <C-Up> [e
402 " Move visually selected lines down/up
403 vmap <C-Down> ]egv
404 vmap <C-Up> [egv
926b0dad »
2010-03-18 Added folding cheet sheet for noobs.
405 " Move visual selection back/forwards
9c88d4dc »
2010-10-21 Added VisIncr plugin.
406 set ww+=<,>
407 vmap <C-Left> x<Left>P`[v`]
408 vmap <C-Right> x<Right>P`[v`]
1b604b9b »
2010-11-07 Patched Gundo.vim
409 " Configure plugins {{{1
410 " Gundo.vim {{{2
411 map <Leader>u :GundoToggle<CR>
b75ddd50 »
2010-11-20 Notes on customizing textobj-entire.
412
413 " TextObject customizations {{{2
0bc0b1aa »
2010-11-21 Map textobj-entire to `ia` and `aa`.
414 " Entire text object {{{3
415 " Map text-object for entire buffer to `ia` and `aa`.
416 let g:textobj_entire_no_default_key_mappings = 1
417 xmap aa <Plug>(textobj-entire-a)
418 omap aa <Plug>(textobj-entire-a)
419 xmap ia <Plug>(textobj-entire-i)
420 omap ia <Plug>(textobj-entire-i)
b75ddd50 »
2010-11-20 Notes on customizing textobj-entire.
421 " }}}
422
eeb8c5a7 »
2010-03-18 Added fold markers to vimrc.
423 " Modelines: {{{1
8e17b15e »
2010-03-18 Set mapleader and make .vimrc easier to edit.
424 " vim: nowrap fdm=marker
926b0dad »
2010-03-18 Added folding cheet sheet for noobs.
425 " }}}
Something went wrong with that request. Please try again.