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