]> git.rmz.io Git - dotfiles.git/blob - vimrc
04d2a4be99d2aaa7ff94948e7b191a8f9c7893ad
[dotfiles.git] / vimrc
1 " My vimrc file.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " pathogen.vim runtime path manipulation
7 silent! call pathogen#infect()
8
9 " search {{{1
10 set incsearch
11 set ignorecase
12 set smartcase
13 set hlsearch
14 nmap <Leader>q :nohl<CR>
15
16 " NERDTree {{{1
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
25
26 " airline {{{1
27 let g:airline#extensions#tabline#enabled = 1
28
29 " tabbing {{{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>
34
35 " backup {{{1
36 if has("vms")
37 set nobackup " do not keep a backup file, use versions instead
38 else
39 set backup " keep a backup file
40 set backupdir=$HOME/.vim/backupdir
41 endif
42
43 " appearance {{{1
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
49
50 " misc options {{{1
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
60
61 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
62
63 " tabs {{{1
64 set softtabstop=4
65 set shiftwidth=4
66 set expandtab
67
68 " misc bindings {{{1
69 " Don't use Ex mode, use Q for formatting
70 map Q gq
71
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>
75
76 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
77 imap `` <Insert>
78
79 " paste toggle {{{1
80 nmap <F11> :set paste! paste?<CR>
81 imap <F11> <C-o>:set paste!<CR>
82 vmap <F11> <Esc>:set paste!<CR>gv
83 set pastetoggle=<F11>
84
85 " mouse {{{1
86 " In many terminal emulators the mouse works just fine, thus enable it.
87 if has('mouse')
88 "xterm mouse with middleclick paste
89 nnoremap <MiddleMouse> i<MiddleMouse>
90 vnoremap <MiddleMouse> s<MiddleMouse>
91 set mouse=rnv
92 "choose either one
93 set ttymouse=xterm
94 "set ttymouse=xterm2
95 endif
96
97 " syntax {{{1
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")
101 syntax on
102 endif
103
104 " autocmd {{{1
105 " Only do this part when compiled with support for autocommands.
106 if has("autocmd")
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
112
113 " Put these in an autocmd group, so that we can delete them easily.
114 augroup vimrcEx
115 au!
116
117 " For all text files set 'textwidth' to 78 characters.
118 autocmd FileType text setlocal textwidth=78
119
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`\"" |
130 \ endif
131
132 augroup END
133 else
134 set autoindent " always set autoindenting on
135 endif " has("autocmd")
136
137 " DiffOrig {{{1
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
144 endif
145
146 " fold {{{1
147 set foldmethod=marker
148 set foldlevelstart=99
149 " space will toggle current fold in normal mode, if not in a fold, normal
150 " behaviour
151 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
152 vnoremap <Space> zf
153 " save and restore folds
154 autocmd BufWinLeave *.* mkview
155 autocmd BufWinEnter *.* silent loadview
156
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.
160 "
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
169 let line = line('.')
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)
179 if (a:exclusive)
180 let line = line - stepvalue
181 endif
182 exe line
183 exe "normal " column . "|"
184 return
185 endif
186 endif
187 endwhile
188 endfunction
189
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>
203 " end of jump indent