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