Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 415 lines (378 sloc) 12.545 kB
9c88d4d @nelstrom Added VisIncr plugin.
authored
1 " Folding cheet sheet
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
2 " zR open all folds
3 " zM close all folds
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
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
3959bcb @nelstrom Enable autocommands in ftdetect/*.vim files.
authored
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
eeb8c5a @nelstrom Added fold markers to vimrc.
authored
12 " An example for a vimrc file. {{{1
84d14ea @nelstrom Added .vimrc copied from vimrc_example.vim
authored
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
f403de8 @nelstrom Fixed typo: (e -> endif).
authored
107 endif
eeb8c5a @nelstrom Added fold markers to vimrc.
authored
108
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
109 " Preferences {{{1
4c820ae @nelstrom Switched off the irritating bell
authored
110 set visualbell t_vb=
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
111 set number
112 set cursorline
113 set tabstop=4
114 set softtabstop=4
115 set shiftwidth=4
116 set expandtab
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
117 set hidden
6b7dc80 @nelstrom set nojoinspaces - at last!
authored
118 set nojoinspaces
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
119 set listchars=tab:\ ,eol:¬
21465d2 @nelstrom set wildmode=longest,list
authored
120 set wildmode=longest,list
87d722a @nelstrom Set spelling region to British English by default.
authored
121 "set spelllang=en_gb
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
122 " Put swap files in /tmp file
123 set backupdir=~/tmp
124 set directory=~/tmp
125 if has("autocmd")
0cd26c2 @nelstrom Use 2 spaces for Vimscript indentation.
authored
126 autocmd FileType html,css,scss,ruby,pml,yaml,coffee,vim setlocal ts=2 sts=2 sw=2 expandtab
980112a @nelstrom Added whitespace prefs for ruby+javascript.
authored
127 autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
3f3f96c @nelstrom Enable linebreak for markdown files.
authored
128 autocmd FileType markdown setlocal wrap linebreak nolist
cdfbc49 @nelstrom vimrc: set filetype for .rss files to xml.
authored
129 autocmd BufNewFile,BufRead *.rss setfiletype xml
17998eb @nelstrom Set ruby filetype for Rakefile,Capfile,Gemfile,Termfile,config.ru
authored
130 autocmd BufNewFile,BufRead Rakefile,Capfile,Gemfile,Termfile,config.ru setfiletype ruby
f749e77 @nelstrom Auto-correct 'initialise' to 'initialize' in ruby files.
authored
131 autocmd FileType ruby :Abolish -buffer initialise initialize
362a7ef @nelstrom Use solarized as default colorscheme.
authored
132 autocmd FileType vo_base :colorscheme solarized
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
133 endif
134
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
135 " Toggles & Switches (Leader commands) {{{1
136 let mapleader = ","
b6171df @nelstrom Added `,s` map to toggle spellchecker.
authored
137 nmap <silent> <leader>l :set list!<CR>
138 nmap <silent> <leader>w :set wrap!<CR>
4fdbf04 @nelstrom Make spelling toggle apply only to current buffer.
authored
139 nmap <silent> <buffer> <leader>s :set spell!<CR>
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
140 nmap <silent> <leader>n :silent :nohlsearch<CR>
614de0c @nelstrom Install indent-guides plugin.
authored
141 nmap <silent> <leader>c :IndentGuidesToggle<CR>
a28930c @nelstrom :Wrap command runs: set wrap linebreak nolist
authored
142 command! -nargs=* Wrap set wrap linebreak nolist
51867d9 @nelstrom Add :Maxsize command to use full window.
authored
143 command! -nargs=* Maxsize set columns=1000 lines=1000
9c02cac @nelstrom Customizations for ctags/taglist.
authored
144 " CTags {{{1
145 map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
146 let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"
147 let tlist_markdown_settings='markdown;h:Headings'
0bffbb0 @nelstrom Make taglist only show symbols for current file.
authored
148 let Tlist_Show_One_File=1
6a45187 @nelstrom Update PML plugin.
authored
149 nmap <Leader>/ :TlistToggle<CR>
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
150
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
151 " Mappings {{{1
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
152 " Speed up buffer switching {{{2
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
153 map <C-k> <C-W>k
154 map <C-j> <C-W>j
155 map <C-h> <C-W>h
156 map <C-l> <C-W>l
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
157 " Speed up tab switching {{{2
158 map <D-S-]> gt
159 map <D-S-[> gT
160 map <D-1> 1gt
161 map <D-2> 2gt
162 map <D-3> 3gt
163 map <D-4> 4gt
164 map <D-5> 5gt
165 map <D-6> 6gt
166 map <D-7> 7gt
167 map <D-8> 8gt
168 map <D-9> 9gt
169 map <D-0> :tablast<CR>
00fe231 @nelstrom Added mappings for easy j/k/$/0/^ on wrapped lines.
authored
170 " Shortcuts to make it easier to explore wrapped lines {{{2
171 " These come in handy when the following settings are enabled:
172 " :set linebreak wrap nolist
173 vmap <D-j> gj
174 vmap <D-k> gk
175 vmap <D-4> g$
176 vmap <D-6> g^
177 vmap <D-0> g^
178 nmap <D-j> gj
179 nmap <D-k> gk
180 nmap <D-4> g$
181 nmap <D-6> g^
182 nmap <D-0> g^
c3d9531 @nelstrom Added shortcuts to :e file in same dir as current file.
authored
183 " Shortcuts for opening file in same directory as current file {{{2
706ba29 @nelstrom Add `%%` mapping in commandline mode to expand working directory.
authored
184 cnoremap %% <C-R>=expand('%:h').'/'<cr>
185 map <leader>ew :e %%
186 map <leader>es :sp %%
187 map <leader>ev :vsp %%
188 map <leader>et :tabe %%
084246a @nelstrom ,er to expand current filename without extension.
authored
189 map <leader>er :e <C-R>=expand("%:r")."."<CR>
9c88d4d @nelstrom Added VisIncr plugin.
authored
190 " Shortcuts for visual selections {{{2
191 nmap gV `[v`]
8dabf73 @nelstrom Fix the `&` command in normal and visual modes.
authored
192 " Substitute command repetition {{{2
193 nnoremap & :~&<Enter>
194 vnoremap & :~&<Enter>
70e1881 @nelstrom Add mappings to trigger :Tabularize for common tokens.
authored
195 " Alignment commands {{{1
196 if exists(":Tabularize")
197 nmap <Leader>a= :Tabularize /=<CR>
198 vmap <Leader>a= :Tabularize /=<CR>
199 nmap <Leader>a: :Tabularize /:\zs<CR>
200 vmap <Leader>a: :Tabularize /:\zs<CR>
201 endif
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
202 " TextObject tweaks {{{1
b829495 @nelstrom Switch out `Va/it` for `va/iT` mappings.
authored
203 nnoremap viT vitVkoj
204 nnoremap vaT vatV
e84cb01 @nelstrom Add insert mode ctrl-e jump to end of line.
authored
205 " Insert mode mappings {{{1
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
206 " emacs style jump to end of line
e84cb01 @nelstrom Add insert mode ctrl-e jump to end of line.
authored
207 imap <C-e> <C-o>A
be24c35 @nelstrom Create cmd-enter mapping to 'o' in insert mode.
authored
208 imap <C-a> <C-o>I
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
209 " Open line above (ctrl-shift-o much easier than ctrl-o shift-O)
be24c35 @nelstrom Create cmd-enter mapping to 'o' in insert mode.
authored
210 imap <C-Enter> <C-o>o
211 imap <C-S-Enter> <C-o>O
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
212 " Easily modify vimrc {{{1
213 nmap <leader>v :e $MYVIMRC<CR>
214 " http://stackoverflow.com/questions/2400264/is-it-possible-to-apply-vim-configurations-without-restarting/2400289#2400289
215 if has("autocmd")
216 augroup myvimrchooks
217 au!
cbaea1f @nelstrom Reload vimrc and gvimrc whenever either one is saved.
authored
218 au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
219 augroup END
220 endif
221
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
222 " Custom commands and functions {{{1
362a7ef @nelstrom Use solarized as default colorscheme.
authored
223 " Create a :Quickfixdo command, to match :argdo/bufdo/windo {{{2
e924edf @nelstrom Add quickfix to arglist functions/commands.
authored
224 " Define a command to make it easier to use
acc1e50 @nelstrom Update Qargs command so other commands may follow.
authored
225 command! -nargs=0 -bar Qargs execute 'args ' . QuickfixFilenames()
e924edf @nelstrom Add quickfix to arglist functions/commands.
authored
226 function! QuickfixFilenames()
227 " Building a hash ensures we get each buffer only once
228 let buffer_numbers = {}
229 for quickfix_item in getqflist()
230 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
231 endfor
232 return join(values(buffer_numbers))
233 endfunction
234
235 command! -nargs=+ QFDo call QFDo(<q-args>)
236 " Function that does the work
237 function! QFDo(command)
238 " Create a dictionary so that we can get the list of buffers rather than
239 " the list of lines in buffers (easy way to get unique entries)
240 let buffer_numbers = {}
241 " For each entry, use the buffer number as a dictionary key (won't get
242 " repeats)
243 for fixlist_entry in getqflist()
244 let buffer_numbers[fixlist_entry['bufnr']] = 1
245 endfor
246 " Make it into a list as it seems cleaner
247 let buffer_number_list = keys(buffer_numbers)
248
249 " For each buffer
250 for num in buffer_number_list
251 " Select the buffer
252 exe 'buffer' num
253 " Run the command that's passed as an argument
254 exe a:command
255 " Save if necessary
256 update
257 endfor
258 endfunction
259 " http://stackoverflow.com/questions/4792561/how-to-do-search-replace-with-ack-in-vim
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
260 " Show syntax highlighting groups for word under cursor {{{2
261 " Tip: http://stackoverflow.com/questions/1467438/find-out-to-which-highlight-group-a-particular-keyword-symbol-belongs-in-vim
262 nmap <C-S-P> :call <SID>SynStack()<CR>
263 function! <SID>SynStack()
264 if !exists("*synstack")
265 return
266 endif
267 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
268 endfunc
abe4af4 @nelstrom Added command `:Only` which closes hidden buffers.
authored
269 " Wipe all buffers which are not active (i.e. not visible in a window/tab) {{{2
270 " http://stackoverflow.com/questions/2974192/how-can-i-pare-down-vims-buffer-list-to-only-include-active-buffers
271 " http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
272 command! -nargs=* Only call CloseHiddenBuffers()
273 function! CloseHiddenBuffers()
274 " figure out which buffers are visible in any tab
275 let visible = {}
276 for t in range(1, tabpagenr('$'))
277 for b in tabpagebuflist(t)
278 let visible[b] = 1
279 endfor
280 endfor
281 " close any buffer that are loaded and not visible
282 let l:tally = 0
283 for b in range(1, bufnr('$'))
284 if bufloaded(b) && !has_key(visible, b)
285 let l:tally += 1
286 exe 'bw ' . b
287 endif
288 endfor
289 echon "Deleted " . l:tally . " buffers"
290 endfun
291
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
292 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
293 " From http://vimcasts.org/episodes/tabs-and-spaces/
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
294 command! -nargs=* Stab call Stab()
295 function! Stab()
296 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
297 if l:tabstop > 0
298 let &l:sts = l:tabstop
299 let &l:ts = l:tabstop
300 let &l:sw = l:tabstop
301 endif
302 call SummarizeTabs()
303 endfunction
304
305 function! SummarizeTabs()
306 try
307 echohl ModeMsg
308 echon 'tabstop='.&l:ts
309 echon ' shiftwidth='.&l:sw
310 echon ' softtabstop='.&l:sts
311 if &l:et
312 echon ' expandtab'
313 else
314 echon ' noexpandtab'
315 end
316 finally
317 echohl None
318 endtry
319 endfunction
320
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
321 " Strip trailing whitespaces {{{2
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
322 function! Preserve(command)
323 " Preparation: save last search, and cursor position.
324 let _s=@/
325 let l = line(".")
326 let c = col(".")
327 " Do the business:
328 execute a:command
329 " Clean up: restore previous search history, and cursor position
330 let @/=_s
331 call cursor(l, c)
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
332 endfunction
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
333 nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
334 nmap _= :call Preserve("normal gg=G")<CR>
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
335 " Swap words in a single substitution command {{{2
336 " http://stackoverflow.com/questions/765894/can-i-substitute-multiple-items-in-a-single-regular-expression-in-vim-or-perl/766093#766093
337 function! Refactor(dict) range
338 execute a:firstline . ',' . a:lastline . 's/\C\<\%(' . join(keys(a:dict),'\|'). '\)\>/\='.string(a:dict).'[submatch(0)]/ge'
339 endfunction
340 command! -range=% -nargs=1 Refactor :<line1>,<line2>call Refactor(<args>)
341
342 " Running :Refactor {'quick':'slow', 'lazy':'energetic'} will change the following text:
343 " The quick brown fox ran quickly next to the lazy brook.
344 "into:
345 " The slow brown fox ran slowly next to the energetic brook.
346
347 " TODO: create a :Swap command, which turns:
348 " :Swap(portrait,landscape)
349 " into
350 " :Refactor {'portrait':'landscape', 'landscape':'portrait'}
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
351
352 " Status line {{{1
353 " Good article on setting a statusline:
354 " http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
70b5a18 @nelstrom Make status line always visible.
authored
355 " Always show the status line (even if no split windows)
356 set laststatus=2
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
357 " Mappings for a recovering TextMate user {{{1
358 " Indentation {{{2
359 nmap <D-[> <<
360 nmap <D-]> >>
361 vmap <D-[> <gv
362 vmap <D-]> >gv
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
363
364 " Commenting {{{2
365 " requires NERDCommenter plugin
366 vmap <D-/> ,c<space>gv
367 map <D-/> ,c<space>
368
529cd6f @nelstrom Add then comment out a line-duplication mapping.
authored
369 " Duplicate selection {{{2
370 "vmap <S-C-D> :copy'> <CR>V`[o
371 "nmap <S-C-D> :copy .<CR>
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
372 " Move selection {{{2
9c88d4d @nelstrom Added VisIncr plugin.
authored
373 " Move current line down/up
374 map <C-Down> ]e
375 map <C-Up> [e
376 " Move visually selected lines down/up
377 vmap <C-Down> ]egv
378 vmap <C-Up> [egv
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
379 " Move visual selection back/forwards
9c88d4d @nelstrom Added VisIncr plugin.
authored
380 set ww+=<,>
381 vmap <C-Left> x<Left>P`[v`]
382 vmap <C-Right> x<Right>P`[v`]
1b604b9 @nelstrom Patched Gundo.vim
authored
383 " Configure plugins {{{1
384 " Gundo.vim {{{2
385 map <Leader>u :GundoToggle<CR>
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
386
387 " TextObject customizations {{{2
0bc0b1a @nelstrom Map textobj-entire to `ia` and `aa`.
authored
388 " Entire text object {{{3
389 " Map text-object for entire buffer to `ia` and `aa`.
390 let g:textobj_entire_no_default_key_mappings = 1
391 xmap aa <Plug>(textobj-entire-a)
392 omap aa <Plug>(textobj-entire-a)
393 xmap ia <Plug>(textobj-entire-i)
394 omap ia <Plug>(textobj-entire-i)
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
395 " }}}
0926a83 @nelstrom Prevent Space.vim mappings from interfering with snipmate.
authored
396 " Space.vim {{{2
397 let g:space_disable_select_mode=1
6b03f6a @nelstrom Disable space.vim remappings for search.
authored
398 let g:space_no_search = 1
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
399
362a7ef @nelstrom Use solarized as default colorscheme.
authored
400 " Solarized {{{2
458a904 @nelstrom Use updated solarized bg toggle (F5 key).
authored
401 let g:solarized_visibility = "low"
362a7ef @nelstrom Use solarized as default colorscheme.
authored
402 set background=light
403 colorscheme solarized
458a904 @nelstrom Use updated solarized bg toggle (F5 key).
authored
404 call togglebg#map("<F5>")
5cc7da2 @nelstrom Upgrade to latest EasyMotion plugin, and use ',,' for leader.
authored
405 " EasyMotion {{{2
406 let g:EasyMotion_leader_key = ',,'
362a7ef @nelstrom Use solarized as default colorscheme.
authored
407
b75ce01 @nelstrom Prevent menus in mVim for Vimwiki and NERDcommenter.
authored
408 " Vim wiki {{{2
409 let g:vimwiki_menu=''
410 " NERDcommenter {{{2
411 let g:NERDMenuMode=0
eeb8c5a @nelstrom Added fold markers to vimrc.
authored
412 " Modelines: {{{1
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
413 " vim: nowrap fdm=marker
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
414 " }}}
Something went wrong with that request. Please try again.