Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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