Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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