a4652b917b8aa743909b89fa6e2ce94d7807ea15
[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 " Uncomment the next line to make Vim more Vi-compatible
22 " NOTE: debian.vim sets 'nocompatible', but only if debian.vim is available,
23 " so let's make sure we run in nocompatible mode:
24   set nocompatible
25
26 " Setting 'compatible' changes numerous
27 " options, so any other options should be set AFTER setting 'compatible'.
28 " set compatible
29
30   set backspace=indent,eol,start        " more powerful backspacing
31
32 " Now we set some defaults for the editor
33   set autoindent        " always set autoindenting on
34 " set linebreak         " Don't wrap words by default
35   set textwidth=0       " Don't wrap lines by default
36   set nobackup          " Don't keep a backup file
37   set viminfo='20,\"50  " read/write a .viminfo file, don't store more than
38                         " 50 lines of registers
39   set history=50        " keep 50 lines of command line history
40   set ruler             " show the cursor position all the time
41
42 " Suffixes that get lower priority when doing tab completion for filenames.
43 " These are files we are not likely to want to edit or read.
44   set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
45
46 " Vim5 and later versions support syntax highlighting.
47 " Just load the main syntax file when Vim was compiled with "+syntax".
48   if has("syntax")
49      syntax on
50   endif
51
52 " Debian uses compressed helpfiles. We must inform vim that the main
53 " helpfiles is compressed. Other helpfiles are stated in the tags-file.
54 " set helpfile=$VIMRUNTIME/doc/help.txt.gz
55
56 " If using a dark background within the editing area and syntax highlighting
57 " turn on this option as well
58   set background=dark
59
60 " begin of grml specials:
61 "  set list listchars=tab:»·
62 "  set listchars=eol:$,precedes:«,extends:»,tab:··,trail:·
63 " end of grml specials
64
65 " Uncomment the following to have Vim jump to the last position when
66 " reopening a file
67 " if has("autocmd")
68 "   au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
69 "     \| exe "normal g'\"" | endif
70 " endif
71
72 " Uncomment the following to have Vim load indentation rules according to the
73 " detected filetype. Per default Debian Vim only load filetype specific
74 " plugins.
75   if has("autocmd")
76     filetype indent on
77   endif
78
79 " The following are commented out as they cause vim to behave a lot
80 " differently from regular Vi. They are highly recommended though.
81   set showcmd           " Show (partial) command in status line.
82   set showmatch         " Show matching brackets.
83 " set ignorecase        " Do case insensitive matching
84 " set smartcase         " Do smart case matching
85 " set incsearch         " Incremental search
86 " set autowrite         " Automatically save before commands like :next and :make
87 " When switching between different buffers you can't use undo without 'set hidden':
88   set hidden            " Hide buffers when they are abandoned
89 " set mouse=a           " Enable mouse usage (all modes) in terminals
90   set wildmenu          " command-line completion operates in an enhanced mode
91
92   set pastetoggle=<f11>               " don't change text when copy/pasting
93   set dictionary=/usr/share/dict/word " used with CTRL-X CTRL-K
94
95 """ set the screen hardstatus to vim(filename.ext)
96   if ((&term =~ '^screen') && ($VIM_PLEASE_SET_TITLE =~ '^yes$') || has('gui_running'))
97     set t_ts=\ek
98     set t_fs=\e\
99     set title
100     autocmd BufEnter * let &titlestring = "vim(" . expand("%:t") . ")"
101     let &titleold = fnamemodify(&shell, ":t")
102   endif
103
104 " turn these ON:
105   set ek hidden ruler sc vb wmnu
106 " set digraph
107 " turn these OFF ("no" prefix):
108   set nodigraph noeb noet nosol
109 " non-toggles:
110   set bs=2 fo=cqrt ls=2 shm=at ww=<,>,h,l
111 " set bs=2 fo=cqrt ls=2 shm=at tw=72 ww=<,>,h,l
112   set comments=b:#,:%,fb:-,n:>,n:)
113 "  set list listchars=tab:»·,trail:·
114   set listchars=eol:$,precedes:«,extends:»,tab:»·,trail:·
115   set viminfo=%,'50,\"100,:100,n~/.viminfo
116   set tags=./tags,./TAGS,tags,TAGS,../tags,../../tags,../../../tags,../../../../tags
117
118 " autocommands:
119 " when the file type is "mail" then set the textwidth to "70":
120   if has("autocmd")
121      au FileType mail   set tw=70
122 " When editing a file, always jump to the last cursor position
123 "  au BufReadPost * if line("'\"") | exe "'\"" | endif
124      autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif
125   endif
126
127 " some colors - as an example "white on black" [use bold fonts]:
128 "  hi normal   ctermfg=white  ctermbg=black guifg=white  guibg=black
129 "  hi nontext  ctermfg=blue   ctermbg=black guifg=blue   guibg=black
130   if has("syntax")
131      syn on
132   endif
133 " set t_Co=256                " number of colors
134
135 " some useful mappings:
136   set pastetoggle=<f11>
137
138 " with F7 copy all current buffer to clipboard, or a selection.
139 " with shift-F7, paste all clipboard contents
140 " see: http://www.vim.org/tips/tip.php?tip_id=964
141   map   <F7>  :w !xclip<CR><CR>
142   vmap  <F7>  "*y
143   map <S-F7>  :r!xclip -o<CR>
144
145 " remove/delete trailing whitespace:
146   nmap ;tr :%s/\s\+$//
147   vmap ;tr  :s/\s\+$//
148
149 " execute the command in the current line (minus the first word, which
150 " is intended to be a shell prompt) and insert the output in the buffer
151   map ,e ^wy$:r!\12"\r
152
153 " update timestamp
154   iab YDATE <C-R>=strftime("%a %b %d %T %Z %Y")<CR>
155   map ,L  1G/Latest change:\s*/e+1<CR>CYDATE<ESC>
156
157 " the shell in a box mode. found in posting by Stefan `Sec` Zehl
158 " in newsgroup de.alt.sysadmin.recovery, msg­id:  <df7lhe$2hup$1@ice.42.org>
159 " Requires zsh for "print -P $PS1" / replace if needed.
160 " Your prompt should end in > (and only contain one)
161 " so run something like:
162 "   % export PS1='%n@%m > '
163 " in your zsh, press ',l' and <enter> for running commands, end mode via <esc>
164   map __start :imap <C-V><C-M> <C-O>__cmd<C-V>\|imap <C-V><ESC> <C-V><ESC>__end<C-M>
165   noremap __end :iunmap <C-V><CR>\|iunmap <C-V><ESC><C-M>:"Vish ended.<C-M>
166   noremap __cmd 0<ESC>f>ly$:r !<C-R>";print -P $PS1<C-M>A
167   noremap __scmd :r !print -P $PS1<c-M>A
168   map ,l __start__scmd
169
170 " Kill quote spaces (when quoting a quote)
171   map ,kqs mz:%s/^> >/>>/<cr>
172
173 " Interface to Mercurial Version Control
174   if filereadable( "/usr/share/doc/mercurial/examples/vim/hg-menu.vim" )
175     source /usr/share/doc/mercurial/examples/vim/hg-menu.vim
176   endif
177
178 " Vim 7 brings cool new features - see ':he version7'!
179 " The coolest features of Vim7 by mika
180 " ====================================
181 "  1) omni/intellisense completion: use CTRL-X CTRL-O in insert mode to start it [:he compl-omni]
182 "  2) internal grep: vimgrep foo bar [:he vimgrep]
183 "  3) tab pages: vim -p file1 file2 - then use the :tab command [:he tabpage]
184 "     gt -> next tab
185 "     gT -> previous tab
186 "  4) undo branches: :undolist / :earlier 2h / :later 2h
187 "     instead of using u (undo) and CTRL-R (redo), you might experiment with g-
188 "     and g+ to move through the text state [:he undolist]
189 "  5) browse remote directories via scp using netrw plugin: :edit scp://host//path/to/ [:he netrw.vim]
190 "  6) start editing the filename under the cursor and jump to the line
191 "     number following the file name: press gF [:he gF]
192 "  7) press 'CTRL-W F' to start editing the filename under the cursor in a new
193 "     window and jump to the line number following the file name. [:he CTRL-W_F]
194 "  8) spelling correction (see later for its configuration) [:he spell]:
195 "      ]s  -> Move to next misspelled word after the cursor.
196 "      zg  -> Add word under the cursor as a good word to the first name in 'spellfile'
197 "      zw  -> Like "zg" but mark the word as a wrong (bad) word.
198 "      z=  -> For the word under/after the cursor suggest correctly spelled words.
199 " 9)  highlight active cursor line using 'set cursorline' [:he cursorline]
200 " 10) delete inner quotes inside HTML-code using <C-O>cit (see its mapping later) [:he tag-blocks]
201 "
202 if version >= 700
203   " Thanks for some ideas to Christian 'strcat' Schneider and Julius Plenz
204   " turn spelling on by default:
205   "  set spell
206   " toggle spelling with F12 key:
207     map <F12> :set spell!<CR><Bar>:echo "Spell Check: " . strpart("OffOn", 3 * &spell, 3)<CR>
208     set spellfile=~/.vim/spellfile.add
209   " change language -  get spell files from http://ftp.vim.org/pub/vim/runtime/spell/ =>
210   " cd ~/.vim/spell && wget http://ftp.vim.org/pub/vim/runtime/spell/de.{latin1,utf-8}.spl
211   " change to german:
212   "  set spelllang=de
213   " highlight spelling correction:
214   "  highlight SpellBad    term=reverse   ctermbg=12 gui=undercurl guisp=Red       " badly spelled word
215   "  highlight SpellCap    term=reverse   ctermbg=9  gui=undercurl guisp=Blue      " word with wrong caps
216   "  highlight SpellRare   term=reverse   ctermbg=13 gui=undercurl guisp=Magenta   " rare word
217   "  highlight SpellLocale term=underline ctermbg=11 gui=undercurl guisp=DarkCyan  " word only exists in other region
218
219   " set maximum number of suggestions listed to top 10 items:
220   set sps=best,10
221
222   " highlight matching parens:
223   " set matchpairs=(:),[:],{:},< :>
224   " let loaded_matchparen = 1
225   " highlight MatchParen term=reverse   ctermbg=7   guibg=cornsilk
226
227   " highlight the cursor line and column:
228   " set cursorline
229   " highlight CursorLine   term=reverse   ctermbg=7   guibg=#333333
230   " highlight CursorColumn guibg=#333333
231
232   " change inner tag - very useful e.g. within HTML-code!
233   " ci" will remove the text between quotes, also works for ' and `
234   imap <F10> <C-O>cit
235
236   " use the popup menu also when there is only one match:
237   " set completeopt=menuone
238   " determine the maximum number of items to show in the popup menu for:
239   set pumheight=7
240   " set completion highlighting:
241   "  highlight Pmenu      ctermbg=13     guifg=Black   guibg=#BDDFFF              " normal item
242   "  highlight PmenuSel   ctermbg=7      guifg=Black   guibg=Orange               " selected item
243   "  highlight PmenuSbar  ctermbg=7      guifg=#CCCCCC guibg=#CCCCCC              " scrollbar
244   "  highlight PmenuThumb cterm=reverse  gui=reverse guifg=Black   guibg=#AAAAAA  " thumb of the scrollbar
245 endif
246
247
248 " To enable persistent undo uncomment following section.
249 " The undo files will be stored in $HOME/.cache/vim
250
251 " if version >= 703
252 " " enable persistent-undo
253 "  set undofile
254 "
255 "  " store the persistent undo file in ~/.cache/vim
256 "  set undodir=~/.cache/vim/
257 "
258 "  " create undodir directory if possible and does not exist yet
259 "  let targetdir=$HOME . "/.cache/vim"
260 "  if isdirectory(targetdir) != 1 && getftype(targetdir) == "" && exists("*mkdir")
261 "   call mkdir(targetdir, "p", 0700)
262 "  endif
263 " endif
264
265 " Source a global configuration file if available
266 " Deprecated by Debian but still supported by grml
267   if filereadable("/etc/vim/vimrc.local")
268     source /etc/vim/vimrc.local
269   endif
270
271 " source user-specific local configuration file
272   if filereadable(expand("$HOME/.vimrc.local"))
273     source $HOME/.vimrc.local
274   endif
275 "# END OF FILE #################################################################