-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
executable file
·233 lines (199 loc) · 7 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
syntax on
set nocompatible " Use vim defaults
set expandtab " Hitting Tab inserts X number of spaces.
set ls=2 " Always show status line
set shiftwidth=2 " Number of indented columns with reindent operations
set tabstop=2 " Number of columns a tab counts for
set hlsearch " Highlight searches
set incsearch " Do incremental searching
set listchars=tab:>-
set nomodeline " Disable mode lines (security measure)
set novisualbell " Turn off visual bell
set nowrap
set number " Show line numbers
set ruler " Show the cursor position all the time
set scrolloff=3 " Keep 3 lines when scrolling
set shortmess+=I " Hide the launch screen
set showcmd " Display incomplete commands
set showmode " Always show what mode we're currently editing in
set switchbuf+=usetab,newtab " Switch to existing tab
set tabpagemax=100
set title " Make your xterm inherit the title from Vim
set ttyfast " Don't lag…
set visualbell t_vb= " Turn off error beep/flash
set wildmenu " Enhanced tab-completion shows all matching cmds in a popup menu
set wildmode=list:longest,full " full completion options
set backspace=indent,eol,start
let g:loaded_matchparen= 1
set t_Co=256
colorscheme 256_redblack
" CTRL+P
" cd ~/.vim; git clone https://github.com/kien/ctrlp.vim.git bundle/ctrlp.vim
set runtimepath^=~/.vim/bundle/ctrlp.vim
" Compiler in use
compiler gcc
" turn off search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Eliminating delays on ESC in vim
set timeoutlen=1000 ttimeoutlen=0
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
" build using makeprg with <F7>
map <F7> :make<CR>
" build using makeprg with <S-F7>
map <S-F7> :make clean all<CR>
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Toggle show/hide invisible chars
nnoremap <leader>i :set list!<cr>
" Toggle show/hide numbers
nnoremap <leader>n :set nu!<cr>
" Toggle and untoggle spell checking
map <leader>s :setlocal spell!<cr>
map <leader>s? z=
" Search word under the cursor
map <F4> :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>
"folding settings
set foldenable " enable folding
set foldmethod=indent "fold based on indent
set foldnestmax=10 "deepest fold is 10 levels
set nofoldenable "dont fold by default
set foldlevel=1 "this is just what i use
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup " do not keep a backup file
set noswapfile
set nowritebackup
" store swap files in one of these directories
" (in case swapfile is ever turned on)
set directory=~/.vim/.tmp,~/tmp,/tmp
" Auto reload ~/.vimrc file upon saving
autocmd BufWritePost .vimrc source %
" Status line
set statusline=
set statusline +=*\ %n\ %* " buffer number
set statusline +=%w%h%m%r " Options
set statusline +=\[%{&ff}/%Y] " filetype
set statusline +=\ [%{hostname()}] " hostname
set statusline +=\ [%{getcwd()}] " current dir
set statusline +=\ %<%f\ " Filename
set statusline +=*%=%5l%* " current line
set statusline +=*/%LL%* " total lines
set statusline +=*%4vC\ %* " virtual column number
set statusline +=*0x%04B\ %* " character under cursor
" \p = Runs PHP lint checker on current file
map <leader>p :! php -l %<CR>
" \o remove reply indent levels
map <leader>o :call StripReply()<CR>
fun! StripReply()
execute '%s/^\W*/> /g'
endfun
" \z remove spaces between words
map <leader>z :call StripSpacesBetweenWords()<CR>
fun! StripSpacesBetweenWords()
execute '%s/\(\S\)\s\+\(\S\)/\1 \2/g'
endfun
" \g generates the header guard
map <leader>g :call IncludeGuard()<CR>
fun! IncludeGuard()
let basename = substitute(bufname(""), '.*/', '', '')
let guard = substitute(toupper(basename), '\.', '_', "H")
call append(0, "#ifndef " . guard . "_INCLUDED")
call append(1, "#define " . guard . "_INCLUDED")
call append( line("$"), "#endif // for #ifndef " . guard)
endfun
" Strip trailing whitespace
map <leader>w :call StripTrailingWhitespace()<CR>
fun! StripTrailingWhitespace()
" Don't strip on these filetypes
if &ft =~ 'markdown'
return
endif
%s/\s\+$//e
endfun
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,big5,gb2312,latin1
" Make Vim recognize xterm escape sequences for Page and Arrow
" keys combined with modifiers such as Shift, Control, and Alt.
" See http://www.reddit.com/r/vim/comments/1a29vk/_/c8tze8p
if &term =~ '^screen'
" Page keys http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/FAQ
execute "set t_kP=\e[5;*~"
execute "set t_kN=\e[6;*~"
" Arrow keys http://unix.stackexchange.com/a/34723
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
" let b:SuperTabDisabled = 0
map <leader>t :call SuperTabToggle()<CR>
let b:SuperTabDisabled = 0
fun! SuperTabToggle()
if b:SuperTabDisabled == 0
let b:SuperTabDisabled = 1
else
let b:SuperTabDisabled = 0
endif
echo "SuperTab: " b:SuperTabDisabled
endfun
" Show tab index in the tabline
if exists("+showtabline")
function! MyTabLine()
let s = ''
let wn = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let wn = tabpagewinnr(i,'$')
let s .= '%#TabNum#'
let s .= i
" let s .= '%*'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let bufnr = buflist[winnr - 1]
let file = bufname(bufnr)
let buftype = getbufvar(bufnr, 'buftype')
if buftype == 'nofile'
if file =~ '\/.'
let file = substitute(file, '.*\/\ze.', '', '')
endif
else
let file = fnamemodify(file, ':p:t')
endif
if file == ''
let file = '[No Name]'
endif
let s .= ' ' . file . ' '
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set stal=2
" set tabline=%!MyTabLine()
set showtabline=1
highlight link TabNum Special
endif
" Custom Indentation
autocmd BufRead,BufNewFile *.php,*.js,*.volt,*.html,*.htm,*.ini,*.css,*.mustache set noexpandtab shiftwidth=4 tabstop=4
autocmd BufRead,BufNewFile *.volt,*.html,*.htm set filetype=html
" Switch to last-active tab
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <Leader>gl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()