-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
228 lines (208 loc) · 5.66 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
syntax on
filetype plugin on
set nocompatible
set nu
set rnu
set hidden
set shortmess+=c
set backspace=2
set autoindent
set hlsearch
set incsearch
set smartcase
set ignorecase
set wildmenu
set wildoptions+=pum
set shiftwidth=4
set tabstop=6
set expandtab
set softtabstop=4
set spr
set ttimeoutlen=10
set signcolumn=yes
set cursorline
set laststatus=2
set statusline=%!Cleanline()
set undofile
set noshowmode
set showcmd
set sloc=statusline
set undodir=~/.vim/undo
set vop-=options
set gp=git\ grep\ -n
set list lcs=tab:\|\
noremap s :edit
noremap S :cd
nnoremap <up> <c-w>k
nnoremap <down> <c-w>j
nnoremap <right> <c-w>l
nnoremap <left> <c-w>h
nnoremap <Esc> :set invhlsearch<CR>
nnoremap <c-z> :qa!
nnoremap \\ :call InvMemory()<CR>
nnoremap \s :call JumpToNormalBuffer("bn")<CR>
nnoremap \a :call JumpToNormalBuffer("bp")<CR>
nnoremap \w :cn<CR>zz
nnoremap \q :cp<CR>zz
nnoremap <silent> \<cr> :call ToggleQuickFix()<CR>
nnoremap \] :Lex<CR>
" use OSC52, only support yank, paste by <ctrl-shift V> in insert mode
"vnoremap <c-y> "my:call OSC52('m')<CR>
vnoremap <c-y> "+y
vnoremap <c-p> "+p
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
cnoremap <c-f1> %:p:h
colorscheme waterless
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_winsize = 20
au BufWinLeave * if expand("%:p") != "" && InMemory(expand("%:p")) | silent mkview
au BufWinEnter * if expand("%:p") != "" && InMemory(expand("%:p")) | silent! loadview
au filetype netrw call s:netrw_config()
au filetype qf call s:quickfix_config()
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
set fillchars=fold:\
set fillchars+=vert:│
set foldtext=Blackbox()
let g:lsp_diagnostics_enabled = 0
let g:miniSnip_trigger = '<c-f1>'
let g:miniSnip_complkey = '<c-x><c-f1>'
let g:miniSnip_extends = {
\ 'cpp': ['c'],
\}
function! Blackbox()
let len = 55
let text = getline(v:foldstart)
if len <= strlen(text)
let text = strpart(text, 0, len - 5) . ".."
endif
let cur = line('.')
if v:foldstart <= cur && cur <= v:foldend
let text = '▶ ' . text . repeat(' ', max([1, len - strlen(text)]) - 2) . '█ ' . (v:foldend - v:foldstart + 1) . ' '
else
let text = text . repeat(' ', max([1, len - strlen(text)])) . '│ ' . (v:foldend - v:foldstart + 1) . ' '
endif
return text
endfunction
function! Cleanline()
if g:statusline_winid != win_getid()
let l:hl=''
else
let l:hl='%#Edflag#'
endif
if &modified
let l:editflag='*'
else
let l:editflag='●'
endif
if InMemory(expand("%:p"))
let l:memflag=' '
else
let l:memflag=''
endif
let l:otherstatus='%#StatusLine# %f%r %P %Y '.l:memflag.'~ %S'.'%=|'.&encoding.' %l,%c'
return l:hl.' '.l:editflag.l:otherstatus
endfunction
function! LoadMemory()
let s:memory_file = expand('$HOME').'/.vim/memory'
if filereadable(s:memory_file)
let s:memory = readfile(s:memory_file)
else
let s:memory = []
endif
endfunction
function! InMemory(filename)
return index(s:memory, a:filename) >= 0
endfunction
function! InvMemory()
let l:filename = expand("%:p")
if InMemory(l:filename)
call remove(s:memory, l:filename)
else
call add(s:memory, l:filename)
endif
call writefile(s:memory, s:memory_file)
endfunction
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> K <plug>(lsp-hover)
nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
endfunction
function! s:netrw_config()
map <buffer> \a <nop>
map <buffer> \s <nop>
nmap <buffer> h -zz
nmap <buffer> l zz<CR>
setlocal statusline=\ ●\ %{&ft}
endfunction
function! s:quickfix_config()
map <buffer> \a <nop>
map <buffer> \s <nop>
nmap <buffer> <space> <cr>zz<c-w>p
endfunction
function! OSC52(reg)
let tmp_fn = system("mktemp")[:-2]
let ret = writefile(split(getreg(a:reg), "\n"), tmp_fn, "b")
if ret == 0
exec "!cat ".tmp_fn." |osc52 && rm ".tmp_fn." || echo ".tmp_fn
return
endif
echo ret
endfunction
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
if empty(getqflist())
let new_quickfix = input("", ":grep ")
if new_quickfix != ":grep "
exe new_quickfix
endif
else
copen
endif
else
cclose
endif
endfunction
function! JumpToNormalBuffer(command)
let l:now_buf = bufnr('%')
exec a:command
while &bt != "" && bufnr('%') != l:now_buf
exec a:command
endwhile
endfunction
call LoadMemory()
" python c/c++ rust go java html js lua
if executable('pylsp')
au User lsp_setup call lsp#register_server({
\ 'name': 'pylsp',
\ 'cmd': {server_info->['pylsp']},
\ 'allowlist': ['python'],
\ })
endif
if executable('clangd')
au User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
\ 'cmd': {server_info->['clangd', '--header-insertion=never']},
\ 'allowlist': ['c', 'cpp', 'objc', 'objcpp'],
\ })
endif
if executable('cmake-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'cmake',
\ 'cmd': {server_info->['cmake-language-server']},
\ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'build/'))},
\ 'whitelist': ['cmake'],
\ 'initialization_options': {
\ 'buildDirectory': 'build',
\ }
\})
endif