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