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