]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vimrc
vimrc: Move some settings to EDITOR SETTINGS.
[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 folding at default
75 endif
76
77 " Only check for case if the searched word contains a capital character.
78 set ignorecase
79 set smartcase
80
81 " Activate spell checking, use English as default.
82 if v:version >= 700
83     set spell
84     set spelllang=en_us
85 endif
86
87
88 " DISPLAY SETTINGS
89
90 " Use a dark background.
91 set background=dark
92
93 " Activate lines display.
94 set number
95 " Display the ruler with current line/file position.
96 set ruler
97 " Display partial commands in the status line.
98 set showcmd
99
100 " Visualize the line the cursor is currently in.
101 if v:version >= 700
102     set cursorline
103 endif
104
105 " Display tabs as "^I" and trailing space as "-".
106 set list
107 set listchars=trail:-
108
109
110 " MAPPINGS (except for plugins, see PLUGIN SETTINGS below)
111
112 " Use <space> to move down a page and - to move up one like in mutt.
113 nnoremap <Space> <C-f>
114 nnoremap - <C-b>
115
116 " Maps to change spell language between English and German.
117 map <Leader>se :set spelllang=en_us<CR>
118 map <Leader>sd :set spelllang=de_de<CR>
119
120 " Add semicolon to the end of the line. Thanks to
121 " http://www.van-laarhoven.org/vim/.vimrc for this idea and godlygeek in #vim
122 " for an improved version which doesn't clobber any marks.
123 nnoremap <silent> ; :call setline(line('.'), getline('.') . ';')<CR>
124
125 " I often type "W" instead of "w" when trying to save a file. Fix my mistake.
126 " Thanks to Tony Mechelynck <antoine.mechelynck@gmail.com> from the Vim
127 " mailing list for the commands.
128 if v:version < 700
129     cnoreabbrev W w
130     cnoreabbrev Wq wq
131     cnoreabbrev Wqa wqa
132 else
133     cnoreabbrev <expr> W
134         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'w' : 'W')
135     cnoreabbrev <expr> Wq
136         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'wq' : 'Wq')
137     cnoreabbrev <expr> Wqa
138         \ ((getcmdtype() == ':' && getcmdpos() <= 4) ? 'wqa' : 'Wqa')
139 endif
140 " Also fix my typo with "Q".
141 if v:version < 700
142     cnoreabbrev Q q
143     cnoreabbrev Qa qa
144 else
145     cnoreabbrev <expr> Q
146         \ ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'q' : 'Q')
147     cnoreabbrev <expr> Qa
148         \ ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'qa' : 'Qa')
149 endif
150
151 " Make sure xa0 (alt + space) is automatically changed to a normal whitespace
152 " if pressed accidentally while in insert mode (happens on Mac sometimes).
153 if has("mac")
154     imap <Char-0xa0> <Space>
155 endif
156
157 " Disable Apple style movements in MacVim.
158 if has("gui_macvim") && has("eval")
159     let macvim_skip_cmd_opt_movement = 1
160 endif
161
162
163 " SYNTAX SETTINGS
164
165 " Activate syntax coloring.
166 if has("syntax")
167     syntax enable
168
169 " Highlight text longer then 78 characters. Thanks to Tony Mechelynck
170 " <antoine.mechelynck@gmail.com> from the Vim mailing list.
171     if v:version >= 700
172         2match Todo /\%>78v./
173     else
174         match Todo /\%>78v./
175     endif
176 endif
177
178
179 " PLUGIN SETTINGS
180
181 " Settings for the NERD commenter.
182 " Don't create any mappings I don't want to use.
183 if has("eval")
184     let NERDCreateDefaultMappings = 0
185 endif
186 " Map toggle comment.
187 map <Leader><Leader> <plug>NERDCommenterToggle
188
189
190 " AUTO COMMANDS
191
192 " Use a custom auto group to prevent problems when the vimrc files is sourced
193 " twice.
194 if has("autocmd")
195     augroup vimrc
196         autocmd!
197
198 " Use diff filetype for mercurial patches in patch queue.
199         autocmd BufReadPost */.hg/patches/* set filetype=diff
200
201     augroup END
202 endif