-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
executable file
·383 lines (328 loc) · 13 KB
/
Copy path.vimrc
File metadata and controls
executable file
·383 lines (328 loc) · 13 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
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
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'vim-scripts/taglist.vim'
Plug 'joe-skb7/cscope-maps'
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Plug 'dense-analysis/ale'
Plug 'ggml-org/llama.vim', { 'for': ['c', 'cpp', 'h', 'hpp', 'python', 'javascript', 'typescript', 'rust', 'go', 'lua', 'json'] }
call plug#end()
let g:llama_config = {
\ 'keymap_fim_trigger': '<C-g>',
\ 'keymap_fim_accept_full': '<C-a>',
\ 'keymap_fim_accept_line': '<C-d>',
\ 'endpoint_fim': 'http://192.168.2.166:8000/infill',
\ 'endpoint_inst': 'http://192.168.2.166:8000/v1/chat/completions',
\ }
let g:llama_config.model_fim = 'qwen25-coder'
"let g:llama_config.model_fim = 'qwen35-nt'
let g:llama_config.auto_fim = v:false
"Map Ctrl+G to trigger llama suggestion
autocmd VimEnter * inoremap <C-g> <cmd>call llama#suggest()<CR>
" NERDTree related
nnoremap <C-n> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" YouCompleteMe
let g:ycm_auto_trigger = 1
syn on " Syntax highlighting on
if has("unix")
colorscheme desert
endif
"filetype plugin on
"filetype indent on
filetype plugin indent on
autocmd FileType markdown setlocal nocindent
autocmd FileType markdown let g:ollama_enabled = 0
autocmd FileType markdown CocDisable
autocmd FileType text setlocal nocindent
autocmd FileType latex setlocal nocindent
autocmd FileType asciidoc setlocal nocindent noautoindent nosmartindent
autocmd FileType asciidoc setlocal fo=want
" autocmd FileType asciidoc hi clear ExtraWhitespace
augroup override_ft
au!
au BufRead,BufNewFile *.c.inc set filetype=c
augroup END
if version >= 700
set omnifunc=syntaxcomplete#Complete
set completeopt=menuone,menu,longest
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
highlight clear
highlight Pmenu ctermfg=0 ctermbg=2
highlight PmenuSel ctermfg=0 ctermbg=7
highlight PmenuSbar ctermfg=7 ctermbg=0
highlight PmenuThumb ctermfg=0 ctermbg=7
end
if has("gui_running")
if has("macunix")
set guifont=Monaco:h14 " use this font
set lines=70 " height = 50 lines
set columns=90 " width = 100 columns
elseif has("unix")
set guifont=Lucida\ Console:h10 " use this font
set lines=70 " height = 50 lines
set columns=90 " width = 100 columns
endif
endif
set tw=90
set mouse=a
" Tab and indent options =======================================================
set number
set relativenumber
set tabstop=4 " Tab is 4 spaces and NOT the default 8
set shiftwidth=4 " numbers of spaces to (auto)indent
set expandtab " Expand tab to spaces
set cindent " cindent
set smartindent " smart indent
set autoindent " always set autoindenting on
set softtabstop=4 " makes the spaces feel like real tabs. E.g. back deletes all 4 chars
set backspace=indent,eol,start " backspace deletes indent, eol and start lineset hlsearch
set cinoptions=l1
nnoremap H gT
nnoremap L gt
set fo+=mM
" Display options ===============================================================
set cursorline
" hi CursorLine cterm=NONE ctermbg=black guibg=black
set ruler
if exists('+autochdir')
set autochdir
else
autocmd BufEnter * silent! lcd %:p:h:gs/ /\ /
endif
set langmenu=none
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
match ExtraWhitespace /\s\+$/
" Tags related ==================================================================
"let Tlist_Ctags_Cmd = "ctags.exe"
set tags=./tags,tags
set tags+=~/.vim/tags/c
"set tags+=~/.vim/tags/c++
set grepprg=grep\ -nH\ $*
let g:ale_linters = {'rust': ['analyzer']}
let g:ale_linters_explicit = 1
augroup filetype_rust
if tagfiles() == []
au!
au BufRead,BufNewFile *.rs nnoremap K :ALEHover<CR>
au BufRead,BufNewFile *.rs nnoremap <C-]> :ALEGoToDefinition<CR>
endif
augroup END
let g:tex_flavor = "pdftex"
let g:Tex_DefaultTargetFormat = "pdf"
let g:Tex_MultipleCompileFormats="pdf,bib,pdf"
let g:Tex_GotoError = 0
let g:Tex_ShowErrorContext = 0
let g:tex_comment_nospell = 1
if has("macunix")
let g:Tex_TreatMacViewersAsUNIX = 1
let g:Tex_ExecuteUNIXViewerInForeground = 1
let g:Tex_ViewRule_ps = 'open -a Skim'
let g:Tex_ViewRule_pdf = 'open -a /Applications/Skim.app'
let g:Tex_ViewRule_dvi = 'open -a /Applications/Skim.app'
elseif has("unix")
let g:Tex_ViewRule_pdf = "okular"
endif
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
let php_sql_query = 1
let php_htmlInStrings = 1
" File operations ===============================================================
set hidden
set confirm
set nobackup
set hidden
" Search options ================================================================
set incsearch
set hlsearch
" Keymaps =======================================================================
nnoremap <c-l> <c-l>:noh<return>
nnoremap <F12> :TlistToggle<return>
"inoremap ( ()i
"inoremap " ""i
"inoremap ¡® "i
"inoremap [ []i
"inoremap { {}i
" for php:
"imap vv $
"imap .. ->
" Autocmd for different behavior based on filetype==============================
autocmd FileType tex set spell nocindent nosmartindent noautoindent nocursorline tw=90
" Disable logging of the JS indent plugin
let g:js_indent_log = 0
function! LoadCscope()
let db = findfile("cscope.out", ".;")
if (!empty(db))
let path = strpart(db, 0, match(db, "/cscope.out$"))
set nocscopeverbose " suppress 'duplicate connection' error
exe "cs add " . db . " " . path
set cscopeverbose
set cscopetag
set cst
set csto=0
endif
endfunction
au BufEnter /* call LoadCscope()
function! UpdateTags()
execute ":!ctags -R --languages=C,C++ --c++-kinds=+p --fields=+iaS --extra=+q ./"
echohl StatusLine | echo "C/C++ tag updated" | echohl None
endfunction
nnoremap <F4> :call UpdateTags()
set csre
" Aligns backslash characters at the end of lines.
" Useful when writing multiline macros or multiline strings.
function AlignBackslash()
:silent! s@\s\+\\$@ \\@
:silent! s/s*\\$/\=repeat(' ', 80-col('.')).'\'
:let @/ = ""
endfunction
function RemoveDuplicateBackslash()
:silent! s/\\\\$/\\/g
endfunction
" In normal mode align the whole file.
nmap \\ mxggVG:call RemoveDuplicateBackslash()<cr>ggVG:call AlignBackslash()<cr>'x
" In visual select mode align selected lines.
vmap \\ :call RemoveDuplicateBackslash()<cr>gv:call AlignBackslash()<cr>
" Insert backslash at the end of current line and align it
nmap <c-\> A\<esc>:call AlignBackslash()<cr>
" Insert backslash at the end of selected lines and align them
vmap <c-\> :norm A\<esc>gv:call AlignBackslash()<cr>
" When opening any C/C++ file under ~/code, add its project's include dir
autocmd BufRead,BufNewFile *.c,*.h,*.cpp,*.hpp call s:SetProjectPath()
function! s:SetProjectPath() abort
" Get directory of current file and its parent (project root)
let l:dir = expand('%:p:h')
let l:root = fnamemodify(l:dir, ':h')
" Assume include directory is at <root>/include
let l:inc = l:root . '/include'
if isdirectory(l:inc)
execute 'setlocal path+=' . fnameescape(l:inc)
endif
endfunction
set nowritebackup
" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
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>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent><nowait> [g <Plug>(coc-diagnostic-prev)
nmap <silent><nowait> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation
nmap <silent><nowait> gd <Plug>(coc-definition)
nmap <silent><nowait> gy <Plug>(coc-type-definition)
nmap <silent><nowait> gi <Plug>(coc-implementation)
nmap <silent><nowait> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming
" nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s)
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
augroup end
" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying code actions at the cursor position
nmap <leader>ac <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>as <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf <Plug>(coc-fix-current)
" Remap keys for applying refactor code actions
" nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
" xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
" nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
" Run the Code Lens action on the current line
nmap <leader>cl <Plug>(coc-codelens-action)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')
" Add `:Fold` command to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>