fixing submodules
[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
12
13 set completeopt=longest,menuone,preview
14 inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
15 inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
16   \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
17
18 inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
19   \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
20
21 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
22 " Theme/Colors
23 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
24 syntax on " syntax highlighting on
25
26 set background=dark
27 set t_Co=256
28 colorscheme morning 
29 "colorscheme xoria256 
30 "let g:solarized_termcolors=256
31
32 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
33 " Vim UI
34 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
35 set nofoldenable    " disable folding
36 set wildmenu " turn on wild menu
37 set ruler " Always show current positions along the bottom 
38 set number " turn on line numbers
39 set lz " do not redraw while running macros (much faster) (LazyRedraw)
40 set hid " you can change buffer without saving
41 set backspace=eol,start,indent " make backspace work normal    
42 set whichwrap+=<,>,h,l  " backspace and cursor keys wrap to
43 set shortmess=atI " shortens messages to avoid 'press a key' prompt 
44 set report=0 " tell us when anything is changed via :...
45 " make the splitters between windows be blank
46 set fillchars=vert:\ ,stl:\ ,stlnc:\ 
47
48 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
49 " Visual Cues
50 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
51 set showmatch " show matching brackets
52 set mat=5 " how many tenths of a second to blink matching brackets for
53 set nohlsearch " highlight searched for phrases
54 set incsearch " do highlight as you type you search phrase
55 set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show when I hit :set list
56 set so=10 " Keep 10 lines (top/bottom) for scope
57 set novisualbell " don't blink
58 set noerrorbells " no noises
59 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]
60 set laststatus=2 " always show the status line
61
62 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
63 " Text Formatting/Layout
64 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
65 set fo=tcrqn " See Help (complex)
66 set ai " autoindent
67 set si " smartindent 
68 set tabstop=4 " tab spacing (settings below are just to unify it)
69 set softtabstop=4 " unify
70 set shiftwidth=4 " unify 
71 set expandtab " space instead of tabs 
72 set smarttab "Use the "shiftwidth" setting for inserting <TAB>s instead of the "tabstop" setting, when at the beginning of a line.
73 set nowrap " do not wrap lines  
74   
75 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
76 " Mouse Settings
77 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
78 set mouse=a                     " mouse support in all modes
79 set mousehide                   " hide the mouse when typing text
80
81 " ,p and shift-insert will paste the X buffer, even on the command line
82 nmap <LocalLeader>p i<S-MiddleMouse><ESC>
83 imap <S-Insert> <S-MiddleMouse>
84 cmap <S-Insert> <S-MiddleMouse>
85
86 " map <C-k> to clear search
87 nmap <silent><C-k> :nohlsearch<CR>
88
89 " this makes the mouse paste a block of text without formatting it 
90 " (good for code)
91 map <MouseMiddle> <esc>"*p
92
93 " Convenient for non italian keyboard
94 map ò :
95
96 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
97 " Matchit
98 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
99 let b:match_ignorecase = 1
100
101 " make tab in v mode ident code
102 vmap <tab> >gv
103 vmap <s-tab> <gv
104
105 " make tab in normal mode ident code
106 nmap <tab> I<tab><esc>
107 nmap <s-tab> ^i<bs><esc>
108
109 "Easy to access esc key
110 map! <C-h> <Esc>
111 map <C-h> <Esc>
112
113 " paste mode - this will avoid unexpected effects when you
114 " cut or copy some text from one window and paste it in Vim.
115 set pastetoggle=<F6>
116
117 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
118 " Perl
119 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
120 let perl_extended_vars=1 " highlight advanced perl vars inside strings
121
122 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
123 " Custom Functions
124 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
125 "switch spellcheck languages
126 let g:myLangList = [ "none", "it", "en_us" ]
127 function! MySpellLang()
128 "loop through languages
129 if !exists( "b:myLang" )
130       let b:myLang=0
131 endif 
132 let b:myLang = b:myLang + 1
133 if b:myLang >= len(g:myLangList) | let b:myLang = 0 | endif
134
135 if b:myLang== 0 | setlocal spell nospell | endif
136 if b:myLang== 1 | setlocal spell spelllang=it | endif
137 if b:myLang== 2 | setlocal spell spelllang=en_us | endif
138
139 echo "language spell:" g:myLangList[b:myLang]
140 endfunction
141
142 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
143 " Mappings
144 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
145 " alt-i (normal mode) inserts a single char, and then switches back to normal
146 map <A-i> i <ESC>r 
147 " set F4 to toogle number/nonumber
148 map <silent><F4> :set invnumber<CR>
149 " encypt the file (toggle)
150 map <F12> ggVGg?
151 map <F8> :call MySpellLang()<CR>
152 " Map NERDTree show and hide
153 map <F2> :NERDTreeToggle<CR>
154 imap <F2> <Esc>:NERDTreeToggle<CR>
155 " Tagbar toggle
156 map <F3> :TagbarToggle<CR>
157 imap <F3> <Esc>:TagbarToggle<CR>
158
159 " Alt-right/left to navigate forward/backward in the tags stack
160 map <M-Left> <C-T>
161 map <M-Right> <C-]>
162
163 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
164 " Autocommands
165 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
166 if has ("autocmd")
167     " Enable file type detection ('filetype on').
168     " Syntax of these languages is fussy over tabs Vs spaces
169     autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
170     autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
171     " Customisations based on house-style (arbitrary)
172     autocmd FileType html setlocal ts=2 sts=2 sw=2 expandtab
173     autocmd FileType css setlocal ts=2 sts=2 sw=2 expandtab
174     " Treat sh correctly
175     autocmd FileType sh setlocal ts=4 sts=4 sw=4 expandtab
176     " Treat .rss files as XML
177     autocmd BufNewFile,BufRead *.rss,*.atom setfiletype xml
178
179     autocmd FileType c,cpp,slang set cindent
180     autocmd FileType c,cpp,slang set textwidth=79
181     autocmd FileType c,cpp,slang set tags=./tags,/usr/src/linux/tags,~/.vim/tags/usr/include/tags 
182
183     autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
184     autocmd BufNewFile *.sh call append(0, "#!/bin/bash")
185     autocmd BufNewFile *.pl call append(0, "#!/usr/bin/perl")
186     autocmd BufNewFile *.py call append(0, "#!/bin/python")
187
188
189     " PHP documenter script bound to Control-P
190     autocmd FileType php inoremap <C-p> <ESC>:call PhpDocSingle()<CR>i
191     autocmd FileType php nnoremap <C-p> :call PhpDocSingle()<CR>
192     autocmd FileType php vnoremap <C-p> :call PhpDocRange()<CR> 
193
194     " When editing a file, always jump to the last known cursor position.
195     " Don't do it when the position is invalid or when inside an event handler
196     " (happens when dropping a file on gvim).
197     autocmd BufReadPost *
198         \ if line("'\"") > 0 && line("'\"") <= line("$") |
199         \ exe "normal g`\"" |
200         \ endif
201 endif
202  
203
204 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
205 " General configs
206 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
207 set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:h\")})%)%(\ %a%)\ -\ %{v:servername}
208 if &term == "screen"
209   set t_ts=^[k
210   set t_fs=^[\
211 endif
212 if &term == "screen" || &term == "xterm"
213   set title
214 endif
215
216
217    
218 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
219 " Plugin activation 
220 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
221 " vim-addon-manager 
222 "
223 let vam_install_path = expand('$HOME') . '/.vim/addons'
224 exec 'set runtimepath+='.vam_install_path.'/vim-addon-manager'
225 " Enable addons with vim-addon-manager using file type recognition
226 let ft_addons = {
227     \ 'always': ['desert', 'gnupg', 'surround', 'checksyntax', 'quickfixsigns', 'LargeFile', 'snipmate', 'snipmate-snippets', 'The_NERD_tree', 'SuperTab%1643', 'fugitive'],
228     \ 'r': [ 'Screen_vim__gnu_screentmux', 'Vim-R-plugin' ],
229     \ '^\%(c\|cpp\|cuda\|javascript\|python\|php\|html\|xml\|r\|sh\|css\|java\|make\|xslt\|vim\)$': [ 'Tagbar', 'checksyntax', 'TagHighlight', 'sleuth'],
230     \ '^\%(c\|cpp\|h\|cuda\)$': [ 'clang_complete' ],
231     \ 'python': [ 'python_pydoc'],
232     \ 'php': ['phpcomplete', 'PDV_-_phpDocumentor_for_Vim'],
233     \ 'gpg': ['gnupg'],
234     \ }
235 call vam#ActivateAddons(ft_addons['always'], {'auto_install': 1})
236 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
237
238 " SuperTab option for context aware completion
239 let g:SuperTabDefaultCompletionType = "context"
240 " If you prefer the Omni-Completion tip window to close when a selection is
241 " " made, these lines close it on movement in insert mode or when leaving
242 " " insert mode
243 if has("autocmd")
244     autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
245     autocmd InsertLeave * if pumvisible() == 0|pclose|endif
246 endif
247
248 let g:clang_complete_copen = 1
249 let g:clang_complete_auto = 1
250 let g:clang_user_options='|| exit 0'
251
252 if has("cscope")
253     set csto=0
254     set cst
255     set nocsverb
256     " add any database in current directory
257     if filereadable("cscope.out")
258         cs add cscope.out
259     " else add database pointed to by environment
260     elseif $CSCOPE_DB != ""
261         cs add $CSCOPE_DB
262     endif
263     if filereadable("/usr/linux/cscope.out")
264         cs add /usr/linux/cscope.out
265     endif
266     set csverb
267 endif