-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
329 lines (277 loc) · 7.42 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
"
" my .vimrc :D
"
set nocompatible
set shell=/usr/bin/bash
" install vim-plug
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
filetype off
call plug#begin('~/.config/nvim/bundle')
" colors
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" helpers
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-abolish' " case-insensitive substitution replace
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --no-update-rc' }
Plug 'junegunn/fzf.vim'
Plug 'justinmk/vim-sneak'
Plug 'mg979/vim-visual-multi'
Plug 'chrisbra/matchit' " extend % matching
" ide
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'w0rp/ale'
Plug 'SirVer/ultisnips'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'fannheyward/telescope-coc.nvim'
" misc
Plug 'christoomey/vim-tmux-navigator'
Plug 'airblade/vim-gitgutter'
Plug 'moll/vim-bbye'
Plug 'psliwka/vim-smoothie'
Plug 'NoahTheDuke/vim-just'
call plug#end()
filetype plugin indent on
syntax on
set noshowmode
set cmdheight=2
set showcmd
set backspace=eol,start,indent
set cursorline
set cursorcolumn
set wildmenu
set wildmode=longest,list:longest,full
set ruler
set ignorecase
set smartcase
set infercase
set hlsearch
set incsearch
set showmatch
set nostartofline
set nonumber
set autoindent
set nobackup
set nowritebackup
set noswapfile
set scrolloff=5
set hidden
set noerrorbells
set novisualbell
set signcolumn=yes
set expandtab
set smarttab
set shiftwidth=0
set tabstop=4
set laststatus=2
set cmdheight=2
set t_Co=256
set shortmess+=c
set completeopt=menu,menuone,preview,noinsert,noselect
set clipboard^=unnamedplus
set updatetime=300
set fileformats=unix
set list
set listchars=tab:│\ ,trail:-,extends:>,precedes:<
set encoding=utf-8
set mouse=a
set foldmethod=syntax
set nofoldenable
" colors
set termguicolors
let g:gruvbox_transparent_bg = 1
colorscheme gruvbox
if has("nvim")
set inccommand=nosplit
endif
if has("gui_running")
" remove menus and toolbars
set guioptions-=m
set guioptions-=g
set guioptions-=t
set guioptions-=T
" remove scrollbars
set guioptions-=r
set guioptions-=R
set guioptions-=l
set guioptions-=L
set guioptions-=b
" remove clipboard autoselection
set guioptions-=a
set guioptions-=A
" console dialogs
set guioptions+=c
endif
" basic mappings
" noremap ; :
noremap j gj
noremap k gk
" user space as leader key
let mapleader="\<space>"
let g:mapleader="\<space>"
" listen to Alt keys
if !has('nvim')
let c = 'a'
while c <= 'z'
exec "set <a-" . c . ">=\e" . c
exec "imap \e" . c . " <a-" . c . ">"
let c = nr2char(1 + char2nr(c))
endw
end
" easily move between splits
" nnoremap <c-j> <c-w>j
" nnoremap <c-k> <c-w>k
" nnoremap <c-h> <c-w>h
" nnoremap <c-l> <c-w>l
" nnoremap <leader>wc <c-w>c
" easily create splits
nnoremap <leader>sv :vsp<cr>
nnoremap <leader>sh :sp<cr>
" switch between files in buffer
nmap <a-l> :bn<cr>
nmap <a-h> :bp<cr>
" don't close buffer on :bd if it's displayed more than once
let bclose_multiple = 0
" remove search highlight
nnoremap <silent><leader>n :noh<cr>
" useful for keeping sanity
cab W! w!
cab Q! q!
cab Wq wq
cab Wa wa
cab wQ wq
cab WQ wq
cab W w
cab Q q
cab E e
map q: :q
" save with sudo
cmap w!! w !sudo tee > /dev/null %
" diffing
nnoremap <leader>do :diffget<cr>
nnoremap <leader>dp :diffput<cr>
" don't lose selection when shifting sidewards
xnoremap < <gv
xnoremap > >gv
" edit and source .vimrc easily
nnoremap <leader>ev :e $MYVIMRC<CR>
nnoremap <leader>lv :so $MYVIMRC<CR>
" create necessary directories on saving files
augroup vimrc-auto-mkdir
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force)
if !isdirectory(a:dir)
\ && (a:force
\ || input("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction
augroup END
" don't yank to default register when changing something
nnoremap c "xc
xnoremap c "xc
" don't copy over-pasted text in visual mode
xnoremap p "_s<c-r>+<esc>
xnoremap P "_s<c-r>+<esc>
" different settings for some file types
autocmd FileType json,terraform,javascript,typescript setlocal tabstop=2
autocmd FileType yml,yaml setlocal tabstop=2 indentkeys-=<:> foldmethod=indent
autocmd FileType go setlocal tabstop=4 noexpandtab
augroup TerminalMappings
autocmd!
if has('nvim')
autocmd TermOpen * nnoremap <buffer> <C-c> i
endif
augroup END
"
" plugins
"
" Tree Sitter
lua <<EOF
require('nvim-treesitter.configs').setup {
ensure_installed = "all",
indent = { enable = true },
highlight = { enable = true },
}
EOF
" vim-bbye: close buffer without closing split view
nnoremap <silent><c-c> :Bdelete<cr>
" tmux navigation
let g:tmux_navigator_disable_when_zoomed = 1
" nvim-tree
nnoremap <silent><expr> <a-1> &filetype == 'NvimTree' ? ":NvimTreeClose\<cr>" : ":NvimTreeFocus\<cr>"
nnoremap <silent> <leader>ff <cmd>NvimTreeFindFile<cr>
lua <<EOF
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
require("nvim-tree").setup {
view = {
adaptive_size = true,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
}
EOF
" telescope
nnoremap <silent> <leader>pf <cmd>Telescope find_files<cr>
nnoremap <silent> <leader>pg <cmd>Telescope live_grep<cr>
nnoremap <silent> <leader>pb <cmd>Telescope buffers<cr>
nnoremap <silent> <leader>pr <cmd>Telescope oldfiles<cr>
nnoremap <silent> <leader>pt <cmd>Telescope file_browser<cr>
nnoremap <silent> <leader>pp <cmd>Telescope pickers<cr>
lua <<EOF
require('telescope').setup {
defaults = {
cache_picker = {
num_pickers = -1
},
file_ignore_patterns = { "node_modules" }
}
}
EOF
" airline
let g:airline_theme = 'gruvbox'
" ale
let g:ale_fix_on_save = 1
"
" coc
"
nnoremap <silent> gd <cmd>Telescope coc definitions<cr>
nnoremap <silent> gt <cmd>Telescope coc type_definitions<cr>
nnoremap <silent> gi <cmd>Telescope coc implementations<cr>
nnoremap <silent> gr <cmd>Telescope coc references<cr>
nnoremap <silent> gs <cmd>Telescope coc document_symbols<cr>
nnoremap <silent> gS <cmd>Telescope coc workspace_symbols<cr>
nnoremap <silent> ge <cmd>Telescope coc diagnostics<cr>
nnoremap <silent> gE <cmd>Telescope coc workspace_diagnostics<cr>
" highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" symbol renaming.
nmap <leader>rr <Plug>(coc-rename)
" use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" show signature help
inoremap <silent><c-\> <c-r>=CocActionAsync('showSignatureHelp')<cr>
inoremap <silent><c-k> <c-r>=CocActionAsync('showSignatureHelp')<cr>
" remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-codeaction-line)
" enter key for completions
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"