Repository navigation
Expand file tree
/
Copy pathvimrc
More file actions
115 lines (99 loc) · 3.43 KB
/
Copy pathvimrc
File metadata and controls
115 lines (99 loc) · 3.43 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
" Basic Vim 9 Configuration
set nocompatible
" Enable line numbers
set number
" Enable syntax highlighting
syntax on
" Enable file type detection, plugins, and indentation
filetype plugin indent on
" Use 4 spaces for tabs (common for Python, C, C++, Shell)
set expandtab
set shiftwidth=4
set softtabstop=4
" Enable auto-indentation
set autoindent
set smartindent
" Highlight the current line
set cursorline
" Case insensitive search unless pattern contains uppercase
set ignorecase
set smartcase
" Enable mouse support
set mouse=a
" Better command-line completion
set wildmenu
" Do not fold by default
set foldlevelstart=99
" Markdown-specific: Enable basic folding
let g:markdown_folding = 1
let g:markdown_fold_style = 'nested'
" Rust-specific configuration (rust.vim)
let g:rustfmt_autosave = 1
let g:rustfmt_fail_silently = 0
let g:rust_fold = 1
" LSP configuration (yegappan/lsp)
"
" clangd takes its flags from a project's compile_commands.json. Without one it
" falls back to a bare `clang <file>`, which on Fedora means C++17 (clang's
" default) even though this machine's gcc defaults to C++20 -- so C++20 code
" that Bazel builds fine still lights up red -- and means no -I paths at all,
" so any third-party header (gtest, Eigen, CLI11) reads as "file not found".
"
" Generate that file for a Bazel workspace with :BazelCompDB below. The
" C++17-vs-C++20 fallback for files no build system knows about is pinned in
" ~/.config/clangd/config.yaml.
let g:lsp_servers = [#{
\ name: 'rust-analyzer',
\ filetype: ['rust'],
\ path: 'rust-analyzer',
\ args: [],
\ syncInit: v:true
\ }, #{
\ name: 'clangd',
\ filetype: ['c', 'cpp'],
\ path: 'clangd',
\ args: [
\ '--background-index',
\ '--clang-tidy',
\ '--completion-style=detailed',
\ '--header-insertion=never',
\ '--pch-storage=memory',
\ '-j=4',
\ '--query-driver=/usr/bin/gcc,/usr/bin/g++'
\ ],
\ rootSearch: ['compile_commands.json', 'MODULE.bazel', 'WORKSPACE',
\ 'WORKSPACE.bazel', 'compile_flags.txt', '.git/'],
\ syncInit: v:true
\ }]
let g:lsp_options = #{
\ autoComplete: v:true,
\ autoHighlightDiags: v:true,
\ showDiagWithSign: v:true,
\ showInlayHints: v:true,
\ showSignature: v:true
\ }
" LSP key mappings
nnoremap <silent> gd <cmd>LspGotoDefinition<CR>
nnoremap <silent> K <cmd>LspHover<CR>
nnoremap <silent> gr <cmd>LspShowReferences<CR>
nnoremap <silent> <leader>rn <cmd>LspRename<CR>
nnoremap <silent> <leader>ca <cmd>LspCodeAction<CR>
nnoremap <silent> [d <cmd>LspDiag prev<CR>
nnoremap <silent> ]d <cmd>LspDiag next<CR>
" Regenerate compile_commands.json for the Bazel workspace containing the
" current file, then restart clangd so it picks the new flags up. Re-run after
" adding a BUILD target, a new source file, or a new external dependency.
command! -nargs=* BazelCompDB call s:BazelCompDB(<q-args>)
function! s:BazelCompDB(args) abort
let l:dir = expand('%:p:h')
if l:dir ==# '' | let l:dir = getcwd() | endif
echo 'Running bazel-compdb (this can take a moment)...'
let l:out = system('cd ' .. shellescape(l:dir) .. ' && bazel-compdb ' .. a:args .. ' 2>&1')
if v:shell_error
echohl ErrorMsg | echom 'bazel-compdb failed:' | echohl None
for l:line in split(l:out, '\n') | echom l:line | endfor
else
echom substitute(split(l:out, '\n')[-1], '^\s*', '', '')
LspServer restart
endif
endfunction