ubuntu vim自动补齐
时间: 2023-10-25 14:29:55 浏览: 92
在 Ubuntu 上使用 Vim 编辑器时,可以通过以下步骤启用自动补齐功能:
1. 安装 Vim 插件管理器 Vundle:
```bash
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
```
2. 在 `~/.vimrc` 文件中添加以下内容:
```vim
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'Valloric/YouCompleteMe'
call vundle#end() " required
filetype plugin indent on " required
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion=2
let g:ycm_collect_identifiers_from_comments_and_strings=1
let g:ycm_complete_in_strings=1
let g:ycm_complete_in_comments=1
let g:ycm_key_invoke_completion='<C-Space>'
let g:ycm_confirm_extra_conf=0
let g:ycm_add_preview_to_completeopt=1
let g:ycm_show_diagnostics_ui=1
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_python_binary_path='/usr/bin/python3'
let g:ycm_server_python_interpreter='/usr/bin/python3'
let g:ycm_server_keep_logfiles=0
let g:ycm_server_log_level=3
```
3. 打开 Vim 并执行以下命令安装插件:
```
:PluginInstall
```
4. 安装 YCM(YouCompleteMe)插件的依赖项:
```bash
sudo apt install build-essential cmake python3-dev
```
5. 在 `~/.vim/bundle/YouCompleteMe/` 目录下执行以下命令安装 YCM 插件:
```bash
python3 install.py --clang-completer
```
安装完成后,重新打开 Vim,输入任意单词并按下 `Ctrl + Space` 键即可触发自动补齐功能。如果需要更改自动补齐的选项,可以修改 `~/.vimrc` 文件中的配置。
阅读全文