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