vim配置
vim 插件配置
1. 安装插件
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
2.配置插件(~/.vimrc)
" vim plugin
call plug#begin('~/.vim/plugged')
"Plug 'morhetz/gruvbox'
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'Yggdroot/LeaderF'
Plug 'ycm-core/YouCompleteMe'
Plug 'easymotion/vim-easymotion'
Plug 'Chiel92/vim-autoformat'
Plug 'mhinz/vim-signify'
Plug 'skywind3000/asyncrun.vim'
Plug 'junegunn/vim-easy-align'
call plug#end()
" for leader shotcut
let mapleader = ";"
nnoremap <Leader>q :q<CR>
nnoremap <Leader>w :w<CR>
nnoremap <Leader>g :NERDTreeToggle<CR>
nnoremap <Leader>f :NERDTreeFind<CR>
set clipboard=unnamedplus " 使用系统剪切板-> vim
set clipboard=unnamed " vim -> 系统剪切版
autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
set ruler " 显示标尺
" set laststatus=2 " 开启状态行,但是目前无效
" set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
set autoread " 文件改动实时显示
set autowrite " 文件自动保存
filetype on " 打开文件类型检测
filetype plugin on " 载入文件类型插件
set backspace=2 " 使回格键(backspace)正常处理indent, eol, start等
set completeopt=longest,menu " 打开文件类型检测, 加了这句才可以用智能补全
set tags=./.tags;,.tags " ctag 使用开关
" morhetz/gruvbox插件
" colorscheme gruvbox
" ycm-core/YouCompleteMe插件配置
let g:ycm_python_binary_path = '~/.local/python3/bin/python3'
" C family Completion Path
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
" 跳转快捷键
let g:ycm_disable_for_files_larger_than_kb=100000
nnoremap <c-k> :YcmCompleter GoToDeclaration<CR>|
nnoremap <c-h> :YcmCompleter GoToDefinition<CR>|
nnoremap <c-j> :YcmCompleter GoToDefinitionElseDeclaration<CR>|
" 停止提示是否载入本地ycm_extra_conf文件
let g:ycm_confirm_extra_conf = 0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files = 1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 添加C++11支持
let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libc++'
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1
" 弹出列表时选择第1项的快捷键(默认为<TAB>和<Down>)
"let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
" 弹出列表时选择前1项的快捷键(默认为<S-TAB>和<UP>)
"let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
" 主动补全, 默认为<C-Space>
"let g:ycm_key_invoke_completion = ['<C-Space>']
" 停止显示补全列表(防止列表影响视野), 可以按<C-Space>重新弹出
"let g:ycm_key_list_stop_completion = ['<C-y>']
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl':['re!\w{2}'],
\ 'cs,lua,javascript':['re!\w{2}'],
\}
"ycm默认需要按ctrl + space 来进行补全,可以在上面的花括号里面加入下面两行代码来直接进行补全[不需要按键]
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_log_level = 'error'
"disable ycm 语法检查
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 0
" NERDTree 插件设置
" 文件树设置 {{{
" 关闭NERDTree快捷键
" map <leader>t :NERDTreeToggle<CR>
""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
""修改树的显示图标
let g:NERDTreeDirArrowExpandable = '►'
let g:NERDTreeDirArrowCollapsible = '▼'
let NERDTreeAutoCenter=1
" 显示行号
let NERDTreeShowLineNumbers=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
let NERDTreeWinSize=28
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略一下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
" }}}
" Yggdroot/LeaderF 插件配置
let g:Lf_Ctags = '~/.local/ctags/bin/ctags'
let g:Lf_ShortcutF = '<c-p>'
let g:Lf_UseCache = 0
noremap <c-n> :LeaderfMru<cr>
noremap <leader>f :LeaderfFunction!<cr>
noremap <leader>b :LeaderfBuffer<cr>
noremap <leader>v :LeaderfBufTag<cr>
noremap <C-F> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR>
noremap <C-B> :<C-U><C-R>=printf("Leaderf! rg -F --current-buffer -e %s ", expand("<cword>"))<CR>
noremap go :<c-U>Leaderf! rg --recall<CR>
let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' }
let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git']
let g:Lf_WorkingDirectoryMode = 'Ac'
let g:Lf_WindowHeight = 0.30
let g:Lf_CacheDirectory = expand('~/.vim/cache')
let g:Lf_ShowRelativePath = 0
let g:Lf_HideHelp = 1
let g:Lf_StlColorscheme = 'powerline'
let g:Lf_PreviewResult = {'Function':0, 'BufTag':0}
let g:ycm_filetype_whitelist = {
\ "c":1,
\ "cpp":1,
\ "python":1,
\ "sh":1
\ }
3.安装插件
完成配置后,保存文件并重新启动 Vim。之后,在 Vim 的命令模式下输入
:PlugInstall
就应该可以正常安装插件了。
4.正常使用
配置插件ycm
安装python>3.8
下载
wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz
编译安装
tar -zxf Python-3.10.10.tgz
# vim依赖python3的动态库,所以必需要--enable-shared
cd Python-3.10.10 && ./configure --enable-shared
make && sudo make install
更新库
# 更新系统的动态链接器缓存,使其能够找到Python库文件
sudo ldconfig
如果Python库文件不在系统默认的库文件路径中,你可以手动将库文件路径添加到`LD_LIBRARY_PATH`环境变量中
export LD_LIBRARY_PATH=/usr/local/lib/python3.10 # 将路径替换为你的Python库文件所在路径
pip3 install PyHamcrest
pip3 install flake8
安装vim > 8.3
下载
git clone https://github.com/vim/vim.git
编译安装
cd vim
LDFLAGS="-rdynamic" ./configure --with-features=huge --enable-python3interp
make && sudo make install
set 配置
:set number " 显示行号
:set nonumber " 关闭行号
:set tabstop=4 " 设置 tab space 为4个空格
:set ts=4 " 同 tabstop
:set expandtab " 将tab替换为指定数量的空格
:set autoindent " 设置为自动缩进
:set background=dark " 设置背景颜色
:set guifont=consolas:h14 " 设置字体为 consolas,字号为14
:set history=700 " 设置保存命令的行数
:set autoread " 设置当文件变化时,自动读取新文件
:set wrap " 启动折行
:set nowrap " 禁止折行
" 切换文件格式,ff是 fileformat 的缩写
:set ff=unix " 将文件切换为 unix 格式,每行以 "\n" 结尾
:set ff=dos " 切换为 Windows 格式,每行以 "\r\n" 结尾
" 设置编码格式
:set encoding=utf-8 " 设置 vim 展示文本时的编码格式
:set fileencoding=utf-8 " 设置 vim 写入文件时的编码格式
:set filetype=html " 设定文件类型,方便语法高亮
:set hlsearch " 高亮显示搜索结果
:set paste " 设置为 paste 模式,在粘贴前设置该模式,可以避免各种 auto-formating
:set nopaste " 切换回 normal 模式
:set noai "无缩进模式"