vimrc: enable features only if available; update changelog for upload
[grml-etc-core.git] / etc / skel / .vimrc
1 " Filename:      .vimrc
2 " Purpose:       configuration file for editor 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 " Thanks to Sven Guckes for his template!
8 "###############################################################################
9
10 " be no-compatible with vi
11   set nocp
12 " turn these ON:
13   set ek hidden ruler sc vb wmnu
14 " set digraph
15 " turn these OFF ("no" prefix):
16   set nodigraph noeb noet nosol
17 " non-toggles:
18   set bs=2 fo=cqrt ls=2 shm=at ww=<,>,h,l
19 " set bs=2 fo=cqrt ls=2 shm=at tw=72 ww=<,>,h,l
20   set comments=b:#,:%,fb:-,n:>,n:)
21 "  set list listchars=tab:»·,trail:·
22   set listchars=eol:$,precedes:«,extends:»,tab:»·,trail:·
23   set viminfo=%,'50,\"100,:100,n~/.viminfo
24   set tags=./tags,./TAGS,tags,TAGS,../tags,../../tags,../../../tags,../../../../tags
25
26 " autocommands:
27 " when the file type is "mail" then set the textwidth to "70":
28   if has("autocmd")
29      au FileType mail   set tw=70
30 " When editing a file, always jump to the last cursor position
31 "  au BufReadPost * if line("'\"") | exe "'\"" | endif
32      autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif
33   endif
34
35 " some colors - as an example "white on black" [use bold fonts]:
36 "  hi normal   ctermfg=white  ctermbg=black guifg=white  guibg=black
37 "  hi nontext  ctermfg=blue   ctermbg=black guifg=blue   guibg=black
38   if has("syntax")
39      syn on
40   endif
41 " set t_Co=256                " number of colors
42
43 " some useful mappings:
44   set pastetoggle=<f11>
45
46 " with F7 copy all current buffer to clipboard, or a selection.
47 " with shift-F7, paste all clipboard contents
48 " see: http://www.vim.org/tips/tip.php?tip_id=964
49   map   <F7>  :w !xclip<CR><CR>
50   vmap  <F7>  "*y
51   map <S-F7>  :r!xclip -o<CR>
52
53 " remove/delete trailing whitespace:
54   nmap ;tr :%s/\s\+$//
55   vmap ;tr  :s/\s\+$//
56
57 " execute the command in the current line (minus the first word, which
58 " is intended to be a shell prompt) and insert the output in the buffer
59   map ,e ^wy$:r!\12"\r
60
61 " update timestamp
62   iab YDATE <C-R>=strftime("%a %b %d %T %Z %Y")<CR>
63   map ,L  1G/Latest change:\s*/e+1<CR>CYDATE<ESC>
64
65 " the shell in a box mode. found in posting by Stefan `Sec` Zehl
66 " in newsgroup de.alt.sysadmin.recovery, msg­id:  <df7lhe$2hup$1@ice.42.org>
67 " Requires zsh for "print -P $PS1" / replace if needed.
68 " Your prompt should end in > (and only contain one)
69 " so run something like:
70 "   % export PS1='%n@%m > '
71 " in your zsh, press ',l' and <enter> for running commands, end mode via <esc>
72   map __start :imap <C-V><C-M> <C-O>__cmd<C-V>\|imap <C-V><ESC> <C-V><ESC>__end<C-M>
73   noremap __end :iunmap <C-V><CR>\|iunmap <C-V><ESC><C-M>:"Vish ended.<C-M>
74   noremap __cmd 0<ESC>f>ly$:r !<C-R>";print -P $PS1<C-M>A
75   noremap __scmd :r !print -P $PS1<c-M>A
76   map ,l __start__scmd
77
78 " Kill quote spaces (when quoting a quote)
79   map ,kqs mz:%s/^> >/>>/<cr>
80
81 " Interface to Mercurial Version Control
82   if filereadable( "/usr/share/doc/mercurial/examples/vim/hg-menu.vim" )
83     source /usr/share/doc/mercurial/examples/vim/hg-menu.vim
84   endif
85
86 " source local configuration file
87   if filereadable(expand("$HOME/.vimrc.local"))
88      source $HOME/.vimrc.local
89   endif
90
91 " Vim 7 brings cool new features - see ':he version7'!
92 " The coolest features of Vim7 by mika
93 " ====================================
94 "  1) omni/intellisense completion: use CTRL-X CTRL-O in insert mode to start it [:he compl-omni]
95 "  2) internal grep: vimgrep foo bar [:he vimgrep]
96 "  3) tab pages: vim -p file1 file2 - then use the :tab command [:he tabpage]
97 "     gt -> next tab
98 "     gT -> previous tab
99 "  4) undo branches: :undolist / :earlier 2h / :later 2h
100 "     instead of using u (undo) and CTRL-R (redo), you might experiment with g-
101 "     and g+ to move through the text state [:he undolist]
102 "  5) browse remote directories via scp using netrw plugin: :edit scp://host//path/to/ [:he netrw.vim]
103 "  6) start editing the filename under the cursor and jump to the line
104 "     number following the file name: press gF [:he gF]
105 "  7) press 'CTRL-W F' to start editing the filename under the cursor in a new
106 "     window and jump to the line number following the file name. [:he CTRL-W_F]
107 "  8) spelling correction (see later for its configuration) [:he spell]:
108 "      ]s  -> Move to next misspelled word after the cursor.
109 "      zg  -> Add word under the cursor as a good word to the first name in 'spellfile'
110 "      zw  -> Like "zg" but mark the word as a wrong (bad) word.
111 "      z=  -> For the word under/after the cursor suggest correctly spelled words. 
112 " 9)  highlight active cursor line using 'set cursorline' [:he cursorline]
113 " 10) delete inner quotes inside HTML-code using <C-O>cit (see its mapping later) [:he tag-blocks]
114 "
115 if version >= 700
116   " Thanks for some ideas to Christian 'strcat' Schneider and Julius Plenz
117   " turn spelling on by default:
118   "  set spell
119   " toggle spelling with F12 key:
120     map <F12> :set spell!<CR><Bar>:echo "Spell Check: " . strpart("OffOn", 3 * &spell, 3)<CR>
121     set spellfile=~/.vim/spellfile.add
122   " change language -  get spell files from http://ftp.vim.org/pub/vim/runtime/spell/ =>
123   " cd ~/.vim/spell && wget http://ftp.vim.org/pub/vim/runtime/spell/de.{latin1,utf-8}.spl
124   " change to german:
125   "  set spelllang=de
126   " highlight spelling correction:
127   "  highlight SpellBad    term=reverse   ctermbg=12 gui=undercurl guisp=Red       " badly spelled word 
128   "  highlight SpellCap    term=reverse   ctermbg=9  gui=undercurl guisp=Blue      " word with wrong caps
129   "  highlight SpellRare   term=reverse   ctermbg=13 gui=undercurl guisp=Magenta   " rare word
130   "  highlight SpellLocale term=underline ctermbg=11 gui=undercurl guisp=DarkCyan  " word only exists in other region
131
132   " set maximum number of suggestions listed to top 10 items:
133   set sps=best,10
134
135   " highlight matching parens:
136   " set matchpairs=(:),[:],{:},< :>
137   " let loaded_matchparen = 1
138   " highlight MatchParen term=reverse   ctermbg=7   guibg=cornsilk
139
140   " highlight the cursor line and column:
141   " set cursorline
142   " highlight CursorLine   term=reverse   ctermbg=7   guibg=#333333
143   " highlight CursorColumn guibg=#333333
144
145   " change inner tag - very useful e.g. within HTML-code!
146   " ci" will remove the text between quotes, also works for ' and `
147   imap <F10> <C-O>cit
148
149   " use the popup menu also when there is only one match:
150   " set completeopt=menuone 
151   " determine the maximum number of items to show in the popup menu for:
152   set pumheight=7
153   " set completion highlighting:
154   "  highlight Pmenu      ctermbg=13     guifg=Black   guibg=#BDDFFF              " normal item
155   "  highlight PmenuSel   ctermbg=7      guifg=Black   guibg=Orange               " selected item
156   "  highlight PmenuSbar  ctermbg=7      guifg=#CCCCCC guibg=#CCCCCC              " scrollbar
157   "  highlight PmenuThumb cterm=reverse  gui=reverse guifg=Black   guibg=#AAAAAA  " thumb of the scrollbar
158
159 endif
160 "# END OF FILE #################################################################