-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
222 lines (191 loc) · 5.56 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"
" ~/.vimrc
"
""""""""""""
" Main options {{{
if $TERM =~ "256"
set t_Co=256
colorscheme zencustom
else
set t_Co=16
colorscheme delek
endif
set nocompatible
set autoindent
set expandtab
set incsearch
set ignorecase
set smartcase
set nobackup
set hlsearch
set nowrap
set number
set confirm
set ruler
set showmode
set showcmd
set smartindent
set smarttab
set linebreak
set title
set vb t_vb=
set shiftwidth=2
set showtabline=1
set laststatus=2
set shortmess=a
set history=50
set updatetime=500
set mouse=nvcr
set foldmethod=syntax
set formatoptions=tcroqn1
set backspace=indent,eol,start
set wildmode=list:longest,full
syntax on
filetype plugin indent on
" }}}
" Folding stuffs {{{
if has ('folding')
set foldenable
set foldmethod=marker
set foldmarker={{{,}}}
set foldcolumn=0
endif
" }}}
" Keymaps {{{
" unmap annoying keys
nnoremap q: <Nop>
nnoremap q/ <Nop>
nnoremap q? <Nop>
" leader key
:let mapleader = ","
" diff
nnoremap <Leader>u :diffupdate<cr>
nnoremap <Leader>g :diffget<cr>
nnoremap <Leader>p :diffput<cr>
" comment/uncomment a visual block
vmap <Leader>c :call CommentLines()<CR>
" macro key
:nnoremap <F2> @q
map ; :
map <space> za
" Tab indents code in visual mode
vmap <Tab> >gv
vmap <S-Tab> <gv
cmap w!! %!sudo tee > /dev/null %
" Tab controls
map <Leader><Tab> :tabnew
map <Leader>o :tabnext<CR>
map <Leader>a :tabprevious<CR>
" }}}
" Autocommands {{{
if has('autocmd')
let python_highlight_all = 1
let python_highlight_space_errors = 1
let python_fold = 1
let lua_fold = 1
let lua_version = 5
let lua_subversion = 1
" html
au Filetype html,xml,xsl set spell
" Remove trailing whitespace
let blacklist = [ 'mail' ]
au BufWritePre * if index(blacklist, &ft) < 0 | :call setline(1, map(getline(1, "$"), 'substitute(v:val, "\\s\\+$", "","")'))
" set the title string
au BufEnter * let &titlestring = "vim: " . substitute(expand("%:p"), $HOME, "~", '')
au BufEnter * let &titleold = substitute(getcwd(), $HOME, "~", '')
" set a better status line
au BufRead * call SetStatusLine()
" restore cursor position
au BufReadPost * call RestoreCursorPos()
"au BufWinEnter * call OpenFoldOnRestore()
" file types for nonstandard/additional config files
au BufNewFile,BufRead *conkyrc* set ft=conkyrc
au BufNewFile,BufRead *muttrc* set ft=muttrc
au BufNewFile,BufRead *.rem set ft=remind
au BufNewFile,BufRead $SCREEN_CONF_DIR/* set ft=screen
au BufNewFile,BufRead *.xcolors set ft=xdefaults
au BufNewFile,BufRead *.rss set ft=xml
" change how vim behaves when composing emails
au BufNewFile,BufRead ~/.mutt/temp/mutt* set ft=mail | set textwidth=72 | set spell | set nohls
au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap <F1> gqap
au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap <F2> gqqj
au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap <F3> kgqj
au BufNewFile,BufRead ~/.mutt/temp/mutt* map! <F1> <ESC>gqapi
au BufNewFile,BufRead ~/.mutt/temp/mutt* map! <F2> <ESC>gqqji
au BufNewFile,BufRead ~/.mutt/temp/mutt* map! <F3> <ESC>kgqji
" set comment characters for common languages
au FileType * let StartComment="#" | let EndComment=""
au FileType python,sh,bash,zsh,ruby,perl,unix let StartComment="#" | let EndComment=""
au FileType cpp,php,c,javascript let StartComment="//" | let EndComment=""
au FileType html let StartComment="<!--" | let EndComment="-->"
au FileType haskell let StartComment="--" | let EndComment=""
au FileType lua let StartComment="--" | let EndComment=""
au FileType vim let StartComment="\"" | let EndComment=""
" file type specific commands
au FileType c set formatoptions+=ro
au FileType make set noexpandtab shiftwidth=8
au FileType python set expandtab shiftwidth=2 tabstop=2
au FileType c syn match matchName /\(#define\)\@<= .*/
au FileType cpp syn match matchName /\(#define\)\@<= .*/
au FileType text setlocal textwidth=72
endif
" }}}
" Functions {{{
function! SetStatusLine()
let l:s1="%-3.3n\\ %f\\ %h%m%r%w"
let l:s2="[%{strlen(&filetype)?&filetype:'?'},\\ %{&encoding},\\ %{&fileformat}]"
let l:s3="%=\\ 0x%-8B\\ \\ %-14.(%l,%c%V%)\\ %<%P"
execute "set statusline=" . l:s1 . l:s2 . l:s3
endfunction
function! RestoreCursorPos()
if expand("<afile>:p:h") !=? $TEMP
if line("'\"") > 1 && line("'\"") <= line("$")
let line_num = line("'\"")
let b:doopenfold = 1
if (foldlevel(line_num) > foldlevel(line_num - 1))
let line_num = line_num - 1
let b:doopenfold = 2
endif
execute line_num
endif
endif
endfunction
function! OpenFoldOnRestore()
if exists("b:doopenfold")
execute "normal zv"
if(b:doopenfold > 1)
execute "+".1
endif
unlet b:doopenfold
endif
endfunction
function CommentLines()
try
execute ":s@^".g:StartComment." @\@g"
execute ":s@ ".g:EndComment."$@@g"
catch
execute ":s@^@".g:StartComment." @g"
execute ":s@$@ ".g:EndComment."@g"
endtry
endfunction
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
function MapToggle(key, opt)
let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
exec 'nnoremap '.a:key.' '.cmd
exec 'inoremap '.a:key." \<C-O>".cmd
endfunction
command -nargs=+ MapToggle call MapToggle(<f-args>)
MapToggle <F4> foldenable
MapToggle <F5> number
MapToggle <F6> spell
MapToggle <F7> paste
MapToggle <F8> hlsearch
MapToggle <F9> wrap
" }}}