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