]> git.rmz.io Git - dotfiles.git/blob - vimrc
55906d8426a671f054d5379dd11d25c07311af56
[dotfiles.git] / vimrc
1 " My vimrc file.
2 "
3 " Maintainer: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 if v:progname =~? "evim"
7 finish
8 endif
9
10 " Use Vim settings, rather than Vi settings (much better!).
11 " This must be first, because it changes other options as a side effect.
12 set nocompatible
13
14 " pathogen.vim runtime path manipulation
15 silent! call pathogen#infect()
16
17 " search {{{1
18 set incsearch
19 set ignorecase
20 set smartcase
21 set hlsearch
22 nmap <Leader>q :nohl<CR>
23
24 " NERDTree {{{1
25 " open/close NERDTree with \e
26 nmap <Leader>e :NERDTreeToggle<CR>
27 " <space> to open files/dirs
28 let NERDTreeMapActivateNode='<space>'
29 " open NERDTree if no files were selected
30 autocmd vimenter * if !argc() | NERDTree | endif
31 " close vim if only NERDTree is open
32 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
33
34 " airline {{{1
35 let g:airline#extensions#tabline#enabled = 1
36
37 " tabbing {{{1
38 :nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
39 :nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
40 :nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
41 :nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
42
43 " backup {{{1
44 if has("vms")
45 set nobackup " do not keep a backup file, use versions instead
46 else
47 set backup " keep a backup file
48 set backupdir=$HOME/.vim/backupdir
49 endif
50
51 " appearance {{{1
52 set background=dark " Dark background, d'uh!
53 set number " show some linenumbers
54 set showmatch " Show matching brackets.
55 set showbreak=▒▒ " show these chars for wrapped lines
56 set list listchars=tab:»·,trail:· " show these chars for tabs and trailing spaces
57
58 " misc options {{{1
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
67 set backspace=indent,eol,start " allow backspacing over everything in insert mode
68
69 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
70
71 " tabs {{{1
72 set softtabstop=4
73 set shiftwidth=4
74 set expandtab
75
76 " misc bindings {{{1
77 " Don't use Ex mode, use Q for formatting
78 map Q gq
79
80 " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
81 " so that you can undo CTRL-U after inserting a line break.
82 inoremap <C-U> <C-G>u<C-U>
83
84 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
85 imap `` <Insert>
86
87 " paste toggle {{{1
88 nmap <F11> :set paste! paste?<CR>
89 imap <F11> <C-o>:set paste!<CR>
90 vmap <F11> <Esc>:set paste!<CR>gv
91 set pastetoggle=<F11>
92
93 " mouse {{{1
94 " In many terminal emulators the mouse works just fine, thus enable it.
95 if has('mouse')
96 "xterm mouse with middleclick paste
97 nnoremap <MiddleMouse> i<MiddleMouse>
98 vnoremap <MiddleMouse> s<MiddleMouse>
99 set mouse=rnv
100 "choose either one
101 set ttymouse=xterm
102 "set ttymouse=xterm2
103 endif
104
105 " syntax {{{1
106 " Switch syntax highlighting on, when the terminal has colors
107 " Also switch on highlighting the last used search pattern.
108 if &t_Co > 2 || has("gui_running")
109 syntax on
110 endif
111
112 " autocmd {{{1
113 " Only do this part when compiled with support for autocommands.
114 if has("autocmd")
115 " Enable file type detection.
116 " Use the default filetype settings, so that mail gets 'tw' set to 72,
117 " 'cindent' is on in C files, etc.
118 " Also load indent files, to automatically do language-dependent indenting.
119 filetype plugin indent on
120
121 " Put these in an autocmd group, so that we can delete them easily.
122 augroup vimrcEx
123 au!
124
125 " For all text files set 'textwidth' to 78 characters.
126 autocmd FileType text setlocal textwidth=78
127
128 " When editing a file, always jump to the last known cursor position.
129 " Don't do it when the position is invalid or when inside an event handler
130 " (happens when dropping a file on gvim).
131 " Also don't do it when the mark is in the first line, that is the default
132 " position when opening a file.
133 " blacklist certain filetype, you can get a file type with :echo &ft
134 let blacklist = ['gitcommit']
135 autocmd BufReadPost *
136 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
137 \ exe "normal! g`\"" |
138 \ endif
139
140 augroup END
141 else
142 set autoindent " always set autoindenting on
143 endif " has("autocmd")
144
145 " DiffOrig {{{1
146 " Convenient command to see the difference between the current buffer and the
147 " file it was loaded from, thus the changes you made.
148 " Only define it when not defined already.
149 if !exists(":DiffOrig")
150 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
151 \ | wincmd p | diffthis
152 endif
153
154 " fold {{{1
155 set foldmethod=marker
156 set foldlevelstart=99
157 " space will toggle current fold in normal mode, if not in a fold, normal
158 " behaviour
159 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
160 vnoremap <Space> zf
161 " save and restore folds
162 autocmd BufWinLeave *.* mkview
163 autocmd BufWinEnter *.* silent loadview
164
165 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks) " {{{1
166 " Jump to the next or previous line that has the same level or a lower
167 " level of indentation than the current line.
168 "
169 " exclusive (bool): true: Motion is exclusive
170 " false: Motion is inclusive
171 " fwd (bool): true: Go to next line
172 " false: Go to previous line
173 " lowerlevel (bool): true: Go to line with lower indentation level
174 " false: Go to line with the same indentation level
175 " skipblanks (bool): true: Skip blank lines
176 " false: Don't skip blank lines
177 let line = line('.')
178 let column = col('.')
179 let lastline = line('$')
180 let indent = indent(line)
181 let stepvalue = a:fwd ? 1 : -1
182 while (line > 0 && line <= lastline)
183 let line = line + stepvalue
184 if ( ! a:lowerlevel && indent(line) == indent ||
185 \ a:lowerlevel && indent(line) < indent)
186 if (! a:skipblanks || strlen(getline(line)) > 0)
187 if (a:exclusive)
188 let line = line - stepvalue
189 endif
190 exe line
191 exe "normal " column . "|"
192 return
193 endif
194 endif
195 endwhile
196 endfunction
197
198 " Moving back and forth between lines of same or lower indentation.
199 nnoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
200 nnoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
201 nnoremap <silent> [L :call NextIndent(0, 0, 1, 1)<CR>
202 nnoremap <silent> ]L :call NextIndent(0, 1, 1, 1)<CR>
203 vnoremap <silent> [l <Esc>:call NextIndent(0, 0, 0, 1)<CR>m'gv''
204 vnoremap <silent> ]l <Esc>:call NextIndent(0, 1, 0, 1)<CR>m'gv''
205 vnoremap <silent> [L <Esc>:call NextIndent(0, 0, 1, 1)<CR>m'gv''
206 vnoremap <silent> ]L <Esc>:call NextIndent(0, 1, 1, 1)<CR>m'gv''
207 onoremap <silent> [l :call NextIndent(0, 0, 0, 1)<CR>
208 onoremap <silent> ]l :call NextIndent(0, 1, 0, 1)<CR>
209 onoremap <silent> [L :call NextIndent(1, 0, 1, 1)<CR>
210 onoremap <silent> ]L :call NextIndent(1, 1, 1, 1)<CR>
211 " end of jump indent