-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
251 lines (203 loc) · 7.44 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
" Disable error bells
set noerrorbells
set vb t_vb=
set mouse=a
let mapleader = " "
nnoremap <leader><Space> :Explore<CR>
" enable syntax "
syntax on
set incsearch
" enable line numbers "
" highlight current line "
"enable highlight search pattern "
" enable smartcase search sensitivity "
set ignorecase
set smartcase
set undofile
let &undodir = expand('$HOME/.vim/undodir_vim')
set signcolumn=yes
set smartcase
" Indentation using spaces "
" tabstop: width of tab character
" softtabstop: fine tunes the amount of whitespace to be added
" shiftwidth: determines the amount of whitespace to add in normal mode
" expandtab: when on use space instead of tab
" textwidth: text wrap width
" autoindent: autoindent in new line
set tabstop =4
set softtabstop =4
set shiftwidth =4
set textwidth =79
set expandtab
set autoindent
" show the matching part of pairs [] {} and () "
set showmatch
" remove trailing whitespace from Python and Fortran files "
autocmd BufWritePre *.py :%s/\s\+$//e
autocmd BufWritePre *.f90 :%s/\s\+$//e
autocmd BufWritePre *.f95 :%s/\s\+$//e
autocmd BufWritePre *.for :%s/\s\+$//e
" Change cursor shape in different modes
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[2 q"
augroup END
" Remove space between vertical and horizontal splits
" Map <C-d> to move down half a page and center the cursor line
nnoremap <C-d> <C-d>zz
" Map <C-u> to move up half a page and center the cursor line
nnoremap <C-u> <C-u>zz
" Map <leader>s to search and replace the word under the cursor
nnoremap <leader>s :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
" Map <leader>x to make the current file executable
nnoremap <leader>x :!chmod +x %<CR>
vnoremap <leader>y "+y
" Map <C-w>f to open the current file in a new tab
nnoremap <silent> <C-w>f :tab split<CR>
nnoremap <leader>fr :bro ol <CR>
nnoremap <leader>y "+y
vnoremap <leader>y "+y
nnoremap <leader>Y "+Y
" Define a function s:sink with the abort attribute
"Plug"
if filereadable(expand("~/.vim/autoload/plug.vim"))
" github.com/junegunn/vim-plug
call plug#begin('~/.local/share/vim/plugins')
Plug 'zah/nim.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'conradirwin/vim-bracketed-paste'
Plug 'morhetz/gruvbox'
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
Plug 'vim-pandoc/vim-pandoc'
Plug 'dahu/vim-asciidoc'
Plug 'rwxrob/vim-pandoc-syntax-simple'
Plug 'dense-analysis/ale'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
call plug#end()
let g:ale_sign_error = '☠'
let g:ale_sign_warning = '🙄'
let g:ale_linters = {'go': ['gometalinter', 'gofmt','gobuild']}
" pandoc
let g:pandoc#formatting#mode = 'h' " A'
let g:pandoc#formatting#textwidth = 72
" golang
let g:go_fmt_fail_silently = 0
let g:go_fmt_command = 'goimports'
let g:go_fmt_autosave = 1
let g:go_gopls_enabled = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 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_variable_declarations = 1
let g:go_highlight_variable_assignments = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_diagnostic_errors = 1
let g:go_highlight_diagnostic_warnings = 1
"let g:go_auto_type_info = 1 " forces 'Press ENTER' too much
let g:go_auto_sameids = 0
" let g:go_metalinter_command='golangci-lint'
" let g:go_metalinter_command='golint'
" let g:go_metalinter_autosave=1
" lsp
" lsp
" setting----------------------------------------------------------------------------------------------------
" NOTE: You can use other key to expand snippet.
" Expand
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
" Expand or jump
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>'
" Jump forward or backward
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
" See https://github.com/hrsh7th/vim-vsnip/pull/50
nmap s <Plug>(vsnip-select-text)
xmap s <Plug>(vsnip-select-text)
nmap S <Plug>(vsnip-cut-text)
xmap S <Plug>(vsnip-cut-text)
" lsp
" setting----------------------------------------------------------------------------------------------------
" setting----------------------------------------------------------------------------------------------------
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
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> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
" refer to doc to add more commands
endfunction
" setting----------------------------------------------------------------------------------------------------
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
set updatetime=100
colorscheme gruvbox
let g:go_gopls_analyses = { 'composites' : v:false }
au FileType go nmap <leader>m ilog.Print("made")<CR><ESC>
au FileType go nmap <leader>n iif err != nil {return err}<CR><ESC>
else
autocmd vimleavepre *.go !gofmt -w % " backup if fatih fails
endif
" Key mapping for paste mode
"Soruce the vimrc"
nnoremap confe :e $HOME/.vimrc<CR>
nnoremap confr :source $HOME/.vimrc<C
" Highlighting settings
" Markdown and pandoc settings
" YAML settings
au FileType yaml hi yamlBlockMappingKey ctermfg=NONE
au FileType yaml set sw=2
" Other filetype-specific settings
au FileType bash set sw=2
au FileType c set sw=8
au FileType sh set noet
function! WrapForTmux(s)
if !exists('$TMUX')
return a:s
endif
let tmux_start = "\<Esc>Ptmux;"
let tmux_end = "\<Esc>\\"
return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
endfunction
let &t_SI .= WrapForTmux("\<Esc>[?2004h")
let &t_EI .= WrapForTmux("\<Esc>[?2004l")
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[201~ XTermPasteBegin()
set background=dark