Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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