Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 298 lines (261 sloc) 8.308 kB
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
1 " Folding cheet sheet
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
110 set number
111 set cursorline
112 set tabstop=4
113 set softtabstop=4
114 set shiftwidth=4
115 set expandtab
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
116 set hidden
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
117 set listchars=tab:\ ,eol:¬
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
118 " Put swap files in /tmp file
119 set backupdir=~/tmp
120 set directory=~/tmp
121 if has("autocmd")
122 autocmd FileType html,css setlocal ts=2 sts=2 sw=2 expandtab
cdfbc49 @nelstrom vimrc: set filetype for .rss files to xml.
authored
123 autocmd BufNewFile,BufRead *.rss setfiletype xml
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
124 endif
125
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
126 " Toggles & Switches (Leader commands) {{{1
127 let mapleader = ","
b6171df @nelstrom Added `,s` map to toggle spellchecker.
authored
128 nmap <silent> <leader>l :set list!<CR>
129 nmap <silent> <leader>w :set wrap!<CR>
130 nmap <silent> <leader>s :set spell! spl=en_gb<CR>
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
131 nmap <silent> <leader>n :silent :nohlsearch<CR>
a28930c @nelstrom :Wrap command runs: set wrap linebreak nolist
authored
132 command! -nargs=* Wrap set wrap linebreak nolist
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
133
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
134 " Mappings {{{1
51f7097 @nelstrom Set the dir for backup/swap files to ~/tmp
authored
135 " Speed up buffer switching {{{2
b4992d4 @nelstrom Added vimrc sections for preferences and mappings.
authored
136 map <C-k> <C-W>k
137 map <C-j> <C-W>j
138 map <C-h> <C-W>h
139 map <C-l> <C-W>l
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
140 " Speed up tab switching {{{2
141 map <D-S-]> gt
142 map <D-S-[> gT
143 map <D-1> 1gt
144 map <D-2> 2gt
145 map <D-3> 3gt
146 map <D-4> 4gt
147 map <D-5> 5gt
148 map <D-6> 6gt
149 map <D-7> 7gt
150 map <D-8> 8gt
151 map <D-9> 9gt
152 map <D-0> :tablast<CR>
00fe231 @nelstrom Added mappings for easy j/k/$/0/^ on wrapped lines.
authored
153 " Shortcuts to make it easier to explore wrapped lines {{{2
154 " These come in handy when the following settings are enabled:
155 " :set linebreak wrap nolist
156 vmap <D-j> gj
157 vmap <D-k> gk
158 vmap <D-4> g$
159 vmap <D-6> g^
160 vmap <D-0> g^
161 nmap <D-j> gj
162 nmap <D-k> gk
163 nmap <D-4> g$
164 nmap <D-6> g^
165 nmap <D-0> g^
c3d9531 @nelstrom Added shortcuts to :e file in same dir as current file.
authored
166 " Shortcuts for opening file in same directory as current file {{{2
167 map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
168 map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
169 map <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR>
170 map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
79f398c @nelstrom Enable matchit plugin.
authored
171
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
172 " Easily modify vimrc {{{1
173 nmap <leader>v :e $MYVIMRC<CR>
174 " http://stackoverflow.com/questions/2400264/is-it-possible-to-apply-vim-configurations-without-restarting/2400289#2400289
175 if has("autocmd")
176 augroup myvimrchooks
177 au!
178 autocmd bufwritepost .vimrc source ~/.vimrc
179 augroup END
180 endif
181
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
182 " Custom commands and functions {{{1
183 " Show syntax highlighting groups for word under cursor {{{2
184 " Tip: http://stackoverflow.com/questions/1467438/find-out-to-which-highlight-group-a-particular-keyword-symbol-belongs-in-vim
185 nmap <C-S-P> :call <SID>SynStack()<CR>
186 function! <SID>SynStack()
187 if !exists("*synstack")
188 return
189 endif
190 echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
191 endfunc
192 " Set tabstop, softtabstop and shiftwidth to the same value {{{2
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
193 " From http://vimcasts.org/episodes/tabs-and-spaces/
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
194 command! -nargs=* Stab call Stab()
195 function! Stab()
196 let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
197 if l:tabstop > 0
198 let &l:sts = l:tabstop
199 let &l:ts = l:tabstop
200 let &l:sw = l:tabstop
201 endif
202 call SummarizeTabs()
203 endfunction
204
205 function! SummarizeTabs()
206 try
207 echohl ModeMsg
208 echon 'tabstop='.&l:ts
209 echon ' shiftwidth='.&l:sw
210 echon ' softtabstop='.&l:sts
211 if &l:et
212 echon ' expandtab'
213 else
214 echon ' noexpandtab'
215 end
216 finally
217 echohl None
218 endtry
219 endfunction
220
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
221 " Strip trailing whitespaces {{{2
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
222 function! Preserve(command)
223 " Preparation: save last search, and cursor position.
224 let _s=@/
225 let l = line(".")
226 let c = col(".")
227 " Do the business:
228 execute a:command
229 " Clean up: restore previous search history, and cursor position
230 let @/=_s
231 call cursor(l, c)
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
232 endfunction
ac46091 @nelstrom Refactored StripTrailingWhitespaces() to Preserve().
authored
233 nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
234 nmap _= :call Preserve("normal gg=G")<CR>
235
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
236 " Search for current visual selection with */# {{{2
237 " Tip tip from: http://amix.dk/blog/viewEntry/19334
238 function! CmdLine(str)
239 exe "menu Foo.Bar :" . a:str
240 emenu Foo.Bar
241 unmenu Foo
242 endfunction
243
244 function! VisualSearch(direction) range
245 let l:saved_reg = @"
246 execute "normal! vgvy"
247
248 let l:pattern = escape(@", '\\/.*$^~[]')
249 let l:pattern = substitute(l:pattern, "\n$", "", "")
250
251 if a:direction == 'b'
252 execute "normal ?" . l:pattern . "^M"
253 elseif a:direction == 'gv'
254 call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
255 elseif a:direction == 'f'
256 execute "normal /" . l:pattern . "^M"
257 endif
258
259 let @/ = l:pattern
260 let @" = l:saved_reg
261 endfunction
262
263 "Basically you press * or # to search for the current selection
264 "then 'n' should search forward, 'N' should search backwards.
265 vnoremap <silent> * :call VisualSearch('f')<CR>
266 vnoremap <silent> # :call VisualSearch('b')<CR>
267 vnoremap <silent> gv :call VisualSearch('gv')<CR>
268
269 " Status line {{{1
270 " Good article on setting a statusline:
271 " http://got-ravings.blogspot.com/2008/08/vim-pr0n-making-statuslines-that-own.html
272
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
273 " Mappings for a recovering TextMate user {{{1
274 " Indentation {{{2
275 nmap <D-[> <<
276 nmap <D-]> >>
277 vmap <D-[> <gv
278 vmap <D-]> >gv
ff45eb9 @nelstrom Added visual star command, and TextMate/NERD comment toggle.
authored
279
280 " Commenting {{{2
281 " requires NERDCommenter plugin
282 vmap <D-/> ,c<space>gv
283 map <D-/> ,c<space>
284
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
285 " Move selection {{{2
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
286 " Move current line down/up
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
287 map <C-Down> ddp
288 map <C-Up> dd<Up>P
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
289 " Move visually selected lines down/up
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
290 vmap <C-Down> xp`[V`]
291 vmap <C-Up> x<Up>P`[V`]
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
292 " Move visual selection back/forwards
79be99f @nelstrom Added section for custom functions, and TextMate maps.
authored
293 vmap <C-Left> x<BS>P`[v`]
294 vmap <C-Right> x<Space>P`[v`]
eeb8c5a @nelstrom Added fold markers to vimrc.
authored
295 " Modelines: {{{1
8e17b15 @nelstrom Set mapleader and make .vimrc easier to edit.
authored
296 " vim: nowrap fdm=marker
926b0da @nelstrom Added folding cheet sheet for noobs.
authored
297 " }}}
Something went wrong with that request. Please try again.