forked from YanhaoYang/docker-golang-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init5-coc.vim
462 lines (375 loc) · 13.7 KB
/
init5-coc.vim
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
source ~/.config/nvim/plugins.vim
filetype on
filetype plugin indent on " Automatically detect file types.
syntax off " syntax highlighting
" Misc plugin settings {{{
let g:NERDDefaultAlign = 'left'
let g:vim_json_syntax_conceal = 0
let g:neodark#use_256color = 1
let g:neodark#terminal_transparent = 1
colorscheme neodark
" }}}
set encoding=utf-8
set wrap
set showbreak=...
set spell " spell checking on
set hidden " allow buffer switching without saving
set showmode " display the current mode
set redrawtime=10000 " fix timeout
if has('cmdline_info')
set ruler " show the ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " a ruler on steroids
set showcmd " show partial commands in status line and
endif
if has('statusline')
set laststatus=2
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
set statusline+=\ [%{&ff}/%Y] " filetype
" set statusline+=%{fugitive#statusline()} " Git Hotness
" set statusline+=\ [%{getcwd()}] " current dir
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
endif
set backspace=indent,eol,start " backspace for dummies
set linespace=0 " No extra spaces between rows
set nu " Line numbers on
set showmatch " show matching brackets/parenthesis
set incsearch " find as you type search
set hlsearch " highlight search terms
set winminheight=0 " windows can be 0 line high
set ignorecase " case insensitive search
set smartcase " case sensitive when uc present
set whichwrap=b,s,h,l,<,>,[,] " backspace and cursor keys wrap to
set scrolljump=5 " lines to scroll when cursor leaves screen
set scrolloff=3 " minimum lines to keep above and below cursor
set foldenable " auto fold code
set foldmethod=indent
set foldcolumn=2
set foldlevel=1
set list
set listchars=tab:,.,trail:.,extends:#,nbsp:. " Highlight problematic whitespace
set wildmenu " show list instead of just completing
set wildmode=list:longest,full " command <Tab> completion, list matches, then longest common part, then all.
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*.so,*.swp,*.zip
set autoindent " indent at the same level of the previous line
set smarttab
set shiftwidth=2 " use indents of 4 spaces
set expandtab " tabs are spaces, not tabs
set tabstop=2 " an indentation every four columns
set softtabstop=2 " let backspace delete indent
set pastetoggle=<F8> " pastetoggle (sane indentation on pastes)
set autowrite
augroup AutoWrite
autocmd! BufLeave * :update
augroup END
highlight ColorColumn ctermbg=235 guibg=#2c2d27
let &colorcolumn="80,100,".join(range(120,999),",")
" fix crontab: temp file must be edited in place
set backupskip=/tmp/*,/private/tmp/*
" Remove trailing whitespaces and ^M chars
autocmd BufWritePre * :%s/\s\+$//e
"jump to last cursor position when opening a file
"dont do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal! g`\""
normal! zz
endif
end
endfunction
let mapleader = ","
let g:mapleader = ","
" Fast saving
map <leader>w :w<CR>
imap <leader>w <ESC>:w<CR>
vmap <leader>w <ESC><ESC>:w<CR>
" :W sudo saves the file
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null
" NerdTree {
map <leader>e :NvimTreeToggle<CR>
nnoremap <silent> <C-f> :NvimTreeFindFile<CR>
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr', '\.DS_Store']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=0
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
" }
" FZF {
let $FZF_DEFAULT_COMMAND = 'ag -g ""'
nmap <leader>f :Files<CR>
nmap <leader>b :Buffers<CR>
nmap <leader>m :Marks<CR>
" }
map <C-q> :wqa<CR>
function! InitializeDirectories()
let separator = "."
let parent = $HOME
let prefix = '.vim'
let dir_list = {
\ 'backup': 'backupdir',
\ 'views': 'viewdir',
\ 'swap': 'directory' }
if has('persistent_undo')
let dir_list['undo'] = 'undodir'
endif
for [dirname, settingname] in items(dir_list)
let directory = parent . '/' . prefix . dirname . "/"
if exists("*mkdir")
if !isdirectory(directory)
call mkdir(directory)
endif
endif
if !isdirectory(directory)
echo "Warning: Unable to create backup directory: " . directory
echo "Try: mkdir -p " . directory
else
let directory = substitute(directory, " ", "\\\\ ", "g")
exec "set " . settingname . "=" . directory
endif
endfor
endfunction
call InitializeDirectories()
autocmd BufNewFile,BufRead *.{md,mkdn,markdown} set filetype=markdown
nmap <Leader>pm :PreviewMarkdown<CR>
nmap <Leader>pt :PreviewTextile<CR>
nmap <Leader>pr :PreviewRdoc<CR>
nmap <Leader>ph :PreviewHtml<CR>
" The Silver Searcher
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
endif
nnoremap gw :Ag <C-R><C-W><CR>
nnoremap gr :grep <cword> --ignore-dir public<CR>
nnoremap Gr :grep <cword> %:p:h/*<CR>
nnoremap gR :grep '\b<cword>\b'<CR>
nnoremap GR :grep '\b<cword>\b' %:p:h/*<CR>
nnoremap gs :%s/\<<C-r><C-w>\>/
nnoremap gb :Git blame<CR>
nnoremap gl :%!xmllint --format -<CR>
nnoremap gp :PreviewMarkdown<CR>
" https://github.com/wincent/clipper
nnoremap yc :call system('nc -N localhost 8377', @0)<CR>
" Allow to copy/paste between VIM instances {
"copy the current visual selection to ~/.vbuf
vmap <leader>y :w! ~/.share/.vbuf<cr>
"copy the current line to the buffer file if no visual selection
nmap <leader>y :.w! ~/.share/.vbuf<cr>
"paste the contents of the buffer file
nmap <leader>p :r ~/.share/.vbuf<cr>
" }
" turn off search highlighting (type <leader>n to de-select everything)
nmap <silent> <leader>n :silent :nohlsearch<cr>
" http://vimcasts.org/episodes/aligning-text-with-tabular-vim/
nmap <Leader>t= :Tabularize /=<CR>
vmap <Leader>t= :Tabularize /=<CR>
nmap <Leader>t: :Tabularize /:\zs<CR>
vmap <Leader>t: :Tabularize /:\zs<CR>
" neoclide/coc.nvim {{{
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
let g:coc_snippet_next = '<tab>'
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
autocmd FileType json syntax match Comment +\/\/.\+$+
" }}}
" Vim-go {{{
let g:go_metalinter_autosave = 1
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck', 'goimports']
let g:go_jump_to_error = 0
let g:go_fmt_command = "goimports"
" let g:go_auto_sameids = 1
" Show a list of interfaces which is implemented by the type under your cursor
autocmd FileType go nmap <Leader>s <Plug>(go-implements)
" Show type info for the word under your cursor
autocmd FileType go nmap <Leader>i <Plug>(go-info)
" Open the relevant Godoc for the word under the cursor
autocmd FileType go nmap <Leader>gd <Plug>(go-doc)
autocmd FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
" Open the Godoc in browser
autocmd FileType go nmap <Leader>gb <Plug>(go-doc-browser)
" Run/build/test/coverage
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <leader>c <Plug>(go-coverage)
" By default syntax-highlighting for Functions, Methods and Structs is disabled.
" Let's enable them!
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
nmap <F8> :TagbarToggle<CR>
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" turn to next or previous errors, after open location list
nmap <leader>j :lnext<CR>
nmap <leader>k :lprevious<CR>
autocmd FileType go nmap <leader>i <Plug>(go-install)
autocmd FileType go set tabstop=4
autocmd FileType go set softtabstop=4
autocmd FileType go set shiftwidth=4
autocmd FileType go set listchars=tab:\ \ ,trail:.,extends:#,nbsp:.
let g:go_fmt_options = { 'gofmt': '-s' }
autocmd FileType go nmap <Leader>ds <Plug>(go-def-split)
autocmd FileType go nmap <Leader>dv <Plug>(go-def-vertical)
autocmd FileType go nmap <Leader>dt <Plug>(go-def-tab)
function! HackVimGo()
autocmd! vim-go-buffer FileChangedShell <buffer>
endfunction
autocmd FileType go call HackVimGo()
" }}}
let g:SuperTabDefaultCompletionType = "<c-n>"
let g:SuperTabContextDefaultCompletionType = "<c-n>"
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>tj :tabnext
map <leader>tk :tabprevious
" visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
map <leader>q :q<cr>
nnoremap fa :GoAlternate<CR>
nnoremap fc :GoCallers<CR>
nnoremap fe :GoIfErr<CR>
nnoremap fi :GoImpl<CR>
nnoremap fk :GoKeyify<CR>
nnoremap fl :GoMetaLinter<CR>
nnoremap fm :GoFmt<CR>
nnoremap fp :GoImports<CR>
nnoremap frf :GoReferrers<CR>
nnoremap frn :GoRename<CR>
nnoremap fs :GoFillStruct<CR>
nnoremap ft :GoAddTags<CR>
nnoremap fv :GoVet<CR>
" https://github.com/lambdalisue/fern.vim
nnoremap fo :Fern .<CR>
nnoremap ff :Fern . -reveal=%<CR>
map <leader>lo :lopen<CR>
map <leader>lf :lfirst<CR>
map <leader>lc :lclose<CR>
" get from REMOTE, file you are merging into your branch
nnoremap dr :diffg RE
" get from BASE, common ancestor
nnoremap db :diffg BA
" get from LOCAL, file from the current branch
nnoremap dl :diffg LO
lua require'hop'.setup()
noremap <leader>w :HopWord<CR>
lua <<EOF
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (or "all")
ignore_install = { "javascript" },
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
highlight = {
enable = true,
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
disable = { "c", "rust" },
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
EOF
lua <<EOF
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
-- vim.opt.termguicolors = true
-- empty setup using defaults
require("nvim-tree").setup()
-- OR setup with some options
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 30,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})
EOF