bc78eb366bed88c57f2e7f858d24d9f4f765e9c8
[stack/conf/vim.git] / .vimrc
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 " General
3 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4 set nocompatible " get out of horrible vi-compatible mode
5 filetype indent plugin on | syn on
6 set history=1000 " How many lines of history to remember
7 set cf " enable error files and error jumping
8 set ffs=unix,dos,mac " support all three, in this order
9 set viminfo+=! " make sure it can save viminfo
10 set isk+=_,@,- " none of these should be word dividers, so make them not be
11 set nobackup " real man don't use backups ;)
12 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
13 " Theme/Colors
14 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
15 syntax on " syntax highlighting on
16
17 set background=dark
18 set t_Co=256
19 colorscheme desert 
20 "colorscheme xoria256 
21 "let g:solarized_termcolors=256
22 "colorscheme solarized
23
24 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
25 " Vim UI
26 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
27 set wildmenu " turn on wild menu
28 set ruler " Always show current positions along the bottom 
29 "set number " turn on line numbers
30 set lz " do not redraw while running macros (much faster) (LazyRedraw)
31 set hid " you can change buffer without saving
32 set backspace=2 " make backspace work normal    
33 set whichwrap+=<,>,h,l  " backspace and cursor keys wrap to
34 set mouse=a " use mouse everywhere
35 set shortmess=atI " shortens messages to avoid 'press a key' prompt 
36 set report=0 " tell us when anything is changed via :...
37 " make the splitters between windows be blank
38 set fillchars=vert:\ ,stl:\ ,stlnc:\ 
39
40 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
41 " Visual Cues
42 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
43 set showmatch " show matching brackets
44 set mat=5 " how many tenths of a second to blink matching brackets for
45 set nohlsearch " do not highlight searched for phrases
46 set incsearch " BUT do highlight as you type you search phrase
47 set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show when I hit :set list
48 set so=10 " Keep 10 lines (top/bottom) for scope
49 set novisualbell " don't blink
50 set noerrorbells " no noises
51 "set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
52 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]
53 set laststatus=2 " always show the status line
54
55 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
56 " Text Formatting/Layout
57 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
58 set fo=tcrqn " See Help (complex)
59 set si " smartindent 
60 set tabstop=4 " tab spacing (settings below are just to unify it)
61 set softtabstop=4 " unify
62 set shiftwidth=4 " unify 
63 set expandtab " space instead of tabs please!
64 set nowrap " do not wrap lines  
65 autocmd FileType c,cpp,slang set cindent
66 autocmd FileType c,cpp,slang set textwidth=79
67
68
69 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
70 " Folding
71 "    Enable folding, but by default make it act like folding is off, because folding is annoying in anything but a few rare cases
72 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
73 set foldenable " Turn on folding
74 set foldmethod=indent " Make folding indent sensitive
75 set foldlevel=100 " Don't autofold anything (but I can still fold manually)
76 set foldopen-=search " don't open folds when you search into them
77 set foldopen-=undo " don't open folds when you undo stuff
78
79 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
80 " Mouse Settings
81 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
82 set mouse=a                     " mouse support in all modes
83 set mousehide                   " hide the mouse when typing text
84
85 " ,p and shift-insert will paste the X buffer, even on the command line
86 nmap <LocalLeader>p i<S-MiddleMouse><ESC>
87 imap <S-Insert> <S-MiddleMouse>
88 cmap <S-Insert> <S-MiddleMouse>
89
90 " this makes the mouse paste a block of text without formatting it 
91 " (good for code)
92 map <MouseMiddle> <esc>"*p
93
94 " Convenient for non italian keyboard
95 map ò :
96
97 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
98 " Matchit
99 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
100 let b:match_ignorecase = 1
101
102 " make tab in v mode ident code
103 vmap <tab> >gv
104 vmap <s-tab> <gv
105
106 " make tab in normal mode ident code
107 nmap <tab> I<tab><esc>
108 nmap <s-tab> ^i<bs><esc>
109
110 "Easy to access esc key
111 map! <C-h> <Esc>
112 map <C-h> <Esc>
113
114 " paste mode - this will avoid unexpected effects when you
115 " cut or copy some text from one window and paste it in Vim.
116 set pastetoggle=<F6>
117
118 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
119 " Perl
120 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
121 let perl_extended_vars=1 " highlight advanced perl vars inside strings
122
123 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
124 " Custom Functions
125 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
126 " Select range, then hit :SuperRetab($width) - by p0g and FallingCow
127 function! SuperRetab(width) range
128     silent! exe a:firstline . ',' . a:lastline . 's/\v%(^ *)@<= {'. a:width .'}/\t/g'
129 endfunction
130
131 "switch spellcheck languages
132 let g:myLangList = [ "none", "it", "en_us" ]
133 function! MySpellLang()
134 "loop through languages
135 if !exists( "b:myLang" )
136       let b:myLang=0
137 endif 
138 let b:myLang = b:myLang + 1
139 if b:myLang >= len(g:myLangList) | let b:myLang = 0 | endif
140
141 if b:myLang== 0 | setlocal spell nospell | endif
142 if b:myLang== 1 | setlocal spell spelllang=it | endif
143 if b:myLang== 2 | setlocal spell spelllang=en_us | endif
144
145 echo "language spell:" g:myLangList[b:myLang]
146 endfunction
147
148 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
149 " Mappings
150 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
151 " alt-i (normal mode) inserts a single char, and then switches back to normal
152 map <A-i> i <ESC>r 
153 map <F10> <ESC>ggVG:call SuperRetab()<left>
154 " encypt the file (toggle)
155 map <F12> ggVGg?
156 map <F8> :call MySpellLang()<CR>
157 map <F7> :TlistOpen<ESC>
158 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
159 " Autocommands
160 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
161 autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
162 autocmd BufNewFile *.sh call append(0, "#!/bin/bash")
163 autocmd BufNewFile *.pl call append(0, "#!/usr/bin/perl")
164 autocmd BufNewFile *.py call append(0, "#!/bin/python")
165
166 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
167 " Useful abbrevs
168 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
169 iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr> 
170
171 " Latex abbrevs
172 "iab cha \chapter{}<ESC>i
173 "iab sub \subsection{}
174 "iab sec \section{}
175 "iab ite \item
176 "iab enu \begin{enumerate}<CR>\end{enumerate}<ESC>O
177 "iab footn \footnote{}
178 "iab tabb \begin{tabbing}<CR>\end{tabbing}<ESC>O
179
180 """""""""""""""""""""""""""
181 set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:h\")})%)%(\ %a%)\ -\ %{v:servername}
182 if &term == "screen"
183   set t_ts=^[k
184   set t_fs=^[\
185 endif
186 if &term == "screen" || &term == "xterm"
187   set title
188 endif
189
190 " vim-addon-manager 
191 "
192 fun SetupVAM()
193   let addons_base = expand('$HOME') . '/.vim/addons'
194   exec 'set runtimepath+='.addons_base.'/vim-addon-manager'
195
196   " unix based os users may want to use this code checking out VAM
197   " if !isdirectory(addons_base.'/vim-addon-manager')
198   " exec '!p='.shellescape(addons_base).'; mkdir -p "$p" && cd "$p" && git clone --depth 1 git://github.com/MarcWeber/vim-addon-manager.git'
199   " endif
200
201   " commenting try .. endtry because trace is lost if you use it.
202   " There should be no exception anyway
203    try
204
205     let g:solarized_termcolors=256
206     call vam#ActivateAddons(['github:altercation/vim-colors-solarized'])
207     call vam#ActivateAddons(['surround','checksyntax','snipmate','snipmate-snippets','gnupg','LargeFile','taglist-plus'], {'auto_install' : 0})
208     " pluginA could be github:YourName see vam#install#RewriteName()
209    catch /.*/
210    echoe v:exception
211    endtry
212 endf
213 call SetupVAM()
214
215 let ft_addons = {
216   \ '^\%(R\|r\)$': [ 'Screen_vim__gnu_screentmux', 'Vim-R-plugin' ],
217 \ }
218 au FileType * for l in values(filter(copy(ft_addons), string(expand('<amatch>')).' =~ v:key')) | call vam#ActivateAddons(l, {'force_loading_plugins_now':1}) | endfor
219 " experimental: run after gui has been started (gvim) [3]
220 " option1: au VimEnter * call SetupVAM()
221 " option2: au GUIEnter * call SetupVAM()
222 " See BUGS sections below [*]