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