]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vimrc
21958050e78cb60ea04715eb5d448f0dbc816665
[config/dotfiles.git] / vimrc
1 " Vim main configuration file.
2
3
4 " EDITOR SETTINGS
5
6 " Make sure Vim (and not Vi) settings are used.
7 set nocompatible
8
9 " Load my scripts from ~/.vim (my scripts) and ~/.vim/runtime (checkout of Vim
10 " runtime files).
11 set runtimepath-=~/.vim
12 set runtimepath^=~/.vim,~/.vim/runtime
13
14 " Disable modelines as they may cause security problems. Instead use
15 " securemodelines (Vim script #1876).
16 set nomodeline
17
18 " When completing paths first use the longest path then display a list of all
19 " possible files.
20 set wildmode=longest,list
21
22
23 " EDIT SETTINGS
24
25 " Enable automatic file detection, plugin and indention.
26 if has('autocmd')
27     filetype plugin indent on
28 endif
29
30 " Use UTF-8 file encoding for all files. Automatically recognize latin1 in
31 " existing files.
32 set fileencodings=utf-8,latin1
33
34 " Wrap text after 78 characters.
35 set textwidth=78
36
37 " Set tabs to 4 spaces, use softtabs.
38 set shiftwidth=4
39 set softtabstop=4
40 set expandtab
41 " When < and > is used indent/deindent to the next shiftwidth boundary.
42 set shiftround
43 " Use the default value for real tabs.
44 set tabstop=8
45
46 " Enable auto indention.
47 set autoindent
48
49 " When joining lines only add one space after a sentence.
50 set nojoinspaces
51
52 " Allow backspacing over autoindent and line breaks.
53 set backspace=indent,eol
54
55 " Start a comment when hitting enter after a commented line (r) and when using
56 " o or O around a commented line (o).
57 set formatoptions+=ro
58 " Don't break a line if was already longer then 'textwidth' when insert mode
59 " started.
60 set formatoptions+=l
61
62 " Allow virtual editing (cursor can be positioned anywhere, even when there is
63 " no character) in visual block mode.
64 set virtualedit=block
65
66 " Already display matches while typing the search command. This makes spotting
67 " errors easy.
68 set incsearch
69
70 " Activate syntax folding.
71 if has('folding')
72     set foldmethod=syntax
73     set foldcolumn=2
74     set foldlevel=99 " no closed folds at default, 'foldenable' would disable
75                      " folding which is not what I want
76 endif
77
78 " Only check for case if the searched word contains a capital character.
79 set ignorecase
80 set smartcase
81
82 " Activate spell checking, use English as default. Don't use spell checking
83 " when diffing.
84 if v:version >= 700 && !&diff
85     set spell
86     set spelllang=en_us
87 endif
88
89 " Allow buffers with changes to be hidden.
90 set hidden
91
92
93 " DISPLAY SETTINGS
94
95 " Use a dark background.
96 set background=dark
97
98 " Activate lines display.
99 set number
100 " Display the ruler with current line/file position.
101 set ruler
102 " Display partial commands in the status line.
103 set showcmd
104
105 " Visualize the line the cursor is currently in.
106 if v:version >= 700
107     set cursorline
108 endif
109
110 " Display tabs, trailing space, non breakable spaces and long lines (when
111 " wrapping is enabled).
112 set list
113 set listchars=trail:-,nbsp:!,extends:>
114
115
116 " MAPPINGS (except for plugins, see PLUGIN SETTINGS below)
117
118 " Use <space> to move down a page and - to move up one like in mutt.
119 nnoremap <Space> <C-f>
120 nnoremap - <C-b>
121
122 " Fast access to buffers.
123 nnoremap <Leader>1 :1b<CR>
124 nnoremap <Leader>2 :2b<CR>
125 nnoremap <Leader>3 :3b<CR>
126 nnoremap <Leader>4 :4b<CR>
127 nnoremap <Leader>5 :5b<CR>
128 nnoremap <Leader>6 :6b<CR>
129 nnoremap <Leader>7 :7b<CR>
130 nnoremap <Leader>8 :8b<CR>
131 nnoremap <Leader>9 :9b<CR>
132 nnoremap <Leader>0 :10b<CR>
133
134 " Maps to change spell language between English and German and disable it.
135 if v:version >= 700
136     map <Leader>sn :set nospell<CR>
137     map <Leader>se :set spell spelllang=en_us<CR>
138     map <Leader>sd :set spell spelllang=de_de<CR>
139 endif
140
141 " Add semicolon to the end of the line. Thanks to
142 " http://www.van-laarhoven.org/vim/.vimrc for this idea and godlygeek in #vim
143 " on Freenode for an improved version which doesn't clobber any marks.
144 nnoremap <silent> ; :call setline(line('.'), getline('.') . ';')<CR>
145
146 " I often type "W" instead of "w" when trying to save a file. Fix my mistake.
147 " Thanks to Tony Mechelynck <antoine.mechelynck@gmail.com> from the Vim
148 " mailing list for the commands.
149 if v:version < 700
150     cnoreabbrev W w
151     cnoreabbrev Wq wq
152     cnoreabbrev Wqa wqa
153 else
154     cnoreabbrev <expr> W
155         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'w' : 'W')
156     cnoreabbrev <expr> Wq
157         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'wq' : 'Wq')
158     cnoreabbrev <expr> Wqa
159         \ ((getcmdtype() == ':' && getcmdpos() <= 4) ? 'wqa' : 'Wqa')
160 endif
161 " Also fix my typo with "Q".
162 if v:version < 700
163     cnoreabbrev Q q
164     cnoreabbrev Qa qa
165 else
166     cnoreabbrev <expr> Q
167         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'q' : 'Q')
168     cnoreabbrev <expr> Qa
169         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'qa' : 'Qa')
170 endif
171
172 " Make sure xa0 (alt + space) is automatically changed to a normal whitespace
173 " if pressed accidentally while in insert mode (happens on Mac when alt
174 " doesn't send escape). filereadable() is necessary for Leopard were 'mac' is
175 " no longer set on the console.
176 if has('mac') || filereadable('/Users/.localized')
177     inoremap <Char-0xa0> <Space>
178 endif
179
180 " Disable Apple style movements in MacVim.
181 if has('gui_macvim') && has('eval')
182     let macvim_skip_cmd_opt_movement = 1
183 endif
184
185
186 " SYNTAX SETTINGS
187
188 " Activate syntax coloring.
189 if has('syntax')
190     syntax enable
191
192 " Highlight text longer then 78 characters. Thanks to Tony Mechelynck
193 " <antoine.mechelynck@gmail.com> from the Vim mailing list.
194     if v:version >= 700
195         2match Todo /\%>78v./
196     else
197         match Todo /\%>78v./
198     endif
199
200 " Highlight TODO, FIXME, CHANGED and XXX in all documents.
201     if v:version >= 701 && has('patch40')
202         call matchadd('Todo', '\(TODO\|FIXME\|CHANGED\|XXX\)')
203     endif
204 endif
205
206
207 " PLUGIN SETTINGS
208
209 " Settings for the NERD commenter.
210 " Don't create any mappings I don't want to use.
211 if has('eval')
212     let NERDCreateDefaultMappings = 0
213 endif
214 " Map toggle comment.
215 map <Leader><Leader> <plug>NERDCommenterToggle
216
217
218 " AUTO COMMANDS
219
220 " Use a custom auto group to prevent problems when the vimrc files is sourced
221 " twice.
222 if has('autocmd')
223     augroup vimrc
224         autocmd!
225
226 " Go to last position of opened files. Taken from :help last-position-jump.
227         autocmd BufReadPost *
228             \ if line("'\"") > 1 && line("'\"") <= line("$") |
229             \     execute "normal! g'\"" |
230             \ endif
231
232 " AFTER/FTPLUGIN AUTO COMMANDS
233
234 " Disable spell checking for files which don't need it.
235         autocmd FileType deb setlocal nospell
236         autocmd FileType diff setlocal nospell
237         autocmd FileType tar setlocal nospell
238 " Fix to allow Vim edit crontab files as crontab doesn't work with
239 " backupcopy=auto.
240         autocmd FileType crontab setlocal backupcopy=yes
241 " Don't use the modeline as the diff created by `git commit -v` may contain
242 " one which could change the filetype or other settings of the commit window.
243         autocmd FileType gitcommit setlocal nomodeline |
244                                  \ let g:secure_modelines_allowed_items = []
245 " Allow folding in perl.
246         autocmd FileType perl let perl_fold = 1 |
247                             \ let perl_fold_blocks = 1
248 " Use the same comment string as for Vim files in vimperator files.
249         autocmd FileType vimperator setlocal commentstring=\"%s
250
251 " FTDETECT AUTO COMMANDS
252
253 " Recognize .md as markdown files.
254         autocmd BufRead,BufNewFile *.md set filetype=mkd
255 " Recognize .test as Tcl files.
256         autocmd BufRead,BufNewFile *.test set filetype=tcl
257
258 " OTHER AUTO COMMANDS
259
260 " Use diff filetype for mercurial patches in patch queue.
261         autocmd BufReadPost */.hg/patches/* set filetype=diff
262
263     augroup END
264 endif