Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 378 lines (337 sloc) 11.286 kb
9c88d4d Drew Neil Added VisIncr plugin.
authored
1 " Folding cheet sheet
926b0da Drew Neil Added folding cheet sheet for noobs.
authored
2 " zR open all folds
3 " zM close all folds
ff45eb9 Drew Neil 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 Drew Neil 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 Drew Neil Added fold markers to vimrc.
authored
12 " An example for a vimrc file. {{{1
84d14ea Drew Neil 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 Drew Neil Fixed typo: (e -> endif).
authored
107 endif
eeb8c5a Drew Neil Added fold markers to vimrc.
authored
108
b4992d4 Drew Neil Added vimrc sections for preferences and mappings.
authored
109 " Preferences {{{1
4c820ae Drew Neil Switched off the irritating bell
authored
110 set visualbell t_vb=
b4992d4 Drew Neil 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 Drew Neil Added section for custom functions, and TextMate maps.
authored
117 set hidden
b4992d4 Drew Neil Added vimrc sections for preferences and mappings.
authored
118 set listchars=tab:\ ,eol:¬
87d722a Drew Neil Set spelling region to British English by default.
authored
119 "set spelllang=en_gb
51f7097 Drew Neil Set the dir for backup/swap files to ~/tmp
authored
120 " Put swap files in /tmp file
121 set backupdir=~/tmp
122 set directory=~/tmp
123 if has("autocmd")
8c8f894 Drew Neil Updated plugins.
authored
124 autocmd FileType html,css,scss,ruby setlocal ts=2 sts=2 sw=2 expandtab
980112a Drew Neil Added whitespace prefs for ruby+javascript.
authored
125 autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
3f3f96c Drew Neil Enable linebreak for markdown files.
authored
126 autocmd FileType markdown setlocal wrap linebreak nolist
cdfbc49 Drew Neil vimrc: set filetype for .rss files to xml.
authored
127 autocmd BufNewFile,BufRead *.rss setfiletype xml
65769a0 Drew Neil For PML files, use XML filetype (not promela)
authored
128 ".pml is automatically set to 'promela'. Override to use XML
129 " lifted from: https://github.com/tpope/vim-markdown/blob/34e28b3f6f6d702ff2963b8196eccae9344ed4bc/ftdetect/markdown.vim
130 autocmd BufNewFile,BufRead *.pml
131 \ if &ft =~# '^\%(promela\)$' |
132 \ set ft=xml |
133 \ else |
134 \ setf xml |
135 \ endif
136
51f7097 Drew Neil Set the dir for backup/swap files to ~/tmp
authored
137 endif
138
8e17b15 Drew Neil Set mapleader and make .vimrc easier to edit.
authored
139 " Toggles & Switches (Leader commands) {{{1
140 let mapleader = ","
b6171df Drew Neil Added `,s` map to toggle spellchecker.
authored
141 nmap <silent> <leader>l :set list!<CR>
142 nmap <silent> <leader>w :set wrap!<CR>
87d722a Drew Neil Set spelling region to British English by default.
authored
143 nmap <silent> <leader>s :set spell!<CR>
8e17b15 Drew Neil Set mapleader and make .vimrc easier to edit.
authored
144 nmap <silent> <leader>n :silent :nohlsearch<CR>
a28930c Drew Neil :Wrap command runs: set wrap linebreak nolist
authored
145 command! -nargs=* Wrap set wrap linebreak nolist
51867d9 Drew Neil Add :Maxsize command to use full window.
authored
146 command! -nargs=* Maxsize set columns=1000 lines=1000
8e17b15 Drew Neil Set mapleader and make .vimrc easier to edit.
authored
147
b4992d4 Drew Neil Added vimrc sections for preferences and mappings.
authored
148 " Mappings {{{1
51f7097 Drew Neil Set the dir for backup/swap files to ~/tmp
authored
149 " Speed up buffer switching {{{2
b4992d4 Drew Neil Added vimrc sections for preferences and mappings.
authored
150 map <C-k> <C-W>k
151 map <C-j> <C-W>j
152 map <C-h> <C-W>h
153 map <C-l> <C-W>l
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
154 " Speed up tab switching {{{2
155 map <D-S-]> gt
156 map <D-S-[> gT
157 map <D-1> 1gt
158 map <D-2> 2gt
159 map <D-3> 3gt
160 map <D-4> 4gt
161 map <D-5> 5gt
162 map <D-6> 6gt
163 map <D-7> 7gt
164 map <D-8> 8gt
165 map <D-9> 9gt
166 map <D-0> :tablast<CR>
00fe231 Drew Neil Added mappings for easy j/k/$/0/^ on wrapped lines.
authored
167 " Shortcuts to make it easier to explore wrapped lines {{{2
168 " These come in handy when the following settings are enabled:
169 " :set linebreak wrap nolist
170 vmap <D-j> gj
171 vmap <D-k> gk
172 vmap <D-4> g$
173 vmap <D-6> g^
174 vmap <D-0> g^
175 nmap <D-j> gj
176 nmap <D-k> gk
177 nmap <D-4> g$
178 nmap <D-6> g^
179 nmap <D-0> g^
c3d9531 Drew Neil Added shortcuts to :e file in same dir as current file.
authored
180 " Shortcuts for opening file in same directory as current file {{{2
181 map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
182 map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
183 map <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR>
184 map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
9c88d4d Drew Neil Added VisIncr plugin.
authored
185 " Shortcuts for visual selections {{{2
186 nmap gV `[v`]
92009f6 Drew Neil Added :Refactor command, for dictionary-based substitutions.
authored
187 " TextObject tweaks {{{1
b829495 Drew Neil Switch out `Va/it` for `va/iT` mappings.
authored
188 nnoremap viT vitVkoj
189 nnoremap vaT vatV
e84cb01 Drew Neil Add insert mode ctrl-e jump to end of line.
authored
190 " Insert mode mappings {{{1
92009f6 Drew Neil Added :Refactor command, for dictionary-based substitutions.
authored
191 " emacs style jump to end of line
e84cb01 Drew Neil Add insert mode ctrl-e jump to end of line.
authored
192 imap <C-e> <C-o>A
be24c35 Drew Neil Create cmd-enter mapping to 'o' in insert mode.
authored
193 imap <C-a> <C-o>I
92009f6 Drew Neil Added :Refactor command, for dictionary-based substitutions.
authored
194 " Open line above (ctrl-shift-o much easier than ctrl-o shift-O)
be24c35 Drew Neil Create cmd-enter mapping to 'o' in insert mode.
authored
195 imap <C-Enter> <C-o>o
196 imap <C-S-Enter> <C-o>O
8e17b15 Drew Neil Set mapleader and make .vimrc easier to edit.
authored
197 " Easily modify vimrc {{{1
198 nmap <leader>v :e $MYVIMRC<CR>
199 " http://stackoverflow.com/questions/2400264/is-it-possible-to-apply-vim-configurations-without-restarting/2400289#2400289
200 if has("autocmd")
201 augroup myvimrchooks
202 au!
203 autocmd bufwritepost .vimrc source ~/.vimrc
204 augroup END
205 endif
206
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
207 " Custom commands and functions {{{1
208 " Show syntax highlighting groups for word under cursor {{{2
209 " Tip: http://stackoverflow.com/questions/1467438/find-out-to-which-highlight-group-a-particular-keyword-symbol-belongs-in-vim
210 nmap <C-S-P> :call <SID>SynStack()<CR>
211 function! <SID>SynStack()
212 if !exists("*synstack")
213 return
214 endif
215 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
216 endfunc
abe4af4 Drew Neil Added command `:Only` which closes hidden buffers.
authored
217 " Wipe all buffers which are not active (i.e. not visible in a window/tab) {{{2
218 " http://stackoverflow.com/questions/2974192/how-can-i-pare-down-vims-buffer-list-to-only-include-active-buffers
219 " http://stackoverflow.com/questions/1534835/how-do-i-close-all-buffers-that-arent-shown-in-a-window-in-vim
220 command! -nargs=* Only call CloseHiddenBuffers()
221 function! CloseHiddenBuffers()
222 " figure out which buffers are visible in any tab
223 let visible = {}
224 for t in range(1, tabpagenr('$'))
225 for b in tabpagebuflist(t)
226 let visible[b] = 1
227 endfor
228 endfor
229 " close any buffer that are loaded and not visible
230 let l:tally = 0
231 for b in range(1, bufnr('$'))
232 if bufloaded(b) && !has_key(visible, b)
233 let l:tally += 1
234 exe 'bw ' . b
235 endif
236 endfor
237 echon "Deleted " . l:tally . " buffers"
238 endfun
239
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
240 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
241 " From http://vimcasts.org/episodes/tabs-and-spaces/
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
242 command! -nargs=* Stab call Stab()
243 function! Stab()
244 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
245 if l:tabstop > 0
246 let &l:sts = l:tabstop
247 let &l:ts = l:tabstop
248 let &l:sw = l:tabstop
249 endif
250 call SummarizeTabs()
251 endfunction
252
253 function! SummarizeTabs()
254 try
255 echohl ModeMsg
256 echon 'tabstop='.&l:ts
257 echon ' shiftwidth='.&l:sw
258 echon ' softtabstop='.&l:sts
259 if &l:et
260 echon ' expandtab'
261 else
262 echon ' noexpandtab'
263 end
264 finally
265 echohl None
266 endtry
267 endfunction
268
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
269 " Strip trailing whitespaces {{{2
ac46091 Drew Neil Refactored StripTrailingWhitespaces() to Preserve().
authored
270 function! Preserve(command)
271 " Preparation: save last search, and cursor position.
272 let _s=@/
273 let l = line(".")
274 let c = col(".")
275 " Do the business:
276 execute a:command
277 " Clean up: restore previous search history, and cursor position
278 let @/=_s
279 call cursor(l, c)
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
280 endfunction
ac46091 Drew Neil Refactored StripTrailingWhitespaces() to Preserve().
authored
281 nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
282 nmap _= :call Preserve("normal gg=G")<CR>
283
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
284 " Search for current visual selection with */# {{{2
285 " Tip tip from: http://amix.dk/blog/viewEntry/19334
286 function! CmdLine(str)
287 exe "menu Foo.Bar :" . a:str
288 emenu Foo.Bar
289 unmenu Foo
290 endfunction
291
292 function! VisualSearch(direction) range
293 let l:saved_reg = @"
294 execute "normal! vgvy"
295
296 let l:pattern = escape(@", '\\/.*$^~[]')
297 let l:pattern = substitute(l:pattern, "\n$", "", "")
298
299 if a:direction == 'b'
300 execute "normal ?" . l:pattern . "^M"
301 elseif a:direction == 'gv'
302 call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
303 elseif a:direction == 'f'
304 execute "normal /" . l:pattern . "^M"
305 endif
306
307 let @/ = l:pattern
308 let @" = l:saved_reg
309 endfunction
92009f6 Drew Neil Added :Refactor command, for dictionary-based substitutions.
authored
310 " Swap words in a single substitution command {{{2
311 " http://stackoverflow.com/questions/765894/can-i-substitute-multiple-items-in-a-single-regular-expression-in-vim-or-perl/766093#766093
312 function! Refactor(dict) range
313 execute a:firstline . ',' . a:lastline . 's/\C\<\%(' . join(keys(a:dict),'\|'). '\)\>/\='.string(a:dict).'[submatch(0)]/ge'
314 endfunction
315 command! -range=% -nargs=1 Refactor :<line1>,<line2>call Refactor(<args>)
316
317 " Running :Refactor {'quick':'slow', 'lazy':'energetic'} will change the following text:
318 " The quick brown fox ran quickly next to the lazy brook.
319 "into:
320 " The slow brown fox ran slowly next to the energetic brook.
321
322 " TODO: create a :Swap command, which turns:
323 " :Swap(portrait,landscape)
324 " into
325 " :Refactor {'portrait':'landscape', 'landscape':'portrait'}
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
326
327 "Basically you press * or # to search for the current selection
328 "then 'n' should search forward, 'N' should search backwards.
329 vnoremap <silent> * :call VisualSearch('f')<CR>
330 vnoremap <silent> # :call VisualSearch('b')<CR>
331 vnoremap <silent> gv :call VisualSearch('gv')<CR>
332
333 " Status line {{{1
334 " Good article on setting a statusline:
335 " http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
70b5a18 Drew Neil Make status line always visible.
authored
336 " Always show the status line (even if no split windows)
337 set laststatus=2
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
338 " Mappings for a recovering TextMate user {{{1
339 " Indentation {{{2
340 nmap <D-[> <<
341 nmap <D-]> >>
342 vmap <D-[> <gv
343 vmap <D-]> >gv
ff45eb9 Drew Neil Added visual star command, and TextMate/NERD comment toggle.
authored
344
345 " Commenting {{{2
346 " requires NERDCommenter plugin
347 vmap <D-/> ,c<space>gv
348 map <D-/> ,c<space>
349
79be99f Drew Neil Added section for custom functions, and TextMate maps.
authored
350 " Move selection {{{2
9c88d4d Drew Neil Added VisIncr plugin.
authored
351 " Move current line down/up
352 map <C-Down> ]e
353 map <C-Up> [e
354 " Move visually selected lines down/up
355 vmap <C-Down> ]egv
356 vmap <C-Up> [egv
926b0da Drew Neil Added folding cheet sheet for noobs.
authored
357 " Move visual selection back/forwards
9c88d4d Drew Neil Added VisIncr plugin.
authored
358 set ww+=<,>
359 vmap <C-Left> x<Left>P`[v`]
360 vmap <C-Right> x<Right>P`[v`]
1b604b9 Drew Neil Patched Gundo.vim
authored
361 " Configure plugins {{{1
362 " Gundo.vim {{{2
363 map <Leader>u :GundoToggle<CR>
b75ddd5 Drew Neil Notes on customizing textobj-entire.
authored
364
365 " TextObject customizations {{{2
0bc0b1a Drew Neil Map textobj-entire to `ia` and `aa`.
authored
366 " Entire text object {{{3
367 " Map text-object for entire buffer to `ia` and `aa`.
368 let g:textobj_entire_no_default_key_mappings = 1
369 xmap aa <Plug>(textobj-entire-a)
370 omap aa <Plug>(textobj-entire-a)
371 xmap ia <Plug>(textobj-entire-i)
372 omap ia <Plug>(textobj-entire-i)
b75ddd5 Drew Neil Notes on customizing textobj-entire.
authored
373 " }}}
374
eeb8c5a Drew Neil Added fold markers to vimrc.
authored
375 " Modelines: {{{1
8e17b15 Drew Neil Set mapleader and make .vimrc easier to edit.
authored
376 " vim: nowrap fdm=marker
926b0da Drew Neil Added folding cheet sheet for noobs.
authored
377 " }}}
Something went wrong with that request. Please try again.