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