forked from dhnza/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
277 lines (225 loc) · 6.96 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
" =============================
" Utility Functions
" =============================
function! SilentMkdir(path)
if !isdirectory(a:path)
call mkdir(a:path, "p", 0700)
endif
endfunction
" =============================
" Vim Settings
" =============================
" Basics
syntax enable
set number
set relativenumber
set cursorline
set hlsearch
set ignorecase
set smartcase
" Correct use of tabs
set tabstop=4
set expandtab
" Indentation
set shiftwidth=4
set autoindent
" Open new split panes to right and bottom
set splitbelow
set splitright
" Tab completion in status bar
set wildmenu
" Use <Space> as leader key
let mapleader="\<Space>"
noremap <Space> <Nop>
" Use 'kj' to exit insert and command mode
inoremap kj <esc>
cnoremap kj <C-C>
" Persistent undo
set undofile "Maintain undo history between sessions
set undodir=~/.vim/undodir
call SilentMkdir($HOME . "/.vim/undodir")
" Write swap and backup files in different directory
set backupdir=~/.vim/backupdir//,/tmp//
set directory=~/.vim/swapfiles//,/tmp//
call SilentMkdir($HOME . "/.vim/backupdir")
call SilentMkdir($HOME . "/.vim/swapfiles")
" ------------------------------
" Shortcuts
" ------------------------------
" Quick save
nnoremap <Leader>w :w<CR>
nnoremap <Leader>wq :wq<CR>
" Open quickfix list item in new tab
nnoremap <C-t> <C-w><CR><C-w>T
" Move between tabs with <C-S-ARROW>
nnoremap <C-S-RIGHT> gt
nnoremap <C-S-LEFT> gT
" Define 'a line' and 'inside line' text objects
" al is the whole line, including all white space
" il is the 'text' inside the line, no leading/trailing white space
vnoremap <silent> al :<C-U>normal 0v$h<CR>
omap <silent> al :normal val<CR>
vnoremap <silent> il :<C-U>normal ^vg_<CR>
omap <silent> il :normal vil<CR>
" =============================
" Commands & Functions
" =============================
" Run makeprg and open quickfix window
command -nargs=* Make make! <args> | cwindow
function! DeleteInactiveBuffers()
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'buflisted(v:val) && index(tpbl, v:val)==-1')
silent exec 'bd' buf
endfor
endfunction
" =============================
" Vim Plug
" =============================
" Automatically install vim-plug
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
" High-light current word
Plug 'RRethy/vim-illuminate'
" Commenting shortcuts
Plug 'tomtom/tcomment_vim'
" Useful shell commands inside vim
Plug 'tpope/vim-eunuch'
" Surrounding text
Plug 'tpope/vim-surround'
" '.' command support for plugins
Plug 'tpope/vim-repeat'
" Handy navigation shortcuts
Plug 'tpope/vim-unimpaired'
" Manipulate variants of a word
Plug 'tpope/vim-abolish'
" Aligning text
Plug 'godlygeek/tabular'
" Syntax checker
Plug 'vim-syntastic/syntastic'
" Fugitive plug-in for git
Plug 'tpope/vim-fugitive'
" Git diff in gutter
Plug 'airblade/vim-gitgutter'
" Pretty status line
Plug 'itchyny/lightline.vim'
" FZF, both command and plugin installation
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Markdown integration
Plug 'plasticboy/vim-markdown'
" Tab completion
Plug 'ajh17/VimCompletesMe'
" Snippets
Plug 'SirVer/ultisnips'
" Color schemes
Plug 'altercation/vim-colors-solarized'
Plug 'sonph/onehalf', { 'rtp': 'vim' }
" Initialize plugin system
call plug#end()
" =============================
" Plugin settings
" =============================
" ------------------------------
" Color Scheme
" ------------------------------
set background=dark
colorscheme onehalfdark
" Enable 24-bit colors, if possible
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" ------------------------------
" Lightline
" ------------------------------
set laststatus=2
set noshowmode
let g:lightline = {
\ 'colorscheme': 'onehalfdark',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ },
\ }
" ------------------------------
" Syntastic
" ------------------------------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
" Disable python syntax checking
let g:syntastic_mode_map = { 'passive_filetypes': ['python'] }
" ------------------------------
" VimCompletesMe
" ------------------------------
" Run automatically on all file types
autocmd FileType vim let b:vcm_tab_complete = 'vim'
" ------------------------------
" UltiSnips
" ------------------------------
" Set triggers that don't conflict with VimCompletesMe
let g:UltiSnipsExpandTrigger = '<C-j>'
let g:UltiSnipsListSnippets = '<C-l>'
let g:UltiSnipsJumpForwardTrigger = '<C-j>'
let g:UltiSnipsJumpBackwardTrigger = '<C-k>'
" Open snippet editor in split window
let g:UltiSnipsEditSplit = 'context'
" ------------------------------
" Vim-Markdown
" ------------------------------
" Disable folding
let g:vim_markdown_folding_disabled = 1
" ------------------------------
" FZF
" ------------------------------
" Search files
nnoremap <Leader>f :Files<CR>
" Search inisde files
nnoremap <Leader>g :Rg<CR>
" Search lines in open buffers
nnoremap <Leader>l :BLines<CR>
nnoremap <Leader>L :Lines<CR>
" Search vim commands
nnoremap <Leader>p :Commands<CR>
" Search open buffers
nnoremap <Leader>b :Buffers<CR>
" Search through tags
nnoremap <Leader>t :BTags<CR>
nnoremap <Leader>T :Tags<CR>
" ------------------------------
" Tabularize
" ------------------------------
" Align text to character after <Leader>a
nnoremap <expr> <Leader>a ':Tabularize /'.nr2char(getchar()).'<CR>'
vnoremap <expr> <Leader>a ':Tabularize /'.nr2char(getchar()).'<CR>'
" =============================
" Miscellaneous
" =============================
" Highlight misspelled spelled words in red
hi SpellBad cterm=underline ctermfg=red
" Set the filetype based on the file's extension, but only if
" 'filetype' has not already been set
au BufRead,BufNewFile *.tpp set filetype=cpp
au BufRead,BufNewFile *.sbatch set filetype=sh
" Use git commit highlighting for dotfiles commits
au BufRead,BufNewFile COMMIT_EDITMSG set filetype=gitcommit
" =============================
" Per-Project Settings
" =============================
" Load settings from .projct_vimrc for all files in a project:
" autocmd BufReadPre,BufNewFile /patch/to/project/* source /path/to/.project_vimrc
" BufReadPre loads settings BEFORE the file is read, so that autocmd settings work.