This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
forked from jmdaly/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
259 lines (215 loc) · 8.97 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
" Install vim-plug if it isn't installed
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
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'bling/vim-airline'
Plug 'tpope/vim-fugitive'
Plug 'jeetsukumaran/vim-buffergator'
Plug 'derekwyatt/vim-fswitch'
Plug 'tomtom/tcomment_vim' " Plugin to assist with commenting out blocks of text:
Plug 'octol/vim-cpp-enhanced-highlight' " Better C++ Syntax Highlighting:
Plug 'mrtazz/DoxygenToolkit.vim' " Plugin to generate doxygen documentation strings:
Plug 'majutsushi/tagbar' " tagbar - allows browsing tags of the current source file
Plug 'junegunn/vim-easy-align' " Plugin to allow easy alignment around various symbols
Plug 'easymotion/vim-easymotion' "Plugin to make it easier to use motions to jump to words and characters
Plug 'mhinz/vim-startify' "Plugin to provide a useful start screen in vim
Plug 'christoomey/vim-tmux-navigator' "vim/tmux navigator
Plug 'tpope/vim-sleuth'
Plug 'vim-scripts/SearchComplete' " Tab-completion for '/' searching
Plug 'tmhedberg/matchit' " matchit plugin
Plug 'mhinz/vim-grepper'
Plug 'justinmk/vim-sneak' " Faster than using 'f'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzzy search
Plug 'junegunn/fzf.vim'
Plug 'heavenshell/vim-jsdoc'
Plug 'tpope/vim-surround'
Plug 'w0rp/ale'
Plug 'psf/black', { 'branch': 'stable' }
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'w0ng/vim-hybrid'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
" Plug 'heavenshell/vim-pydocstring', { 'do': 'make install', 'for': 'python' }
call plug#end()
" Colorscheme
set background=dark
let g:hybrid_custom_term_colors = 1
let g:hybrid_reduced_contrast = 1 " Remove this line if using the default palette.
colorscheme hybrid
set nocompatible
filetype off
set expandtab
set splitbelow
set splitright
set number
set ignorecase
set smartcase
set nomousehide
set wildmenu
set backspace=indent,eol,start " backspace sanity
autocmd Filetype python setlocal ts=4 sw=4 tw=79 "python settings
autocmd Filetype cpp setlocal ts=2 sw=2 tw=79
autocmd Filetype xml setlocal ts=4 sw=4 tw=0
autocmd Filetype json setlocal ts=2 sw=2 tw=0 "JSON convention
autocmd Filetype cmake setlocal ts=2 sw=2 tw=0 tw=79 "cmake convention
autocmd Filetype md setlocal tw=79
autocmd Filetype rst setlocal tw=79
au BufNewFile,BufRead Jenkinsfile setf groovy " Treat Jenkinsfile's with groovy syntax
" let python_highlight_all=1 " Vim built-in syntax highlighting for python
let $XMLLINT_INDENT=' ' " Set xmllint to 4 space indentation
filetype plugin indent on " required
" Never automatically continue comment on next line
au FileType * set fo-=c fo-=r fo-=o
syntax enable
" General language server settings
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> gp <plug>(lsp-peek-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> g[ <plug>(lsp-previous-diagnostic)
nmap <buffer> g] <plug>(lsp-next-diagnostic)
nmap <buffer> ge <plug>(lsp-next-error)
nmap <buffer> gh <plug>(lsp-hover)
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
" autocmd! BufWritePre *.py,*.cpp,*.c,*.h call execute('LspDocumentFormatSync')
autocmd! BufWritePre *.cpp,*.c,*.h call execute('LspDocumentFormatSync')
" refer to doc to add more commands
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" Python LSP
if executable('pylsp')
" pip install python-lsp-server
au User lsp_setup call lsp#register_server({
\ 'name': 'pylsp',
\ 'cmd': {server_info->['pylsp']},
\ 'allowlist': ['python']
\})
endif
if executable('clangd-12')
au User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
\ 'cmd': {server_info->['clangd-12', '-background-index', '-header-insertion=never']},
\ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'],
\ })
endif
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_diagnostics_enabled = 1
" let g:lsp_signs_enabled = 1
" let g:lsp_signs_error = {'text': '✗'}
" let g:lsp_signs_warning = {'text': '!'}
" let g:lsp_highlights_enabled = 1
" let g:lsp_virtual_text_enabled = 0
" let g:lsp_diagnostics_echo_cursor = 0
" let g:lsp_diagnostics_float_cursor = 1
" let g:lsp_highlight_references_enabled = 1
" let g:lsp_preview_max_width = 80
let g:black_linelength = 79
set laststatus=2 " always display statusline
let g:airline#extensions#tabline#enabled = 1 " enable the list of buffers
let g:airline#extensions#ale#enabled = 1 " enable ale messages in statusline
let g:airline#extensions#tabline#fnamemod = ':t' " show just the filename
let g:airline_powerline_fonts = 1
" let g:ycm_collect_identifiers_from_tags_files = 1 " Let YouCompleteMe use tag files for completion as well:
" Vim sneak
let g:sneak#label = 1 " minimaist vim-sneak
" replace s with f for sneaking
nnoremap f <Plug>Sneak_s
nnoremap F <Plug>Sneak_S
" Pydocstring
" nnoremap <silent> <Dop> <Plug>(pydocstring)
" NERD Tree shortcut
map <F5> :NERDTreeToggle<CR>
let NERDTreeChDirMode = 2
nnoremap <leader>n :NERDTree .<CR>
" asynccomplete
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() : "\<cr>"
" vsnip
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
" If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.
let g:vsnip_filetypes = {}
let g:vsnip_filetypes.javascriptreact = ['javascript']
let g:vsnip_filetypes.typescriptreact = ['typescript']
let g:vsnip_snippet_dir = '~/dotfiles/vsnip'
" Mapping for fswitch, to switch between header
" and source:
" nnoremap <leader>s :FSHere<CR>
augroup FILE_FORMATTING
autocmd FileType cpp noremap <buffer> <expr> <leader>f ":py3f " . "/usr/share/clang/clang-format-12/clang-format.py<CR>"
autocmd FileType c noremap <buffer> <expr> <leader>f ":py3f " . "/usr/share/clang/clang-format-12/clang-format.py<CR>"
autocmd FileType python noremap <buffer> <expr> <leader>f ":Black<CR>"
augroup END
" custom vim split commands
" Tmux style pane navigation in vim
nnoremap <c-j> <C-w>j
nnoremap <c-k> <C-w>k
nnoremap <c-h> <C-w>h
nnoremap <c-l> <C-w>l
" tmux navigation through vim splits
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
nnoremap <silent> <c-\> :TmuxNavigatePrevious<cr>
" Use tab and shift+Tab to switch buffers
nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>
let g:tmux_navigator_save_on_switch = 1 " This will execute the update command on leaving vim to a tmux pane. Default is Zero
" fzf mappings
nnoremap <leader>fa :Ag<CR>
nnoremap <leader>ff :Files<CR>
noremap <leader>fh :BCommits<CR>
noremap <leader>fc :BLines<CR>
noremap <leader>fb :Buffers<CR>
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-i': 'vsplit' }
" Check this link if having issues with displaying 'down'
" https://github.com/junegunn/fzf/issues/1486
let g:fzf_layout = { 'up': '~40%' }
nnoremap <leader>q :bd<CR> " Close current buffer
" Function, courtesy of Marc Gallant, to make it easy
" to switch between C and C++ header and source files
" using fzf.
function! FZFSameName(sink, pre_command, post_command)
let current_file_no_extension = expand("%:t:r")
let current_file_with_extension = expand("%:t")
execute a:pre_command
call fzf#run(fzf#wrap({
\ 'source': 'find -name ' . current_file_no_extension . '.* | grep -Ev *' . current_file_with_extension . '$',
\ 'options': '--select-1', 'sink': a:sink}))
execute a:post_command
endfunction
nnoremap <leader>ss :call FZFSameName('e', '', '')<CR>
" Remove obnoxious noises vim makes
set noerrorbells visualbell t_vb=
if has('autocmd')
autocmd GUIEnter * set visualbell t_vb=
endif