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