# VIM语法&配置
### 懒人配置包
[https://cloud.tencent.com/developer/article/1058322](https://cloud.tencent.com/developer/article/1058322)
### 常用命令
```bash
# aaa"bbb"ccc
vim删除双引号中的内容方法:di" 或da"
●向下复制一行:yy–>p
●选中复制:v–>配合↑↓←→w or b等–>y复制
●其他复制
y 在使用v模式选定了某一块的时候,复制选定块到缓冲区用
yy 复制整行(nyy或者yny ,复制n行,n为数字)
y^ 复制当前到行头的内容
y$ 复制当前到行尾的内容
yw 复制一个word (nyw或者ynw,复制n个word,n为数字)
yG 复制至档尾(nyG或者ynG,复制到第n行,例如1yG或者y1G,复制到档尾)
●撤销:u
```
### 列编辑
```
①删除:ctrl+v–>选择区域–>选择完毕后按d即可全部删除
②插入:ctrl+v–>选择区域–>shift+i(大写i)–>内容–>ESC退出
③替换:ctrl+v–>选择区域–>shift+i(大写i)–>按键c–>内容–>ESC退出
```
**实时搜索、增量搜索、动态搜索**
```bash
:set incsearch
# 冒号 set inc 然后按tab键会自动补全
```
**忽略大小写查找**
```bash
:set ignorecase
```
**设置粘贴时不带注释符号**
```bash
:set paste
```
**显示行号**
```bash
:set number
```
配置永久生效:
```bash
echo -e "set incsearch\nset ignorecase\nset paste\nset number" >> /etc/vimrc
```
---
————————————————
### 插件
**vundle**
> vundle插件管理器,较老
>
[https://github.com/VundleVim/Vundle.vim](https://github.com/VundleVim/Vundle.vim)
**vim-plug**
> 推荐
>
[https://github.com/junegunn/vim-plug](https://github.com/junegunn/vim-plug)
安装方式:
```bash
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
使用配置
编辑~/.vimrc文件
```bash
call plug#begin()
Plug 'tpope/vim-sensible'
"Go development plugin for Vim
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()
```
```bash
注:使用缩写形式指定了插件在github上的地址
Plug 'tpope/vim-sensible'
完整形式
Plug '[https://github.com/tpope/vim-sensible.gi](https://github.com/tpope/vim-sensible.gi)t'
```
---
安装插件
```bash
# vim编辑模式下
:PlugInstall
```
**pathogen**
> recommend
>
[https://github.com/tpope/vim-pathogen](https://github.com/tpope/vim-pathogen)
安装方式
```bash
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
```
#.Auto Pairs(括号匹配神器)
git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs
#.nerdcommenter(代码注释)
git clone https://github.com/preservim/nerdcommenter.git ~/.vim/bundle/nerdcommenter
#.NERDTree(目录树)
git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
1.开启–>NERDTreeToggle
ctrl + w + h 光标 focus 左侧树形目录
ctrl + w + l 光标 focus 右侧文件显示窗口
#.YouCompleteMe
git clone –recursive https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
python3 install.py –go-completer
注:如果提示错误
ERROR: Python headers are missing in /usr/include/python3.6m.
请安装–>centos–>yum install python3-devel
ubuntu–>apt-get install python-dev
---
2.代码补全插件YouCompleteMe(最难装的一款插件)
①克隆代码
git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
②进入YouCompleteMe目录检查依赖
git submodule update –init –recursive
————————————————
1.克隆项目
2.修改/etc/vim/vimrc文件,粘贴官方上的代码
#先下包,后安装
https://www.jianshu.com/p/8d416ac4ad11
---
●Minimalist Vim Plugin Manager
注:zsh 用户需要在 vimrc 中添加 set shell=/bin/sh
vim-plug 插件管理器(主要用于安装代码补全插件coc)
https://github.com/junegunn/vim-plug
1.下载plug插件
curl -fLo ~/.vim/autoload/plug.vim –create-dirs </p>
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
依赖:
①sudo apt install nodejs
②sudo apt install npm
2.添加进添加插件
不建议该方法安装
输入命令 sudo vim /etc/vim/vimrc
填写下方代码
推荐方法
1.新建文件 vim ~/.vimrc
2.粘贴下方代码
————————————–
call plug#begin(‘~/.vim/plugged’)
" coc.nvim 智能补全插件
Plug ‘neoclide/coc.nvim’, {‘branch’: ‘release’}
call plug#end()
————————————–
3.在vim的命令行模式下输入下方命令
:source ~/.vimrc
退出再重新进入即可
相关参考文章:
https://linux.cn/article-9751-1.html
### 其他
解决gvim打开文件乱码问题
打开gvim软件,编辑→启动设置→粘贴代码进配置文件中→保存重启即可
注:
1.文件名为_vimrc
2.无后缀名
3.一般放在用户目录中 C:[username]_vimrc
————————————————
" Gvim中文菜单乱码解决方案
" 设置文件编码格式
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1,gbk,gb18030,gk2312
if has(“win32”)
set fileencoding=chinese
else
set fileencoding=utf-8
endif
" 解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 解决consle提示信息输出乱码
language messages zh_CN.utf-8