]> git.rmz.io Git - dotfiles.git/blob - vimrc
tabbing options
[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 " 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>
18
19 " line wrap {{{1
20 set backspace=indent,eol,start " allow backspacing over everything in insert mode
21 set wrap " wrap lines
22 set linebreak " do not wrap in the middle of a word
23 set showbreak=▒▒ " show these chars for wrapped lines
24
25 " indent {{{1
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 ">>"
31
32 set cindent " use smart C indenting (see :h C-indenting)
33 set cinoptions=l1,c4,(0,U1,w1,m1,j1,J1
34
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>
39
40 " backup/undo {{{1
41 set backup " keep a backup file
42 set backupdir=$HOME/.vim/backupdir
43
44 set undofile " persistent undo history
45 set undodir=$HOME/.vim/backupdir
46
47 " NERDTree {{{1
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
56
57 " airline {{{1
58 let g:airline#extensions#tabline#enabled = 1
59
60 " appearance {{{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
65
66 " misc options {{{1
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
75
76 set viminfo='100,<50,s10,h,n~/.vim/viminfo " viminfo defaults but save file in .vim
77
78
79 " misc bindings {{{1
80 " Don't use Ex mode, use Q for formatting
81 map Q gq
82
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>
86
87 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
88 imap `` <Insert>
89
90 " paste toggle {{{1
91 nmap <F11> :set paste! paste?<CR>
92 imap <F11> <C-o>:set paste!<CR>
93 vmap <F11> <Esc>:set paste!<CR>gv
94 set pastetoggle=<F11>
95
96 " mouse {{{1
97 " In many terminal emulators the mouse works just fine, thus enable it.
98 if has('mouse')
99 "xterm mouse with middleclick paste
100 nnoremap <MiddleMouse> i<MiddleMouse>
101 vnoremap <MiddleMouse> s<MiddleMouse>
102 set mouse=rnv
103 "choose either one
104 set ttymouse=xterm
105 "set ttymouse=xterm2
106 endif
107
108 " syntax {{{1
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")
112 syntax on
113 endif
114
115 " autocmd {{{1
116 " Only do this part when compiled with support for autocommands.
117 if has("autocmd")
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
123
124 " Put these in an autocmd group, so that we can delete them easily.
125 augroup vimrcEx
126 au!
127
128 " For all text files set 'textwidth' to 78 characters.
129 autocmd FileType text setlocal textwidth=78
130
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`\"" |
141 \ endif
142
143 augroup END
144 else
145 set autoindent " always set autoindenting on
146 endif " has("autocmd")
147
148 " DiffOrig {{{1
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
155 endif
156
157 " fold {{{1
158 set foldmethod=marker
159 set foldlevelstart=99
160 " space will toggle current fold in normal mode, if not in a fold, normal
161 " behaviour
162 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
163 vnoremap <Space> zf
164 " save and restore folds
165 autocmd BufWinLeave *.* mkview
166 autocmd BufWinEnter *.* silent loadview
167
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.
171 "
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
180 let line = line('.')
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)
190 if (a:exclusive)
191 let line = line - stepvalue
192 endif
193 exe line
194 exe "normal " column . "|"
195 return
196 endif
197 endif
198 endwhile
199 endfunction
200
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>
214 " end of jump indent