Skip to content

HTTPS clone URL

Subversion checkout URL

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