]> git.rmz.io Git - dotfiles.git/blob - vimrc
add command-t and vim-fugitive submodules
[dotfiles.git] / vimrc
1 " My vimrc file.
2 "
3 " Maintainer: Samir Benmendil <ram-z@chakra-project.org>
4 "
5
6 if v:progname =~? "evim"
7 finish
8 endif
9
10 " TODO
11 " organize this file, never thought it'll get this big
12 " TODO
13
14 " pathogen.vim runtime path manipulation
15 silent! call pathogen#infect()
16
17 " Use Vim settings, rather than Vi settings (much better!).
18 " This must be first, because it changes other options as a side effect.
19 set nocompatible
20
21 " allow backspacing over everything in insert mode
22 set backspace=indent,eol,start
23
24 if has("vms")
25 set nobackup " do not keep a backup file, use versions instead
26 else
27 set backup " keep a backup file
28 set backupdir=$HOME/.vim/backupdir
29 endif
30 set history=50 " keep 50 lines of command line history
31 set ruler " show the cursor position all the time
32 set showcmd " display incomplete commands
33 set incsearch " do incremental searching
34 set number " show some linenumbers
35 " viminfo defaults but save file in .vim
36 set viminfo='100,<50,s10,h,n~/.vim/viminfo
37
38 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
39 " let &guioptions = substitute(&guioptions, "t", "", "g")
40
41 " Don't use Ex mode, use Q for formatting
42 map Q gq
43
44 " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
45 " so that you can undo CTRL-U after inserting a line break.
46 inoremap <C-U> <C-G>u<C-U>
47
48 "paste toggle
49 nmap <F11> :set paste! paste?<CR>
50 imap <F11> <C-o>:set paste!<CR>
51 vmap <F11> <Esc>:set paste!<CR>gv
52 set pastetoggle=<F11>
53
54 " In many terminal emulators the mouse works just fine, thus enable it.
55 "if has('mouse')
56 " "xterm mouse with middleclick paste
57 " nnoremap <MiddleMouse> i<MiddleMouse>
58 " vnoremap <MiddleMouse> s<MiddleMouse>
59 " set mouse=rnv
60 " "choose either one
61 " set ttymouse=xterm
62 " "set ttymouse=xterm2
63 "endif
64
65 " Switch syntax highlighting on, when the terminal has colors
66 " Also switch on highlighting the last used search pattern.
67 if &t_Co > 2 || has("gui_running")
68 syntax on
69 set hlsearch
70 endif
71
72 " Only do this part when compiled with support for autocommands.
73 if has("autocmd")
74
75 " Enable file type detection.
76 " Use the default filetype settings, so that mail gets 'tw' set to 72,
77 " 'cindent' is on in C files, etc.
78 " Also load indent files, to automatically do language-dependent indenting.
79 filetype plugin indent on
80
81 " Put these in an autocmd group, so that we can delete them easily.
82 augroup vimrcEx
83 au!
84
85 " For all text files set 'textwidth' to 78 characters.
86 autocmd FileType text setlocal textwidth=78
87
88 " When editing a file, always jump to the last known cursor position.
89 " Don't do it when the position is invalid or when inside an event handler
90 " (happens when dropping a file on gvim).
91 " Also don't do it when the mark is in the first line, that is the default
92 " position when opening a file.
93 " blacklist certain filetype, you can get a file type with :echo &ft
94 let blacklist = ['gitcommit']
95 autocmd BufReadPost *
96 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
97 \ exe "normal! g`\"" |
98 \ endif
99
100 augroup END
101
102 else
103
104 set autoindent " always set autoindenting on
105
106 endif " has("autocmd")
107
108 " Convenient command to see the difference between the current buffer and the
109 " file it was loaded from, thus the changes you made.
110 " Only define it when not defined already.
111 if !exists(":DiffOrig")
112 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
113 \ | wincmd p | diffthis
114 endif
115
116 " Ask what to do when closing unsaved documents
117 set confirm
118
119 " If using a dark background within the editing area and syntax highlighting
120 " turn on this option as well
121 set background=dark
122
123 " The following are commented out as they cause vim to behave a lot
124 " differently from regular Vi. They are highly recommended though.
125 set showcmd " Show (partial) command in status line.
126 set showmatch " Show matching brackets.
127 set ignorecase " Do case insensitive matching
128 set smartcase " Do smart case matching
129 set incsearch " Incremental search
130 set autowrite " Automatically save before commands like :next and :make
131 "set hidden " Hide buffers when they are abandoned
132 "set mouse=a " Enable mouse usage (all modes)
133
134 " expand tabs
135 set softtabstop=4
136 set shiftwidth=4
137 set expandtab
138
139 set showbreak=▒▒
140 " show these chars for tabs and trailing spaces
141 set list listchars=tab:»·,trail:·
142
143 set pastetoggle=<F11>
144 " split right when using :vsp
145 set splitright
146
147 set scrolloff=3 " keep at least 3 lines above/below
148 " Press i to enter insert mode, and ii to exit.
149 imap ii <Esc>
150 " Press `` to toggle insert and replace mode (no <Insert> key on Mac keyboard)
151 imap `` <Insert>
152
153 " fold between {{{ }}}
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 " Jump to the next or previous line that has the same level or a lower
165 " level of indentation than the current line.
166 "
167 " exclusive (bool): true: Motion is exclusive
168 " false: Motion is inclusive
169 " fwd (bool): true: Go to next line
170 " false: Go to previous line
171 " lowerlevel (bool): true: Go to line with lower indentation level
172 " false: Go to line with the same indentation level
173 " skipblanks (bool): true: Skip blank lines
174 " false: Don't skip blank lines
175 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
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