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