]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
awesome: fix layout on chronos
[dotfiles.git] / vim / vimrc
1 " My vimrc file.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " use xdg
7 set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after
8
9 " bundles {{{1
10 filetype off
11 set rtp+=$XDG_DATA_HOME/vim/vundle
12 call vundle#rc('$XDG_DATA_HOME/vim')
13
14 Bundle 'gmarik/vundle'
15 Bundle 'wincent/Command-T'
16 Bundle 'bling/vim-airline'
17 Bundle 'ctrlp.vim'
18 Bundle 'fugitive.vim'
19 Bundle 'Gundo'
20 Bundle 'The-NERD-tree'
21 Bundle 'surround.vim'
22 Bundle 'Syntastic'
23 Bundle 'Tagbar'
24 Bundle 'tComment'
25 Bundle 'Valloric/YouCompleteMe'
26 Bundle 'elzr/vim-json'
27
28 filetype plugin indent on
29
30 " moving around, searching and patterns {{{1
31 set incsearch " show match for partly typed search command
32 set ignorecase " ignore case when using a search pattern
33 set smartcase " override 'ignorecase' when pattern has upper case characters
34 set hlsearch " highlight all matches for the last used search pattern
35
36 " use leader-n to unhighlight search
37 nmap <silent> <Leader>n :silent nohl<CR>
38 " use leader-# to display the number of matches for the last search
39 nmap <Leader># :%s:<C-R>/::gn<CR>
40 " center cursor after search
41 nnoremap n nzz
42 " disable arrows
43 inoremap <Up> <NOP>
44 inoremap <Down> <NOP>
45 inoremap <Left> <NOP>
46 inoremap <Right> <NOP>
47 noremap <Up> <NOP>
48 noremap <Down> <NOP>
49 noremap <Left> <NOP>
50 noremap <Right> <NOP>
51
52 set nostartofline " don't move the cursor to the first non-blank char of a line
53 set path=.,** " current + subdirectory search for :find, :grep:, ...
54
55 " displaying text {{{1
56 set scrolloff=5 " number of screen lines to show around the cursor
57 set wrap " long lines wrap
58 set linebreak " wrap long lines at a character in 'breakat'
59 set showbreak=▒▒ " show these chars for wrapped lines
60
61 set lazyredraw " don't redraw while executing macros
62
63 set list " show chars defined in 'listchars'
64 set listchars=tab:»·,trail:· " list of strings used for list mode
65
66 set number " show the line number for each line
67 set relativenumber " show the relative line number for each line
68 " toggle relativenumber
69 nnoremap <silent> <Leader>u :exe "set relativenumber!"<CR>
70
71 if has("autocmd")
72 " When editing a file, always jump to the last known cursor position.
73 " Don't do it when the position is invalid or when inside an event handler
74 " (happens when dropping a file on gvim).
75 " Also don't do it when the mark is in the first line, that is the default
76 " position when opening a file.
77 " blacklist certain filetype, you can get a file type with :echo &ft
78 let blacklist = ['gitcommit']
79 autocmd BufReadPost *
80 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
81 \ exe "normal! g`\"" |
82 \ endif
83 endif
84
85
86 " syntax, highlighting and spelling {{{1
87 set background=dark " Dark background, d'uh!
88 syntax on
89
90 set spelllang=en_gb " list of accepted languages
91 set dictionary=spell " list of dictionary files for keyword completion
92 " toggle spell-checking
93 map <silent><F10> :set nospell!<CR>:set nospell?<CR>
94
95 if has("autocmd")
96 au Filetype *
97 \ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
98 endif
99
100 " multiple windows {{{1
101 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
102
103 set previewheight=20 " default height for the preview window
104
105 set splitright " a new window is put right of the current one
106
107 nmap <C-J> <C-W>j
108 nmap <C-K> <C-W>k
109 nmap <C-H> <C-W>h
110 nmap <C-L> <C-W>l
111
112 map <F1> :ls<CR>:b<space>
113
114 " using the mouse {{{1
115 set mouse=rnv " list of flags for using the mouse
116 set ttymouse=xterm " type of mouse
117
118 "xterm mouse with middleclick paste
119 nnoremap <MiddleMouse> i<MiddleMouse>
120 vnoremap <MiddleMouse> s<MiddleMouse>
121
122 " messages and info {{{1
123 set showcmd " Show (partial) command in status line.
124 set ruler " show the cursor position all the time
125 set confirm " Ask what to do when closing unsaved documents
126
127 " editing text {{{1
128 set backspace=indent,eol,start " allow backspacing over everything in insert mode
129
130 set showmatch " Show matching brackets.
131
132 set nojoinspaces " don't use two spaces after '.' when joining a line
133 set formatoptions+=j " remove comment leader when joining lines
134
135 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
136
137 " whether to use a popup menu for Insert mode completion
138 set completeopt=longest,menuone,preview
139
140 " Indent if we're at the beginning of a line. Else, do completion.
141 function! InsertTabWrapper()
142 let col = col('.') - 1
143 if !col || getline('.')[col - 1] !~ '\k'
144 return "\<Tab>"
145 else
146 return "\<C-N>"
147 endif
148 endfunction
149 inoremap <Tab> <C-R>=InsertTabWrapper()<CR>
150 inoremap <S-Tab> <C-P>
151
152 " fix legacy vi inconsistency
153 map Y y$
154
155 " allow repeat operator on visual
156 vnoremap . :normal .<CR>
157
158 " add line without changing position or leaving mode
159 map <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
160 map <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
161
162 " Don't use Ex mode, use Q for formatting
163 map Q gq
164
165 " allow undoing in insert-mode
166 inoremap <C-U> <C-G>u<C-U>
167 inoremap <C-W> <C-G>u<C-W>
168
169 " tabs and indent {{{1
170 set shiftwidth=4 " number of spaces used for each step of (auto)indent
171 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
172 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
173 set shiftround " round to 'shiftwidth' for "<<" and ">>"
174 set expandtab " expand <Tab> to spaces in Insert mode
175
176 set cindent " use smart C indenting (see :h C-indenting)
177 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
178
179 set pastetoggle=<F11> " key sequence to toggle paste mode
180
181 nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
182 nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
183 nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
184 nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
185
186 " folding {{{1
187 set foldmethod=marker " folding type
188 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
189
190 " space will toggle current fold in normal mode
191 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
192 " create folds around visual selection
193 vnoremap <Space> zf
194
195 " save and restore folds
196 autocmd BufWinLeave *.* mkview
197 autocmd BufWinEnter *.* silent loadview
198
199 " reading and writing files {{{1
200 set writebackup " write a backup file before overwriting a file
201 set backup " keep a backup after owerwriting a file
202 set backupdir=$XDG_CACHE_HOME/vim
203
204 set undofile " persistent undo history
205 set undodir=$XDG_CACHE_HOME/vim
206
207 set autowrite " automatically write a file when leaving a modified buffer
208
209 " save with sudo
210 cmap w!! w !sudo tee % > /dev/null
211
212 " the swap file {{{1
213 set directory=$XDG_CACHE_HOME/vim,.,/var/tmp
214
215 " command line editing {{{1
216 set history=500 " how many command lines are remembered
217 set wildmode=longest:full " specifies how command line completion works
218 set wildmenu " command-line completion shows a list of matches
219
220 " various {{{1
221 set virtualedit=block " let cursor move past last char in <C-V> mode
222 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .vim
223
224 set viewdir=$XDG_CACHE_HOME/vim
225
226 " plugins {{{1
227 " airline {{{2
228 let g:airline_detect_whitespace=2
229 let g:airline_whitespace_symbol = 'Ξ'
230 let g:airline_linecolumn_prefix = '␊ '
231 let g:airline_left_sep = '▶'
232 let g:airline_right_sep = '◀'
233 let g:airline#extensions#tabline#enabled = 1
234
235 " Gundo {{{2
236 nnoremap <F7> :GundoToggle<CR>
237 " fugitive {{{2
238 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
239
240 " NERDTree {{{2
241 " open/close NERDTree with \e
242 nmap <Leader>e :NERDTreeToggle<CR>
243 nmap <F6> :NERDTreeToggle<CR>
244 " <space> to open files/dirs
245 let NERDTreeMapActivateNode='<space>'
246 " open NERDTree if no files were selected
247 autocmd vimenter * if !argc() | NERDTree | endif
248 " close vim if only NERDTree is open
249 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
250
251 " synastic {{{2
252 let g:syntastic_enable_highlighting = 0
253 let g:syntastic_error_symbol='E'
254 let g:syntastic_style_error_symbol='S'
255 let g:syntastic_warning_symbol='W'
256 let g:syntastic_style_warning_symbol='S'
257 let g:syntastic_always_populate_loc_list=1
258 nmap <silent> <leader>y :SyntasticCheck<cr>
259
260 if ! &diff
261 let g:syntastic_check_on_open=1
262 endif
263
264 " tagbar {{{2
265 map <F5> :TagbarToggle<cr>
266 let g:tagbar_sort = 0
267 let g:tagbar_compact = 1
268 let g:tagbar_autoshowtag = 1
269 let g:tagbar_width = 25
270 let g:tagbar_iconchars = ['+', '-']
271
272 " YouCompleteMe {{{2
273 let g:ycm_extra_conf_globlist = ['/mnt/data/src/*']
274
275 " vim-json {{{2
276 let g:vim_json_syntax_conceal = 0
277
278 " functions {{{1
279 " Convenient command to see the difference between the current buffer and the
280 " file it was loaded from, thus the changes you made.
281 " Only define it when not defined already.
282 if !exists(":DiffOrig")
283 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
284 \ | wincmd p | diffthis
285 endif