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