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