ubuntu vim自动补齐
时间: 2023-11-07 17:47:32 浏览: 38
在 Ubuntu 系统中使用 vim 编辑器时,可以通过设置自动补齐来提高编辑效率。以下是实现自动补齐的步骤:
1. 安装 vim 插件管理器 Vundle:
```
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
```
2. 在 vim 配置文件 ~/.vimrc 中添加以下内容:
```
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
Plugin 'Valloric/YouCompleteMe'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" YouCompleteMe settings
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_key_invoke_completion = '<c-space>'
let g:ycm_always_populate_location_list = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1
let g:ycm_seed_identifiers_with_syntax = 1
" UltiSnips settings
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
```
以上配置文件中包含了三个插件,其中 YouCompleteMe 提供了自动补齐功能,ultisnips 和 vim-snippets 则提供了代码片段和模板的支持。
3. 安装 YouCompleteMe 插件:
```
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clangd-completer
```
其中,--clangd-completer 参数表示使用 clangd 作为代码补全引擎。如果你使用的是其他编程语言,可以参考官方文档选择合适的补全引擎。
4. 重新打开 vim,输入代码时即可使用自动补齐功能。可以通过 <Tab> 键来触发补全提示,通过 <Enter> 或 <Tab> 键来选择补全项。