Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 411 lines (374 sloc) 12.511 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`]
70e1881 @nelstrom Add mappings to trigger :Tabularize for common tokens.
authored
192 " Alignment commands {{{1
193 if exists(":Tabularize")
194 nmap <Leader>a= :Tabularize /=<CR>
195 vmap <Leader>a= :Tabularize /=<CR>
196 nmap <Leader>a: :Tabularize /:\zs<CR>
197 vmap <Leader>a: :Tabularize /:\zs<CR>
198 endif
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
199 " TextObject tweaks {{{1
b829495 @nelstrom Switch out `Va/it` for `va/iT` mappings.
authored
200 nnoremap viT vitVkoj
201 nnoremap vaT vatV
e84cb01 @nelstrom Add insert mode ctrl-e jump to end of line.
authored
202 " Insert mode mappings {{{1
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
203 " emacs style jump to end of line
e84cb01 @nelstrom Add insert mode ctrl-e jump to end of line.
authored
204 imap <C-e> <C-o>A
be24c35 @nelstrom Create cmd-enter mapping to 'o' in insert mode.
authored
205 imap <C-a> <C-o>I
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
206 " 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
207 imap <C-Enter> <C-o>o
208 imap <C-S-Enter> <C-o>O
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
209 " Easily modify vimrc {{{1
210 nmap <leader>v :e $MYVIMRC<CR>
211 " http://stackoverflow.com/questions/2400264/is-it-possible-to-apply-vim-configurations-without-restarting/2400289#2400289
212 if has("autocmd")
213 augroup myvimrchooks
214 au!
cbaea1f @nelstrom Reload vimrc and gvimrc whenever either one is saved.
authored
215 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
216 augroup END
217 endif
218
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
219 " Custom commands and functions {{{1
362a7ef @nelstrom Use solarized as default colorscheme.
authored
220 " Create a :Quickfixdo command, to match :argdo/bufdo/windo {{{2
e924edf @nelstrom Add quickfix to arglist functions/commands.
authored
221 " Define a command to make it easier to use
b7377ef @nelstrom New :Qargs command populates arglist from quickfix.
authored
222 command! -nargs=* Qargs execute 'args ' . QuickfixFilenames()
e924edf @nelstrom Add quickfix to arglist functions/commands.
authored
223 function! QuickfixFilenames()
224 " Building a hash ensures we get each buffer only once
225 let buffer_numbers = {}
226 for quickfix_item in getqflist()
227 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
228 endfor
229 return join(values(buffer_numbers))
230 endfunction
231
232 command! -nargs=+ QFDo call QFDo(<q-args>)
233 " Function that does the work
234 function! QFDo(command)
235 " Create a dictionary so that we can get the list of buffers rather than
236 " the list of lines in buffers (easy way to get unique entries)
237 let buffer_numbers = {}
238 " For each entry, use the buffer number as a dictionary key (won't get
239 " repeats)
240 for fixlist_entry in getqflist()
241 let buffer_numbers[fixlist_entry['bufnr']] = 1
242 endfor
243 " Make it into a list as it seems cleaner
244 let buffer_number_list = keys(buffer_numbers)
245
246 " For each buffer
247 for num in buffer_number_list
248 " Select the buffer
249 exe 'buffer' num
250 " Run the command that's passed as an argument
251 exe a:command
252 " Save if necessary
253 update
254 endfor
255 endfunction
256 " 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
257 " Show syntax highlighting groups for word under cursor {{{2
258 " Tip: http://stackoverflow.com/questions/1467438/find-out-to-which-highlight-group-a-particular-keyword-symbol-belongs-in-vim
259 nmap <C-S-P> :call <SID>SynStack()<CR>
260 function! <SID>SynStack()
261 if !exists("*synstack")
262 return
263 endif
264 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
265 endfunc
abe4af4 @nelstrom Added command `:Only` which closes hidden buffers.
authored
266 " Wipe all buffers which are not active (i.e. not visible in a window/tab) {{{2
267 " http://stackoverflow.com/questions/2974192/how-can-i-pare-down-vims-buffer-list-to-only-include-active-buffers
268 " http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
269 command! -nargs=* Only call CloseHiddenBuffers()
270 function! CloseHiddenBuffers()
271 " figure out which buffers are visible in any tab
272 let visible = {}
273 for t in range(1, tabpagenr('$'))
274 for b in tabpagebuflist(t)
275 let visible[b] = 1
276 endfor
277 endfor
278 " close any buffer that are loaded and not visible
279 let l:tally = 0
280 for b in range(1, bufnr('$'))
281 if bufloaded(b) && !has_key(visible, b)
282 let l:tally += 1
283 exe 'bw ' . b
284 endif
285 endfor
286 echon "Deleted " . l:tally . " buffers"
287 endfun
288
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
289 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
290 " From http://vimcasts.org/episodes/tabs-and-spaces/
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
291 command! -nargs=* Stab call Stab()
292 function! Stab()
293 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
294 if l:tabstop > 0
295 let &l:sts = l:tabstop
296 let &l:ts = l:tabstop
297 let &l:sw = l:tabstop
298 endif
299 call SummarizeTabs()
300 endfunction
301
302 function! SummarizeTabs()
303 try
304 echohl ModeMsg
305 echon 'tabstop='.&l:ts
306 echon ' shiftwidth='.&l:sw
307 echon ' softtabstop='.&l:sts
308 if &l:et
309 echon ' expandtab'
310 else
311 echon ' noexpandtab'
312 end
313 finally
314 echohl None
315 endtry
316 endfunction
317
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
318 " Strip trailing whitespaces {{{2
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
319 function! Preserve(command)
320 " Preparation: save last search, and cursor position.
321 let _s=@/
322 let l = line(".")
323 let c = col(".")
324 " Do the business:
325 execute a:command
326 " Clean up: restore previous search history, and cursor position
327 let @/=_s
328 call cursor(l, c)
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
329 endfunction
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
330 nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
331 nmap _= :call Preserve("normal gg=G")<CR>
92009f6 @nelstrom Added :Refactor command, for dictionary-based substitutions.
authored
332 " Swap words in a single substitution command {{{2
333 " http://stackoverflow.com/questions/765894/can-i-substitute-multiple-items-in-a-single-regular-expression-in-vim-or-perl/766093#766093
334 function! Refactor(dict) range
335 execute a:firstline . ',' . a:lastline . 's/\C\<\%(' . join(keys(a:dict),'\|'). '\)\>/\='.string(a:dict).'[submatch(0)]/ge'
336 endfunction
337 command! -range=% -nargs=1 Refactor :<line1>,<line2>call Refactor(<args>)
338
339 " Running :Refactor {'quick':'slow', 'lazy':'energetic'} will change the following text:
340 " The quick brown fox ran quickly next to the lazy brook.
341 "into:
342 " The slow brown fox ran slowly next to the energetic brook.
343
344 " TODO: create a :Swap command, which turns:
345 " :Swap(portrait,landscape)
346 " into
347 " :Refactor {'portrait':'landscape', 'landscape':'portrait'}
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
348
349 " Status line {{{1
350 " Good article on setting a statusline:
351 " http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
70b5a18 @nelstrom Make status line always visible.
authored
352 " Always show the status line (even if no split windows)
353 set laststatus=2
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
354 " Mappings for a recovering TextMate user {{{1
355 " Indentation {{{2
356 nmap <D-[> <<
357 nmap <D-]> >>
358 vmap <D-[> <gv
359 vmap <D-]> >gv
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
360
361 " Commenting {{{2
362 " requires NERDCommenter plugin
363 vmap <D-/> ,c<space>gv
364 map <D-/> ,c<space>
365
529cd6f @nelstrom Add then comment out a line-duplication mapping.
authored
366 " Duplicate selection {{{2
367 "vmap <S-C-D> :copy'> <CR>V`[o
368 "nmap <S-C-D> :copy .<CR>
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
369 " Move selection {{{2
9c88d4d @nelstrom Added VisIncr plugin.
authored
370 " Move current line down/up
371 map <C-Down> ]e
372 map <C-Up> [e
373 " Move visually selected lines down/up
374 vmap <C-Down> ]egv
375 vmap <C-Up> [egv
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
376 " Move visual selection back/forwards
9c88d4d @nelstrom Added VisIncr plugin.
authored
377 set ww+=<,>
378 vmap <C-Left> x<Left>P`[v`]
379 vmap <C-Right> x<Right>P`[v`]
1b604b9 @nelstrom Patched Gundo.vim
authored
380 " Configure plugins {{{1
381 " Gundo.vim {{{2
382 map <Leader>u :GundoToggle<CR>
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
383
384 " TextObject customizations {{{2
0bc0b1a @nelstrom Map textobj-entire to `ia` and `aa`.
authored
385 " Entire text object {{{3
386 " Map text-object for entire buffer to `ia` and `aa`.
387 let g:textobj_entire_no_default_key_mappings = 1
388 xmap aa <Plug>(textobj-entire-a)
389 omap aa <Plug>(textobj-entire-a)
390 xmap ia <Plug>(textobj-entire-i)
391 omap ia <Plug>(textobj-entire-i)
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
392 " }}}
0926a83 @nelstrom Prevent Space.vim mappings from interfering with snipmate.
authored
393 " Space.vim {{{2
394 let g:space_disable_select_mode=1
6b03f6a @nelstrom Disable space.vim remappings for search.
authored
395 let g:space_no_search = 1
b75ddd5 @nelstrom Notes on customizing textobj-entire.
authored
396
362a7ef @nelstrom Use solarized as default colorscheme.
authored
397 " Solarized {{{2
398 set background=light
399 colorscheme solarized
400 if has("autocmd")
401 " For some reason, opening a vimoutliner file switches to another
402 " colorscheme. This prevents that from happening.
403 autocmd FileType vo_base :colorscheme solarized
404 endif
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
eeb8c5a @nelstrom Added fold markers to vimrc.
authored
408 " Modelines: {{{1
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
409 " vim: nowrap fdm=marker
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
410 " }}}
Something went wrong with that request. Please try again.