3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
6 " pathogen.vim runtime path manipulation
7 silent! call pathogen#infect()
14 " use leader-n to unhighlight search
15 nmap <silent> <Leader>n :silent nohl<CR>
16 " use leader-# to display the number of matches for the last search
17 nmap <Leader># :%s:<C-R>/::gn<CR>
20 set backspace=indent,eol,start " allow backspacing over everything in insert mode
22 set linebreak " do not wrap in the middle of a word
23 set showbreak=▒▒ " show these chars for wrapped lines
26 " open/close NERDTree with \e
27 nmap <Leader>e :NERDTreeToggle<CR>
28 " <space> to open files/dirs
29 let NERDTreeMapActivateNode='<space>'
30 " open NERDTree if no files were selected
31 autocmd vimenter * if !argc() | NERDTree | endif
32 " close vim if only NERDTree is open
33 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
36 let g:airline#extensions#tabline#enabled = 1
39 :nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
40 :nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
41 :nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
42 :nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
46 set nobackup " do not keep a backup file, use versions instead
48 set backup " keep a backup file
49 set backupdir=$HOME/.vim/backupdir
53 set background=dark " Dark background, d'uh!
54 set number " show some linenumbers
55 set showmatch " Show matching brackets.
56 set list listchars=tab:»·,trail:· " show these chars for tabs and trailing spaces
59 set history=500 " keep 500 lines of command line history
60 set ruler " show the cursor position all the time
61 set confirm " Ask what to do when closing unsaved documents
62 set showcmd " Show (partial) command in status line.
63 set autowrite " Automatically save before commands like :next and :make
64 "set hidden " Hide buffers when they are abandoned
65 set splitright " split right when using :vsp
66 set scrolloff=5 " keep at least n lines above/below
68 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
76 " Don't use Ex mode, use Q for formatting
79 " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
80 " so that you can undo CTRL-U after inserting a line break.
81 inoremap <C-U> <C-G>u<C-U>
83 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
87 nmap <F11> :set paste! paste?<CR>
88 imap <F11> <C-o>:set paste!<CR>
89 vmap <F11> <Esc>:set paste!<CR>gv
93 " In many terminal emulators the mouse works just fine, thus enable it.
95 "xterm mouse with middleclick paste
96 nnoremap <MiddleMouse> i<MiddleMouse>
97 vnoremap <MiddleMouse> s<MiddleMouse>
105 " Switch syntax highlighting on, when the terminal has colors
106 " Also switch on highlighting the last used search pattern.
107 if &t_Co > 2 || has("gui_running")
112 " Only do this part when compiled with support for autocommands.
114 " Enable file type detection.
115 " Use the default filetype settings, so that mail gets 'tw' set to 72,
116 " 'cindent' is on in C files, etc.
117 " Also load indent files, to automatically do language-dependent indenting.
118 filetype plugin indent on
120 " Put these in an autocmd group, so that we can delete them easily.
124 " For all text files set 'textwidth' to 78 characters.
125 autocmd FileType text setlocal textwidth=78
127 " When editing a file, always jump to the last known cursor position.
128 " Don't do it when the position is invalid or when inside an event handler
129 " (happens when dropping a file on gvim).
130 " Also don't do it when the mark is in the first line, that is the default
131 " position when opening a file.
132 " blacklist certain filetype, you can get a file type with :echo &ft
133 let blacklist = ['gitcommit']
134 autocmd BufReadPost *
135 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
136 \ exe "normal! g`\"" |
141 set autoindent " always set autoindenting on
142 endif " has("autocmd")
145 " Convenient command to see the difference between the current buffer and the
146 " file it was loaded from, thus the changes you made.
147 " Only define it when not defined already.
148 if !exists(":DiffOrig")
149 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
150 \ | wincmd p | diffthis
154 set foldmethod=marker
155 set foldlevelstart=99
156 " space will toggle current fold in normal mode, if not in a fold, normal
158 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
160 " save and restore folds
161 autocmd BufWinLeave *.* mkview
162 autocmd BufWinEnter *.* silent loadview
164 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks) " {{{1
165 " Jump to the next or previous line that has the same level or a lower
166 " level of indentation than the current line.
168 " exclusive (bool): true: Motion is exclusive
169 " false: Motion is inclusive
170 " fwd (bool): true: Go to next line
171 " false: Go to previous line
172 " lowerlevel (bool): true: Go to line with lower indentation level
173 " false: Go to line with the same indentation level
174 " skipblanks (bool): true: Skip blank lines
175 " false: Don't skip blank lines
177 let column = col('.')
178 let lastline = line('$')
179 let indent = indent(line)
180 let stepvalue = a:fwd ? 1 : -1
181 while (line > 0 && line <= lastline)
182 let line = line + stepvalue
183 if ( ! a:lowerlevel && indent(line) == indent ||
184 \ a:lowerlevel && indent(line) < indent)
185 if (! a:skipblanks || strlen(getline(line)) > 0)
187 let line = line - stepvalue
190 exe "normal " column . "|"
197 " Moving back and forth between lines of same or lower indentation.
198 nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
199 nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
200 nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
201 nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
202 vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
203 vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
204 vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
205 vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
206 onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
207 onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
208 onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
209 onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>