-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
209 lines (166 loc) · 5.68 KB
/
vimrc
File metadata and controls
209 lines (166 loc) · 5.68 KB
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
set encoding=utf-8
set noswapfile
set nobackup
set incsearch
set clipboard+=unnamed
" ----- Plugins ------
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
Plug 'morhetz/gruvbox'
" fzf
" if has('unix')
" let s:uname = substitute(system('uname -s'), '\n', '', '')
" if s:uname == 'Darwin'
" Plug '/usr/local/opt/fzf'
" else
" Plug '/bin/fzf'
" endif
" endif
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" syntax highlighting
Plug 'HerringtonDarkholme/yats.vim'
" glsl
Plug 'tikhomirov/vim-glsl'
" go
" Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" git
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/nerdtree'
Plug 'mhinz/vim-grepper'
Plug 'tomtom/tcomment_vim'
Plug 'itchyny/lightline.vim'
Plug 'mbbill/undotree'
" tmux
Plug 'christoomey/vim-tmux-navigator'
Plug 'tmux-plugins/vim-tmux-focus-events'
" lsp
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'rhysd/vim-clang-format'
" languages
" Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'evanleck/vim-svelte'
" Initialize plugin system
call plug#end()
" ----- General ------
syntax on
set number
set cursorline
set nowrap
set relativenumber
" ----- Tabs -----
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
" ----- Theme ------
colorscheme gruvbox
set background=dark
" ----- Whitespace -----
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
keepp %s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
set list
set list listchars=tab:→\ ,trail:·
" ----- Keybindings -----
let mapleader = "\<Space>"
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
map <C-p> :Files<CR>
" map <C-p> :FZF<CR>
" nnoremap <esc><esc> :noh<return>
nnoremap <esc> :noh<return><esc>
" inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
" inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
" Insert <tab> when previous text is space, refresh completion if not.
inoremap <silent><expr> <TAB>
coc#pum#visible() ? coc#pum#next(1):
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
nnoremap <leader>g :Grepper -tool rg<CR>
nnoremap <leader>G :Grepper -tool rg -cword -noprompt<cr>
nnoremap <leader>nt :NERDTreeToggle<cr>
nnoremap <leader>nf :NERDTreeFind<cr>
nnoremap <leader>ut :UndotreeToggle<cr>:UndotreeFocus<cr>
autocmd FileType c,cpp,objc,glsl,frag,vert nnoremap <buffer><leader>cf :<C-u>ClangFormat<CR>
autocmd FileType c,cpp,objc,glsl,frag,vert vnoremap <buffer><leader>cf :ClangFormat<CR>
autocmd FileType c,cpp,objc,glsl,frag,vert nnoremap <buffer><leader>o :CocCommand clangd.switchSourceHeader<CR>
vmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format)
command! -nargs=0 CE :CocCommand eslint.executeAutofix
nmap <leader>ef :CE<cr>
command! -nargs=0 Prettier :CocCommand prettier.formatFile
nmap <leader>rn <Plug>(coc-rename)
nnoremap <silent> <leader>p :<C-u>CocList -I symbols<cr>
" nmap <silent>gd <Plug>(coc-definition)
" nmap <silent>gy <Plug>(coc-type-definition)
" nmap <silent>gi <Plug>(coc-implementation)
" nmap <silent> gr <Plug>(coc-references)
nmap <silent> gd :Telescope coc definitions<cr>
nmap <silent> gi :Telescope coc implementations<cr>
nmap <silent> gr :Telescope coc references<cr>
nnoremap <leader>te :tabe<cr>
nnoremap <leader>tc :tabc<cr>
nnoremap <leader>o :call CurtineIncSw()<cr>
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" I always it W so just make it write instead of the fzf command
command! W write
" Use K for show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if &filetype == 'vim'
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" ----- NERDTree ------
" let g:NERDTreeNodeDelimiter = "\u00a0" " Hack to fix NERDTree delim
" ----- fzf ------
" let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -l -g ""'
let $FZF_DEFAULT_COMMAND = "rg --hidden --files -g !.git"
" ----- quick fix -----
au FileType qf wincmd J
" ----- save on focus lost -----
":au FocusLost * silent! wa
" ----- refresh on focus -----
set autoread
" Triger `autoread` when files changes on disk
" https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044
" https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
" Notification after file change
" https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
" ----- status line -----
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'cocstatus', 'readonly', 'absolutepath', 'modified' ] ]
\ },
\ 'component_function': {
\ 'cocstatus': 'coc#status'
\ },
\ }
" Use autocmd to force lightline update.
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()