1 " Vim main configuration file.
6 " Make sure Vim (and not Vi) settings are used.
9 " Load my scripts from ~/.vim (my scripts) and ~/.vim/runtime (checkout of Vim
11 set runtimepath-=~/.vim
12 set runtimepath^=~/.vim,~/.vim/runtime
14 " Disable modelines as they may cause security problems. Instead use
15 " securemodelines (Vim script #1876).
18 " When completing paths first use the longest path then display a list of all
20 set wildmode=longest,list
25 " Enable automatic file detection, plugin and indention support.
27 filetype plugin indent on
30 " Use UTF-8 file encoding for all files. Automatically recognize latin1 in
32 set fileencodings=utf-8,latin1
34 " Wrap text after 78 characters.
37 " Set tabs to 4 spaces, use softtabs.
41 " When < and > is used indent/deindent to the next 'shiftwidth' boundary.
43 " Use the default value for real tabs.
46 " Enable auto indention.
49 " When joining lines only add one space after a sentence.
52 " Allow backspacing over autoindent and line breaks.
53 set backspace=indent,eol
55 " Start a comment when hitting enter after a commented line (r) and when using
56 " o or O around a commented line (o).
58 " Don't break a line if was already longer then 'textwidth' when insert mode
62 " Allow virtual editing (cursor can be positioned anywhere, even when there is
63 " no character) in visual block mode.
66 " Already display matches while typing the search command. This makes spotting
70 " Activate syntax folding.
74 set foldlevel=99 " no closed folds at default, 'foldenable' would disable
75 " folding which is not what I want
78 " Only check for case if the searched word contains a capital character.
82 " Activate spell checking, use English as default. Don't use spell checking
84 if v:version >= 700 && has('syntax') && !&diff
89 " Allow buffers with changes to be hidden. Very important for effective
90 " editing with multiple buffers.
96 " Use a dark background. Doesn't change the background color, only sets text
97 " colors for a dark terminal.
100 " Display line numbers.
102 " Display the ruler with current line/file position.
104 " Display partial commands in the status line.
107 " Visualize the line the cursor is currently in.
112 " Display tabs, trailing space, non breakable spaces and long lines (when
113 " wrapping is enabled).
115 set listchars=trail:-,extends:>
117 set listchars+=nbsp:!
120 " Always display the status line even if there is only one window.
126 " MAPPINGS (except for plugins, see PLUGIN SETTINGS below)
128 " Use <space> to move down a page and - to move up one like in mutt.
129 nnoremap <Space> <C-f>
132 " Fast access to buffers.
133 nnoremap <Leader>1 :1b<CR>
134 nnoremap <Leader>2 :2b<CR>
135 nnoremap <Leader>3 :3b<CR>
136 nnoremap <Leader>4 :4b<CR>
137 nnoremap <Leader>5 :5b<CR>
138 nnoremap <Leader>6 :6b<CR>
139 nnoremap <Leader>7 :7b<CR>
140 nnoremap <Leader>8 :8b<CR>
141 nnoremap <Leader>9 :9b<CR>
142 nnoremap <Leader>0 :10b<CR>
144 " Make last active window the only window. Similar to <C-w> o.
145 nnoremap <C-w>O <C-w>p<C-w>o
147 " Maps to change spell language between English and German and disable spell
150 map <Leader>sn :set nospell<CR>
151 map <Leader>se :set spell spelllang=en_us<CR>
152 map <Leader>sd :set spell spelllang=de_de<CR>
155 " Add semicolon to the end of the line. Thanks to
156 " http://www.van-laarhoven.org/vim/.vimrc for this idea and godlygeek in #vim
157 " on Freenode for an improved version which doesn't clobber any marks.
158 nnoremap <silent> <Leader>; :call setline(line('.'), getline('.') . ';')<CR>
160 " I often type "W" instead of "w" when trying to save a file. Fix my mistake.
161 " Thanks to Tony Mechelynck <antoine.mechelynck@gmail.com> from the Vim
162 " mailing list for the commands.
170 \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'w' : 'W')
171 cnoreabbrev <expr> Wa
172 \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'wa' : 'Wa')
173 cnoreabbrev <expr> Wq
174 \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'wq' : 'Wq')
175 cnoreabbrev <expr> Wqa
176 \ ((getcmdtype() == ':' && getcmdpos() <= 4) ? 'wqa' : 'Wqa')
178 " Also fix my typo with "Q".
184 \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'q' : 'Q')
185 cnoreabbrev <expr> Qa
186 \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'qa' : 'Qa')
189 " Make sure xa0 (alt + space) is automatically changed to a normal whitespace
190 " if pressed accidentally while in insert mode (happens on Mac when alt
191 " doesn't send escape). filereadable() is necessary for Leopard were 'mac' is
192 " no longer set on the console.
193 if has('mac') || filereadable('/Users/.localized')
194 inoremap <Char-0xa0> <Space>
197 " Disable Apple style movements in MacVim.
198 if has('gui_macvim') && has('eval')
199 let macvim_skip_cmd_opt_movement = 1
205 " Activate syntax coloring.
209 " Highlight lines longer than 78 characters. Thanks to Tony Mechelynck
210 " <antoine.mechelynck@gmail.com> from the Vim mailing list.
211 " It can easily be disabled if necessary with :2match (in Vim >= 700).
213 2match Todo /\%>78v./
218 " Highlight TODO, FIXME, CHANGED and XXX in all documents.
219 if v:version > 701 || (v:version == 701 && has('patch42'))
220 call matchadd('Todo', '\(TODO\|FIXME\|CHANGED\|XXX\)')
227 " Settings for the NERD commenter.
228 " Don't create any mappings I don't want to use.
230 let NERDCreateDefaultMappings = 0
232 " Map toggle comment.
233 map <Leader><Leader> <plug>NERDCommenterToggle
238 " Use a custom auto group to prevent problems when the vimrc files is sourced
244 " Go to last position of opened files. Taken from :help last-position-jump.
245 autocmd BufReadPost *
246 \ if line("'\"") > 1 && line("'\"") <= line("$") |
247 \ execute "normal! g'\"" |
249 " But not for Git commits, go to beginning of the file.
250 autocmd BufReadPost COMMIT_EDITMSG normal! gg
252 " AFTER/FTPLUGIN AUTO COMMANDS
254 " Disable spell checking for files which don't need it.
255 autocmd FileType deb setlocal nospell
256 autocmd FileType diff setlocal nospell
257 autocmd FileType tar setlocal nospell
258 " Fix to allow Vim edit crontab files as crontab doesn't work with
260 autocmd FileType crontab setlocal backupcopy=yes
261 " Don't use the modeline in git commits as the diff created by `git commit -v`
262 " may contain one which could change the filetype or other settings of the
263 " commit buffer. Also make sure we use only 72 characters per line which is
264 " the recommendation for git commit messages (http://tpope.net/node/106).
265 autocmd FileType gitcommit setlocal nomodeline |
266 \ let g:secure_modelines_allowed_items = [] |
267 \ setlocal textwidth=72
268 " Allow folding in perl.
269 autocmd FileType perl let perl_fold = 1 |
270 \ let perl_fold_blocks = 1
271 " Use the same comment string as for Vim files in Vimperator files.
272 autocmd FileType vimperator setlocal commentstring=\"%s
274 " FTDETECT AUTO COMMANDS
276 " Recognize .md as markdown files (Vim default is .mkd).
277 autocmd BufRead,BufNewFile *.md set filetype=mkd
278 " Recognize .test as Tcl files.
279 autocmd BufRead,BufNewFile *.test set filetype=tcl
281 " OTHER AUTO COMMANDS
283 " Use diff filetype for mercurial patches in patch queue.
284 autocmd BufReadPost */.hg/patches/* set filetype=diff