Skip to content

HTTPS clone URL

Subversion checkout URL

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