forked from etr/config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·253 lines (205 loc) · 7.28 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
" Vim Settings
" -----------------------------------------------------------------------------
" Remove compatibility with vi.
set nocompatible
set grepprg=grep\ -nH\ $*
" Dark background color. Leads to brighter fonts.
set background=dark
set number
"colorscheme desert
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Tabs become 4 spaces
set expandtab
set tabstop=4
set shiftwidth=4
" History of 100 commands
set history=100
" Show info about the cursor position
set ruler
" Display commands as you type them
set showcmd
" Disable incremental search
set noincsearch
" Use shiftwidth when indenting and when inserting a <Tab>
set smarttab
" Window minimum height set to zero, so that when you have multiple windows you
" are not forced to see one row for each file.
set wmh=0
" Max text width: 78 columns.
"set textwidth=78
" When inserting a closing parenthesis, briefly flash the closed one
set showmatch
" Used to open quickfix errors in new windows
set switchbuf=split
" Backup in /tmp
set bdir=/tmp,.
" Enhanced mode for command-line tab completion
set wildmenu
" Fix for pyflakes, that screws the quickfix window.
let g:pyflakes_use_quickfix = 0
" Persistent Undo
set undodir=~/.vim/undodir
set undofile
"set undolevels=1000 "maximum number of changes that can be undone
"set undoreload=10000 "maximum number lines to save for undo on a buffer reload
set mouse=a
" Reach the line while searching
set incsearch
" Ignore files which name matches
set wildignore=*.o,*.obj,*.bak,*.exe,*.a,*.so
" Key mappings
" -----------------------------------------------------------------------------
" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" Call man for the word under the cursor
map <F1> :exe ":!man ".expand("<cword>")<CR>
" Move to the directory of the file in the current buffer
map <F4> :cd %:p:h<CR>
" Run make
map <F5> :make<CR>
" Use <C-J> (resp. <C-K>) to move one window up (resp. down) and maximize the
" new window
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
imap <C-J> <Esc><C-J>a
imap <C-K> <Esc><C-K>a
" Use <C-L> (resp. <C-H>) to move to the next (resp. previous) tab.
map <C-L> :tabn<CR>
map <C-H> :tabp<CR>
" Lets the backspace key start a new undo sequence
inoremap <C-H> <C-G>u<C-H>
" Allows j and k keys to move even inside wrapped lines
map j gj
map k gk
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Functions
" -----------------------------------------------------------------------------
function! s:LookupPythonModule()
let l:module_name = expand("<cword>")
let l:cmd = "/usr/bin/python -c 'import " . l:module_name . "; print " . l:module_name . ".__file__[:-1]'"
let l:module = system(l:cmd)
try
exe "sp " . l:module
catch /E172:/
echo "Not a module, or maybe a builtin module. Couldn't reach it, sorry."
endtry
endfunction
" Autocommands
" -----------------------------------------------------------------------------
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Forced file types for some extensions
au BufNewFile,BufRead *.thtml setfiletype php
au BufNewFile,BufRead *.tex setfiletype tex
au BufNewFile,BufRead *.hpp setfiletype cpp
au BufNewFile,BufRead *.as setfiletype actionscript
au! Syntax slice source ~/.vim/syntax/slice.vim
au BufNewFile,BufRead *.ice setfiletype slice
" Filetype-dependent autocommands
au FileType java set makeprg=ant\ -emacs
au FileType python match errorMsg /^\t+/
au FileType python set makeprg=pep8\ --repeat\ %
au FileType python command! LookupPythonModule :call <SID>LookupPythonModule()
au Filetype python map <F7> :LookupPythonModule<CR>
" If there is a local .lvimrc file, source it (useful for project-related vim
" settings)
au BufRead,BufNewFile * let x=expand('%:p:h')."/.lvimrc" | if filereadable(x) | exe "source ".substitute(x, ' ', '\\ ', 'g') | endif
let x=expand('%:p:h')."/.lvimrc" | if filereadable(x) | exe "source ".substitute(x, ' ', '\\ ', 'g') | endif
endif
" Strip the newline from the end of a string
function! Chomp(str)
return substitute(a:str, '\n$', '', '')
endfunction
" Find a file and pass it to cmd
function! DmenuOpen(cmd)
let fname = Chomp(system("git ls-files | dmenu -i -l 20 -p " . a:cmd))
if empty(fname)
return
endif
execute a:cmd . " " . fname
endfunction
function! ToggleCopyMode()
if &mouse == 'a'
set mouse=
set nonumber
set paste
echo "Copy mode!"
else
set mouse=a
set number
set nopaste
endif
endfunction
" Allow usage of Dmenu as file searcher
map <c-t> :call DmenuOpen("tabe")<cr>
map <c-f> :call DmenuOpen("e")<cr>
" Enable usage of NERDTree
map <F2> <esc>:NERDTreeToggle<cr>
map <F3> <esc>:TlistToggle<cr>
map <F12> <esc>:call ToggleCopyMode()<cr>
" highlight if 80 char per line is exceeded
autocmd FileType cpp highlight OverLength ctermbg=red ctermfg=white
autocmd FileType hpp highlight OverLength ctermbg=red ctermfg=white
autocmd FileType h highlight OverLength ctermbg=red ctermfg=white
autocmd FileType python highlight OverLength ctermbg=red ctermfg=white
" guibg=#592929
autocmd FileType cpp match OverLength /\%81v.\+/
autocmd FileType hpp match OverLength /\%81v.\+/
autocmd FileType python match OverLength /\%81v.\+/
" make easy access
let $makejarg=""
fun! SetMkfile()
let filemk = "Makefile"
let buildpt = "build/"
let pathmk = "./"
let depth = 1
while depth < 4
if filereadable(pathmk . filemk)
return pathmk
endif
if filereadable(pathmk . buildpt . filemk)
return pathmk . buildpt
endif
let depth += 1
let pathmk = "../" . pathmk
endwhile
return "."
endf
command! -nargs=* Make | let $mkpath=SetMkfile() | make <args> $makejarg -C $mkpath | cwindow 5
map <F6> <esc>:Make<cr>
"omnifunc code complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType cpp set omnifunc=ccomplete#Complete
"swaps current word with the following
nmap <silent> gw "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr><c-o><c-l>
" reach directory of file in selected buffer
autocmd BufEnter * lcd %:p:h
" automatically remove trailing whitespaces
set wrap
set linebreak
" note trailing space at end of next line
set showbreak=>\ \ \
autocmd FileType c,cpp,h,hpp,java,php autocmd BufWritePre <buffer> :%s/\s\+$//e