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