Rust文件中Vim自动补全插入错误左大括号问题排查求助
Rust文件中Vim自动补全插入错误左大括号问题排查求助
各位Vim同好们,最近写Rust代码的时候碰到个闹心的小问题:自动补全时总是会插入格式错误的左大括号——要么位置跑偏,要么平白无故多出来一个,严重拖慢写代码的节奏。我把自己的.vimrc完整配置贴在下面,麻烦大伙帮我瞅一眼,到底哪块配置可能出问题了?
set runtimepath^=~/.config/vim " Visual mode select and move laterally using < and > sign vnoremap < <gv vnoremap > >gv " Centre align search and n & N nnoremap <silent> n nzzzv nnoremap <silent> N Nzzzv set hlsearch " Highlight all matches of the search set incsearch " Show matches as you type nnoremap <silent> <Esc> :nohlsearch<CR> " Disable visual bell and turn off error beeping set visualbell t_vb= " Python path let g:python3_host_prog = '~/.config/miniconda3/bin/python' " Don't show extra line set noshowmode " Enable true color support set termguicolors " Set 24-bit RGB colors for terminal foreground and background let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" " Set leader key to space let mapleader = " " " Use 'Tab' to select the current item in the completion menu (Ctrl-y) inoremap <expr> <Tab> pumvisible() ? "\<C-y>" : "\<Tab>" " File and buffer shortcuts nnoremap <Leader>ff :call fzf#run(fzf#wrap({'source': 'rg --files --hidden --glob "!.git/*" --glob "!node_modules/*" --glob "!__pycache__/*" --glob "!target/*" --glob "!tmp/*"', 'options': '--preview "bat --color always {}"'}))<CR> nnoremap <Leader>fg :RG <CR> nnoremap <Leader>rg :Rg <CR> nnoremap <Leader>bf :Buffers<CR> noremap <leader>bd :bd<CR> noremap <leader>bu :bd!<CR> noremap <leader>bc :close<CR> nnoremap <leader>q :BufOnly<CR> nnoremap <Leader>h :History<CR> nnoremap <Leader>c :Commands<CR> " NERDTree configuration let NERDTreeIgnore = ['\.pyc$', '\~$', '^node_modules$', '^__pycache__$', '^target$', '^\.git$', '^tmp$'] augroup NERDTreeAutoResize autocmd! autocmd FileType nerdtree call ResizeNERDTreeToHalf() augroup END function! ResizeNERDTreeToHalf() let l:half_width = float2nr(&columns * 4 / 5) execute "vertical resize " . l:half_width endfunction let g:NERDTreeWinPos = "right" nnoremap <leader>e :call ToggleNERDTreePosition()<CR> function! ToggleNERDTreePosition() if exists("t:NERDTreeBufName") NERDTreeClose endif if g:NERDTreeWinPos ==# 'left' let g:NERDTreeWinPos = 'right' else let g:NERDTreeWinPos = 'left' endif NERDTreeToggle echo "NERDTree position set to " . g:NERDTreeWinPos endfunction nnoremap - :NERDTreeToggle<CR> nnoremap <leader>x :q<CR> nnoremap <leader>n :enew<CR> nnoremap <leader>u :UndotreeToggle<CR> " Map leader + tc to open the Colors menu nnoremap <leader>th :call OpenColorsMenu()<CR> " Map leader + ts to save the selected colorscheme nnoremap <leader>ts :call SaveColorscheme()<CR> " Map Ctrl + ` to toggle background nnoremap <leader>tg :call ToggleBackground()<CR> " Terminal shortcuts for opening a floating terminal and lazygit nnoremap <silent> <leader>te :FloatermNew --autoclose=2<CR> nnoremap <silent> <leader>gg :FloatermNew --autoclose=2 --width=0.8 --height=0.8 lazygit<CR> " Save buffer and switch to the next/previous one using Tab nnoremap <silent> <tab> :if &modifiable && !&readonly && &modified <CR> :write<CR> :endif<CR>:bnext<CR> nnoremap <silent> <s-tab> :if &modifiable && !&readonly && &modified <CR> :write<CR> :endif<CR>:bprevious<CR> " Toggle ZoomWinTab nnoremap <leader>z :ZoomWinTabToggle<CR> " Replace current word nnoremap <leader>rp :Replace <C-r>=expand("<cword>")<CR><Space> nmap <leader>rn <Plug>(coc-rename) " 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>rv <Plug>(coc-codeaction-refactor-selected) nmap <silent> <leader>rv <Plug>(coc-codeaction-refactor-selected) " Run the Code Lens action on the current line nmap <leader>cl <Plug>(coc-codelens-action)
我自己先琢磨了几个可能的点,但拿不准:
- 我用Coc做补全,配置里有不少Coc的映射,会不会是rust-analyzer的默认配置有坑?毕竟我没在.vimrc里写Coc的具体Rust补全规则。
- 那个Tab键的补全映射:
inoremap <expr> <Tab> pumvisible() ? "\<C-y>" : "\<Tab>",当补全菜单出来时按Tab直接选当前项,会不会是这个导致补全时没正确展开括号的结构? - 有没有可能是Rust语法相关的隐性配置和补全插件冲突了?不过我.vimrc里没单独装语法插件,应该是Coc自带的。
有没有大佬碰到过类似情况,或者从我的配置里看出问题了?麻烦给指条明路,谢谢啦!
内容来源于stack exchange
相关产品推荐
相关产品推荐

