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