vimrc: support vim-tiny and older versions of vim
[grml-etc-core.git] / etc / vim / vimrc
1 " Filename:      /etc/vim/vimrc
2 " Purpose:       configuration file for vim
3 " Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 " Bug-Reports:   see http://grml.org/bugs/
5 " License:       This file is licensed under the GPL v2.
6 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
7
8 " All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
9 " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime you
10 " can find below.  If you wish to change any of those settings, you should do it
11 " in the file /etc/vim/vimrc.local, since debian.vim will be overwritten
12 " everytime an upgrade of the vim packages is performed and this file
13 " (/etc/vim/vimrc) every time the package grml-etc-core is upgraded.  It is
14 " recommended to make changes after sourcing debian.vim since it alters the
15 " value of the 'compatible' option.
16
17 " This line should not be removed as it ensures that various options are
18 " properly set to work with the Vim-related packages available in Debian.
19 runtime! debian.vim
20
21 " | Begin of defaults.vim related stuff {
22 " |
23 " | Comments starting with a bar ('|') are added by the Grml-Team
24 " | and the settings below override the default.vim configuration everything
25 " | else is copied from $VIMRUNTIME/defaults.vim.
26 " |
27 " | Do *not* source $VIMRUNTIME/defaults.vim (in case no user vimrc is found),
28 " | since that prevents overwriting values we want to set in this file,
29 " | instead we set settings similar to what can be found in default.vim below
30 " |
31 " | Only do this part when Vim was compiled with the +eval feature.
32 if 1
33   let g:skip_defaults_vim=1
34 endif
35
36 " Use Vim settings, rather than Vi settings (much better!).
37 " This must be first, because it changes other options as a side effect.
38 " Avoid side effects when it was already reset.
39 if &compatible
40   set nocompatible
41 endif
42
43 " When the +eval feature is missing, the set command above will be skipped.
44 " Use a trick to reset compatible only when the +eval feature is missing.
45 silent! while 0
46   set nocompatible
47 silent! endwhile
48
49 " Allow backspacing over everything in insert mode.
50 set backspace=indent,eol,start
51
52 set history=200         " keep 200 lines of command line history
53 set ruler               " show the cursor position all the time
54 set showcmd             " display incomplete commands
55 set wildmenu            " display completion matches in a status line
56
57 set ttimeout            " time out for key codes
58 set ttimeoutlen=100     " wait up to 100ms after Esc for special key
59
60 " Show @@@ in the last line if it is truncated.
61 " | This features is only available in later versions
62 if has("patch-7.4.2115")
63   set display=truncate
64 endif
65
66 " Show a few lines of context around the cursor.  Note that this makes the
67 " text scroll if you mouse-click near the start or end of the window.
68 set scrolloff=5
69
70 " Do incremental searching when it's possible to timeout.
71 if has('reltime')
72   set incsearch
73 endif
74
75 " Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
76 " confusing.
77 set nrformats-=octal
78
79 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
80 if has('win32')
81   set guioptions-=t
82 endif
83
84 " Don't use Ex mode, use Q for formatting.
85 " Revert with ":unmap Q".
86 map Q gq
87
88 " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
89 " so that you can undo CTRL-U after inserting a line break.
90 " Revert with ":iunmap <C-U>".
91 inoremap <C-U> <C-G>u<C-U>
92
93 " In many terminal emulators the mouse works just fine.  By enabling it you
94 " can position the cursor, Visually select and scroll with the mouse.
95 "
96 " | We prefer to disable the mouse usage though and use what we're used
97 " | from older Vim versions.
98 " |
99 " | if has('mouse')
100 " |   set mouse=a
101 " | endif
102 if has('mouse')
103   set mouse=
104 endif
105
106 " Switch syntax highlighting on when the terminal has colors or when using the
107 " GUI (which always has colors).
108 if &t_Co > 2 || has("gui_running")
109   " Revert with ":syntax off".
110   syntax on
111
112   " I like highlighting strings inside C comments.
113   " Revert with ":unlet c_comment_strings".
114   let c_comment_strings=1
115 endif
116
117 " Only do this part when Vim was compiled with the +eval feature.
118 if 1
119
120   " Enable file type detection.
121   " Use the default filetype settings, so that mail gets 'tw' set to 72,
122   " 'cindent' is on in C files, etc.
123   " Also load indent files, to automatically do language-dependent indenting.
124   " Revert with ":filetype off".
125   filetype plugin indent on
126
127   " Put these in an autocmd group, so that you can revert them with:
128   " ":augroup vimStartup | au! | augroup END"
129   augroup vimStartup
130     au!
131
132     " When editing a file, always jump to the last known cursor position.
133     " Don't do it when the position is invalid, when inside an event handler
134     " (happens when dropping a file on gvim) and for a commit message (it's
135     " likely a different one than last time).
136     autocmd BufReadPost *
137       \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
138       \ |   exe "normal! g`\""
139       \ | endif
140
141   augroup END
142
143 endif
144
145 " Convenient command to see the difference between the current buffer and the
146 " file it was loaded from, thus the changes you made.
147 " Only define it when not defined already.
148 " Revert with: ":delcommand DiffOrig".
149 if !exists(":DiffOrig")
150   command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
151                   \ | wincmd p | diffthis
152 endif
153
154 if has('langmap') && exists('+langremap')
155   " Prevent that the langmap option applies to characters that result from a
156   " mapping.  If set (default), this may break plugins (but it's backward
157   " compatible).
158   set nolangremap
159 endif
160
161 " | End of defaults.vim related stuff }
162
163 " Begin of custom Grml configuration {
164 " The Grml-Team believes that the options and configuration values which override
165 " the Vim defaults are useful and helpful for our users.
166 "
167 " A lot of options are Grml defaults since the very start and we cleaned up as
168 " much as possible but if you do not like any of these settings feel free to
169 " change them back in your user vimrc or file a bug and tell us to change the
170 " default.
171 "
172 " The idea behind commented out options and configuration values is to show
173 " you interesting settings you should know about but we did not set them by
174 " default because they might have to much of an impact for everyone.
175 "
176 " If a commented option precedes an option set by us it usually shows the
177 " Vim default.
178
179   set autoindent                            " always set autoindenting on
180   set dictionary=/usr/share/dict/words      " used with CTRL-X CTRL-K
181   set esckeys                               " recognize keys that start with <Esc> in insert mode
182   set formatoptions=cqrt                    " list of flags that tell how automatic formatting works
183   set laststatus=2                          " when to use a status line for the last window
184   set nobackup                              " don't keep a backup file
185   set noerrorbells                          " don't ring the bell (beep or screen flash) for error messages
186   set nostartofline                         " keep cursor in the same column (if possible) when moving cursor
187   set pastetoggle=<f11>                     " don't change text when copy/pasting
188   set shortmess=at                          " list of flags to make messages shorter
189   set showmatch                             " show matching brackets.
190   set textwidth=0                           " don't wrap lines by default
191   set viminfo=%,'100,<100,s10,h             " what to store in .viminfo file
192   set visualbell                            " use a visual bell instead of beeping
193   set whichwrap=<,>,h,l                     " list of flags specifying which commands wrap to another line
194
195 " set expandtab                             " Use appropriate number of spaces to insert a <Tab>
196 " set linebreak                             " Don't wrap words by default
197   set ignorecase                            " Do case insensitive matching
198   set smartcase                             " Do smart case matching
199 " set autowrite                             " Automatically save before commands like :next and :make
200 " set nodigraph                             " enter characters that normally cannot be entered by an ordinary keyboard
201
202 " list of strings used for list mode
203 " set list listchars=eol:$
204   if (&encoding =~ 'utf-8')
205     set listchars=eol:$,precedes:«,extends:»,tab:»·,trail:·
206   else
207     set listchars=eol:$
208   endif
209
210 " list of file names to search for tags
211 " set tags=./tags,tags
212   set tags=./tags,./TAGS,tags,TAGS,../tags,../../tags,../../../tags,../../../../tags
213
214 " When switching between different buffers you can't use undo without 'set hidden':
215   set hidden                                " Hide buffers when they are abandoned
216
217 " Suffixes that get lower priority when doing tab completion for filenames.
218 " These are files we are not likely to want to edit or read.
219 " set suffixes=.bak,~,.o,.h,.info,.swp,.obj
220   set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
221
222 " set the screen hardstatus to vim(filename.ext)
223   if ((&term =~ '^screen') && ($VIM_PLEASE_SET_TITLE =~ '^yes$') || has('gui_running'))
224     set t_ts=\ek
225     set t_fs=\e\
226     set title
227     if has("autocmd")
228       autocmd BufEnter * let &titlestring = "vim(" . expand("%:t") . ")"
229     endif
230     let &titleold = fnamemodify(&shell, ":t")
231   endif
232
233 " autocommands:
234   if has("autocmd")
235      " when the file type is "mail" then set the textwidth to "70":
236      autocmd FileType mail   set tw=70
237   endif
238
239 " some useful mappings:
240
241 " remove/delete trailing whitespace:
242   nmap ;tr :%s/\s\+$//
243   vmap ;tr  :s/\s\+$//
244
245 " execute the command in the current line (minus the first word, which
246 " is intended to be a shell prompt) and insert the output in the buffer
247   map ,e ^wy$:r!\12"\r
248
249 " update timestamp
250   iab YDATE <C-R>=strftime("%a %b %d %T %Z %Y")<CR>
251   map ,L  1G/Latest change:\s*/e+1<CR>CYDATE<ESC>
252
253 " Vim 7 brings cool new features - see ':he version7'!
254 " The coolest features of Vim7 by mika
255 " ====================================
256 "  1) omni/intellisense completion: use CTRL-X CTRL-O in insert mode to start it [:he compl-omni]
257 "  2) internal grep: vimgrep foo bar [:he vimgrep]
258 "  3) tab pages: vim -p file1 file2 - then use the :tab command [:he tabpage]
259 "     gt -> next tab
260 "     gT -> previous tab
261 "  4) undo branches: :undolist / :earlier 2h / :later 2h
262 "     instead of using u (undo) and CTRL-R (redo), you might experiment with g-
263 "     and g+ to move through the text state [:he undolist]
264 "  5) browse remote directories via scp using netrw plugin: :edit scp://host//path/to/ [:he netrw.vim]
265 "  6) start editing the filename under the cursor and jump to the line
266 "     number following the file name: press gF [:he gF]
267 "  7) press 'CTRL-W F' to start editing the filename under the cursor in a new
268 "     window and jump to the line number following the file name. [:he CTRL-W_F]
269 "  8) spelling correction (see later for its configuration) [:he spell]:
270 "      ]s  -> Move to next misspelled word after the cursor.
271 "      zg  -> Add word under the cursor as a good word to the first name in 'spellfile'
272 "      zw  -> Like "zg" but mark the word as a wrong (bad) word.
273 "      z=  -> For the word under/after the cursor suggest correctly spelled words.
274 " 9)  highlight active cursor line using 'set cursorline' [:he cursorline]
275 " 10) delete inner quotes inside HTML-code using <C-O>cit (see its mapping later) [:he tag-blocks]
276 "
277 if version >= 700
278   " Thanks for some ideas to Christian 'strcat' Schneider and Julius Plenz
279   " turn spelling on by default:
280   "  set spell
281   " toggle spelling with F12 key:
282     map <F12> :set spell!<CR><Bar>:echo "Spell Check: " . strpart("OffOn", 3 * &spell, 3)<CR>
283     set spellfile=~/.vim/spellfile.add
284   " change language -  get spell files from http://ftp.vim.org/pub/vim/runtime/spell/ =>
285   " cd ~/.vim/spell && wget http://ftp.vim.org/pub/vim/runtime/spell/de.{latin1,utf-8}.spl
286   " change to german:
287   "  set spelllang=de
288   " highlight spelling correction:
289   "  highlight SpellBad    term=reverse   ctermbg=12 gui=undercurl guisp=Red       " badly spelled word
290   "  highlight SpellCap    term=reverse   ctermbg=9  gui=undercurl guisp=Blue      " word with wrong caps
291   "  highlight SpellRare   term=reverse   ctermbg=13 gui=undercurl guisp=Magenta   " rare word
292   "  highlight SpellLocale term=underline ctermbg=11 gui=undercurl guisp=DarkCyan  " word only exists in other region
293
294   " set maximum number of suggestions listed top 10 items:
295   set spellsuggest=best,10
296
297   " highlight matching parens:
298   " set matchpairs=(:),[:],{:},< :>
299   " let loaded_matchparen = 1
300   " highlight MatchParen term=reverse   ctermbg=7   guibg=cornsilk
301
302   " highlight the cursor line and column:
303   " set cursorline
304   " highlight CursorLine   term=reverse   ctermbg=7   guibg=#333333
305   " highlight CursorColumn guibg=#333333
306
307   " change inner tag - very useful e.g. within HTML-code!
308   " ci" will remove the text between quotes, also works for ' and `
309   imap <F10> <C-O>cit
310
311   " use the popup menu also when there is only one match:
312   " set completeopt=menuone
313   " determine the maximum number of items to show in the popup menu for:
314   set pumheight=7
315   " set completion highlighting:
316   "  highlight Pmenu      ctermbg=13     guifg=Black   guibg=#BDDFFF              " normal item
317   "  highlight PmenuSel   ctermbg=7      guifg=Black   guibg=Orange               " selected item
318   "  highlight PmenuSbar  ctermbg=7      guifg=#CCCCCC guibg=#CCCCCC              " scrollbar
319   "  highlight PmenuThumb cterm=reverse  gui=reverse guifg=Black   guibg=#AAAAAA  " thumb of the scrollbar
320 endif
321
322 " To enable persistent undo uncomment following section.
323 " The undo files will be stored in $HOME/.cache/vim
324
325 " if version >= 703
326 " " enable persistent-undo
327 "  set undofile
328 "
329 "  " store the persistent undo file in ~/.cache/vim
330 "  set undodir=~/.cache/vim/
331 "
332 "  " create undodir directory if possible and does not exist yet
333 "  let targetdir=$HOME . "/.cache/vim"
334 "  if isdirectory(targetdir) != 1 && getftype(targetdir) == "" && exists("*mkdir")
335 "   call mkdir(targetdir, "p", 0700)
336 "  endif
337 " endif
338
339 " Source a global configuration file if available
340   if filereadable("/etc/vim/vimrc.local")
341     source /etc/vim/vimrc.local
342   endif
343
344 " source user-specific local configuration file
345 "
346 " NOTE: If this vimrc file is used as system vimrc the initialization of Vim looks like this:
347 "
348 "   `system-vimrc (this file) + /etc/vim/vimrc.local + $HOME/.vimrc.local -> user-vimrc`
349 "
350 " This means that user-vimrc overrides the settings set in `$HOME/.vimrc.local`.
351 "
352 " If this file is used as user-vimrc the initialization of Vim looks like this
353 "
354 "   `system-vimrc + /etc/vim/vimrc.local -> user-vimrc (this file) + /etc/vim/vimrc.local + $HOME/.vimrc.local`
355 "
356 " This means that `/etc/vim/vimrc.local` + `$HOME/.vimrc.local` overrides the
357 " settings set in the user-vimrc (and `/etc/vim/vimrc.local` is sourced twice).
358 "
359 " Either way, this might or might not be something a user would expect.
360   if filereadable(expand("$HOME/.vimrc.local"))
361     source $HOME/.vimrc.local
362   endif
363
364 " End of custom Grml configuration }
365
366 "# END OF FILE #################################################################