/
.vimrc
204 lines (172 loc) · 4.76 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
if !exists("loaded_setup")
" put in vim mode
set nocompatible
let g:loaded_setup=1
endif
set backspace=indent,eol,start
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set mouse=a " force mouse input to on
set number " turn on line numbers
syntax on " turn on syntax hilighting
" turn on tab complete for commands, with longest complete possible
set wildmenu
set wildmode=list:longest,full
" Vundle config
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'AnsiEsc.vim'
Plugin 'bufexplorer.zip'
Plugin 'winmanager'
Plugin 'linediff.vim'
Plugin 'scrooloose/syntastic'
Plugin 'tpope/vim-fugitive'
Plugin 'surround.vim'
Plugin 'python.vim'
Plugin 'systemverilog.vim'
Plugin 'altercation/vim-colors-solarized'
call vundle#end()
filetype plugin indent on
set background=dark
colorscheme solarized
" vimscript the hard way
let mapleader=" "
let localleader="\\"
" shortcut to display tabs
nnoremap <leader>l :set list!<CR>
" faster navigation
noremap <C-j> 10j
noremap <C-k> 10k
" center line when searching
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
" next and previous button hotkeys
nnoremap <leader>b :bp<CR>
nnoremap <leader>n :bn<CR>
" toggle pastemode
set pastetoggle=<F2>
" map a hotkey for wrap/nowrap
nnoremap <leader>w :set wrap!<CR>
" map a hotkey for the tabmode cycler
nnoremap <F9> :call TabModeHelper()<CR>
" map a hotkey for "do last macro"
nnoremap <C-B> @@
" TabModeHelper: select a tabmode, or create it if first run
" Cycle through the available tab modes, and call TabModeAbsolute to set the
" mode. Print the mode if not first time
fu! TabModeHelper()
if !exists("g:curtabmode")
let g:curtabmode = 0
elseif g:curtabmode < 2
let g:curtabmode += 1
echo "Tab Mode is" g:curtabmode
else
let g:curtabmode = 0
echo "Tab Mode is" g:curtabmode
endif
call TabModeAbsolute(g:curtabmode)
endfu
" TabModeAbsolute: set the tab mode based on the argument
fu! TabModeAbsolute(mode)
if a:mode == 0
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
elseif a:mode == 1
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
elseif a:mode == 2
set tabstop=4
set shiftwidth=4
set softtabstop=4
set noexpandtab
endif
endfu
" call TabModeHelper to put in first tab mode
call TabModeHelper()
function! DoPrettyXML()
" save the filetype so we can restore it later
let l:origft = &ft
set ft=
" delete the xml header if it exists. This will
" permit us to surround the document with fake tags
" without creating invalid xml.
1s/<?xml .*?>//e
" insert fake tags around the entire document.
" This will permit us to pretty-format excerpts of
" XML that may contain multiple top-level elements.
0put ='<PrettyXML>'
$put ='</PrettyXML>'
silent %!xmllint --format -
" xmllint will insert an <?xml?> header. it's easy enough to delete
" if you don't want it.
" delete the fake tags
2d
$d
" restore the 'normal' indentation, which is one extra level
" too deep due to the extra tags we wrapped around the document.
silent %<
" back to home
1
" restore the filetype
exe "set ft=" . l:origft
endfunction
command! PrettyXML call DoPrettyXML()
" Settings for window manager plugin
nnoremap <Leader>m :call DS_WMToggle()<CR>
let g:winManagerWindowLayout = 'BufExplorer'
let g:winManagerWidth = 30
let g:bufExplorerSortBy = 'name'
function! DS_WMToggle()
let currentWindowNumber = winnr() + 1
execute "WMToggle"
call DS_GotoWindow(0)
setlocal winfixwidth
call DS_GotoWindow(currentWindowNumber)
endfunction
function! DS_GotoWindow(reqdWinNum)
let startWinNum = winnr()
if startWinNum == a:reqdWinNum
return 1
end
if winbufnr(a:reqdWinNum) == -1
return 0
else
exe a:reqdWinNum.' wincmd w'
return 1
end
endfunction
" Automatically delete trailing whitespace.
autocmd BufWritePre * :%s/\s\+$//e
" Foldlist
let g:Flist_width=40
map <leader>o :vertical rightb wincmd F<CR>
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
" vimscript the hard way
nnoremap <leader>ev :topleft vertical split $MYVIMRC<CR>
nnoremap <leader>sv :source $MYVIMRC<CR>
inoremap jk <esc>
" Syntastic
let g:syntastic_always_populate_loc_list = 1
" Put a diff into all other buffers.
function! GetDiffBuffers()
return map(filter(range(1, winnr('$')), 'getwinvar(v:val, "&diff")'), 'winbufnr(v:val)')
endfunction
function! DiffPutAll()
for bufspec in GetDiffBuffers()
execute 'diffput' bufspec
endfor
endfunction
command! -range=-1 -nargs=* DPA call DiffPutAll()