]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vimrc
vimrc: Add maps for fast access to buffers.
[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 " When completing paths first use the longest path then display a list of all
15 " possible files.
16 set wildmode=longest,list
17
18 " Increase number of tabs which can be opened with the -p option.
19 if v:version >= 700
20     set tabpagemax=50
21 endif
22
23
24 " EDIT SETTINGS
25
26 " Enable automatic file detection, plugin and indention.
27 if has("autocmd")
28     filetype plugin indent on
29 endif
30
31 " Use UTF-8 file encoding for all files.
32 set fileencodings=utf-8
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 easily.
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.
83 if v:version >= 700
84     set spell
85     set spelllang=en_us
86 endif
87
88 " Allow buffers with changes to be hidden.
89 set hidden
90
91
92 " DISPLAY SETTINGS
93
94 " Use a dark background.
95 set background=dark
96
97 " Activate lines display.
98 set number
99 " Display the ruler with current line/file position.
100 set ruler
101 " Display partial commands in the status line.
102 set showcmd
103
104 " Visualize the line the cursor is currently in.
105 if v:version >= 700
106     set cursorline
107 endif
108
109 " Display tabs, trailing space, non breakable spaces and long lines (when
110 " wrapping is enabled).
111 set list
112 set listchars=trail:-,nbsp:!,extends:>
113
114
115 " MAPPINGS (except for plugins, see PLUGIN SETTINGS below)
116
117 " Use <space> to move down a page and - to move up one like in mutt.
118 nnoremap <Space> <C-f>
119 nnoremap - <C-b>
120
121 " Fast access to buffers.
122 nnoremap <Leader>1 :1b<CR>
123 nnoremap <Leader>2 :2b<CR>
124 nnoremap <Leader>3 :3b<CR>
125 nnoremap <Leader>4 :4b<CR>
126 nnoremap <Leader>5 :5b<CR>
127 nnoremap <Leader>6 :6b<CR>
128 nnoremap <Leader>7 :7b<CR>
129 nnoremap <Leader>8 :8b<CR>
130 nnoremap <Leader>9 :9b<CR>
131 nnoremap <Leader>0 :10b<CR>
132
133 " Maps to change spell language between English and German and disable it.
134 if v:version >= 700
135     map <Leader>sn :set nospell<CR>
136     map <Leader>se :set spell spelllang=en_us<CR>
137     map <Leader>sd :set spell spelllang=de_de<CR>
138 endif
139
140 " Add semicolon to the end of the line. Thanks to
141 " http://www.van-laarhoven.org/vim/.vimrc for this idea and godlygeek in #vim
142 " on Freenode for an improved version which doesn't clobber any marks.
143 nnoremap <silent> ; :call setline(line('.'), getline('.') . ';')<CR>
144
145 " I often type "W" instead of "w" when trying to save a file. Fix my mistake.
146 " Thanks to Tony Mechelynck <antoine.mechelynck@gmail.com> from the Vim
147 " mailing list for the commands.
148 if v:version < 700
149     cnoreabbrev W w
150     cnoreabbrev Wq wq
151     cnoreabbrev Wqa wqa
152 else
153     cnoreabbrev <expr> W
154         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'w' : 'W')
155     cnoreabbrev <expr> Wq
156         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'wq' : 'Wq')
157     cnoreabbrev <expr> Wqa
158         \ ((getcmdtype() == ':' && getcmdpos() <= 4) ? 'wqa' : 'Wqa')
159 endif
160 " Also fix my typo with "Q".
161 if v:version < 700
162     cnoreabbrev Q q
163     cnoreabbrev Qa qa
164 else
165     cnoreabbrev <expr> Q
166         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'q' : 'Q')
167     cnoreabbrev <expr> Qa
168         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'qa' : 'Qa')
169 endif
170
171 " Make sure xa0 (alt + space) is automatically changed to a normal whitespace
172 " if pressed accidentally while in insert mode (happens on Mac sometimes).
173 if has("mac")
174     imap <Char-0xa0> <Space>
175 endif
176
177 " Disable Apple style movements in MacVim.
178 if has("gui_macvim") && has("eval")
179     let macvim_skip_cmd_opt_movement = 1
180 endif
181
182
183 " SYNTAX SETTINGS
184
185 " Activate syntax coloring.
186 if has("syntax")
187     syntax enable
188
189 " Highlight text longer then 78 characters. Thanks to Tony Mechelynck
190 " <antoine.mechelynck@gmail.com> from the Vim mailing list.
191     if v:version >= 700
192         2match Todo /\%>78v./
193     else
194         match Todo /\%>78v./
195     endif
196 endif
197
198
199 " PLUGIN SETTINGS
200
201 " Settings for the NERD commenter.
202 " Don't create any mappings I don't want to use.
203 if has("eval")
204     let NERDCreateDefaultMappings = 0
205 endif
206 " Map toggle comment.
207 map <Leader><Leader> <plug>NERDCommenterToggle
208
209
210 " AUTO COMMANDS
211
212 " Use a custom auto group to prevent problems when the vimrc files is sourced
213 " twice.
214 if has("autocmd")
215     augroup vimrc
216         autocmd!
217
218 " Use diff filetype for mercurial patches in patch queue.
219         autocmd BufReadPost */.hg/patches/* set filetype=diff
220
221     augroup END
222 endif