vim 插件 入门

摘要:
Vim手册vimtutor紧凑版帮助用户手册详细手册一些Vim内置设置直接在~/Vimrc文件中,可以通过编写以下配置来设置:setnu“显示行号setcursorline”突出显示当前行setcursorcolumn“突出显示当前列sethlsearch”突出显示搜索结果“不同语言的自适应智能缩进filetypeindenton”将选项卡扩展到空白空间setexpandtab“在编辑期间设置选项卡

vim 手册

vimtutor 精简版本
help user-manual 详细手册

一些vim自带设置

直接在~/.vimrc文件上写上如下配置即可

set nu "显示行号
set cursorline "高亮显示当前行
set cursorcolumn "高亮显示当前列
set hlsearch "高亮显示搜索结果

" 自适应不同语言的智能缩进
filetype indent on
" 将制表符扩展为空格
set expandtab
" 设置编辑时制表符占用空格数
set tabstop=4
" 设置格式化时制表符占用空格数
set shiftwidth=4
" 让 vim 把连续数量的空格视为一个制表符
set softtabstop=4

Manjaro下让vim支持clipboard

使用命令vim --version | grep "clipboard"来查看是否支持clipboard,如若看到-clipboard就是不支持,如果看到+clipboard就是支持。
如果是不支持那就使用sudo pacman -S gvim安装gui版本的vim。
复制到系统剪切板的命令是:"+y注意那个加号是真的要输入的+, 粘贴系统剪贴板的命令是shift insert或者ctrl shift v

Windows下让vim支持clipboard

我是使用MSYS2安装的vim:pacman -S vim,安装后vim --version | grep "clipboard"发现直接能看到+clipboard
MSYS2的使用参考另外的文章:https://www.cnblogs.com/feipeng8848/p/10038421.html

Ubuntu

sudo apt install vim-gtk

插件管理 vim-plugin

下载下面的文件:
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
并将文件放在 windows 中的 ~/vimfiles/autoload 或 unix 中的 ~/.vim/autoload 文件夹内
https://www.v2ex.com/t/532549
安装插件
安装插件,只需要将插件写在 .vimrc 内,然后在 vim 中使用 :PlugInstall 命令即可:

call plug#begin('~/.vim/plugged')
Plug 'vim-airline/vim-airline'
call plug#end()

确保插件要放在 begin 和 end 之间
重新打开 vim 使用命令 :PlugInstall
Finishing ... Done! 表示安装完成

plug-vim的github页面有很多插件的例子可以参考

删除插件
删除插件,只需要将写在 .vimrc 配置文件内的插件删除,重启 vim 并执行命令 :PlugClean 即可:
call plug#begin('~/.vim/plugged')
call plug#end()
保存在 vim 中使用 :PlugClean:

设置代码高亮

打开~/.vimrc文件追加一行syntax on 这是默认的vim代码高亮设置,插件的后面再说。

nerdtree插件

用于列出目录树,效果如下图
vim 插件 入门第1张
github 链接:https://github.com/scrooloose/nerdtree
安装:打开~/.vimrc 添加如下命令

call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
call plug#end()

然后打开vim输入PluginInstall

配置nerdtree

以下翻译自github帮助文档,直接在~/.vimrc文件中写入配置就行
1、在vim启动时自动打开NERDTree

autocmd vimenter * NERDTree

2、如果没有指定文件,如何在vim启动时自动打开NERDTree?

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

3、如何映射特定键或快捷方式以打开NERDTree?
下面的配置使用control n切换是否打开nerdtree

map <C-n> :NERDTreeToggle<CR>

更多配置可参考github DOC目录下的教程
另外一些常用快捷键

ctrl + w + h 光标 focus 左侧树形目录
ctrl + w + l 光标 focus 右侧文件显示窗口
ctrl + w + w 光标自动在左右侧窗口切换
ctrl + w + r 移动当前窗口的布局位置

我的配置

" NERD tree
let NERDChristmasTree=0
let NERDTreeWinSize=35
let NERDTreeChDirMode=2
let NERDTreeIgnore=['~$', '.pyc$', '.swp$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos="left"
" 打开vim自动打开nerdtree
autocmd vimenter * NERDTree
" Automatically open a NERDTree if no files where specified
autocmd vimenter * if !argc() | NERDTree | endif
" 自动关闭nerdtree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"open NERDTree automatically when vim starts up on opening a directory
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
" Open a NERDTree
map <C-n> :NERDTreeToggle<CR>

Molokai 配色方案

下载文件https://github.com/tomasr/molokai,colors放置到.vim文件夹下
.vimrc文件添加:

Plugin 'tomasr/molokai'

编辑.vimrc文件,增加以下配置

"molokai配色方案
colorscheme molokai
let g:molokai_original = 1
set t_Co=256
set background=dark

Vim Powerline

一个显示vim状态栏插件,它能够显示vim模式、操作环境、编码格式、行数/列数等信息。
https://github.com/powerline/powerline

Plugin 'Lokaltog/vim-powerline'

代码缩进树

https://github.com/nathanaelkane/vim-indent-guides

Plugin 'nathanaelkane/vim-indent-guides'

然后进vim PluginInstall

在.vimrc中做一些设置

" 随 vim 自启动
let g:indent_guides_enable_on_vim_startup=1
" 从第二层开始可视化显示缩进
let g:indent_guides_start_level=2
" 色块宽度
let g:indent_guides_guide_size=1
" 快捷键 i 开/关缩进可视化
:nmap <silent> <Leader>i <Plug>IndentGuidesToggle

代码补全

https://github.com/ycm-core/YouCompleteMe

Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }

在plug-vim中安装之后,插件会出现在 ~/.vim/plugged目录下
编译需要

sudo apt install build-essential cmake python3-dev

然后去编译即可

cd ~/.vim/plugged/YouCompleteMe
python3 install.py --clang-completer

YCM还提供以下附加语言支持选项:(机翻自github 的 readme.md)
C#支持:安装Mono( https://www.mono-project.com/download/stable/#download-lin )并在调用install.py的时候添加--cs-completer 。
去支持:安装Go并--go-completer在调用时 添加install.py。
JavaScript和TypeScript支持:安装Node.js和npm并--ts-completer在调用时添加install.py。
Rust支持:--rust-completer在调用时添加install.py。
如果你的Python解释器比2.7.9老,您还需要 rustup你PATH。
Java支持:安装JDK8(需要版本8)并--java-completer在调用时添加 install.py。
要简单地编译启用的所有内容,就会有一个--all标志。请注意,这个标志也没有安装clangd。您需要通过添加手动指定它--clangd-completer。
因此,安装了所有的语言特性,保证 xbuild,go,tsserver,node,npm和安装工具和你PATH,然后只需运行:

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

编译过程中遇到了一些问题找不到文件等。后发现那个目录缺少文件,删除那个目录然后重新执行git submodule update --init --recursive 后解决
错误信息

CMake Error: The source directory "/home/kun/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/cregex" does not appear to contain CMakeLists.txt. 
Specify --help for usage, or press the help button on the CMake GUI. 
ERROR: the build failed.                                                                                                                                        NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the issue tracker, including the entire output of this script
and the invocation line used to run it. 

解决:
vim 插件 入门第2张
然后再执行python3 install.py --all编译就好了
此时,YCM应该是可以做一些简单的代码补全了,但是,还没有那么好用,比如我装的C#,system.之后没有任何提示。
接下来就是配置了,配置完才好用。

对于c家族语言

用ycm自带的.ycm_extra_conf.py文件.

cp third_party/ycmd/examples/.ycm_extra_conf.py ~/

配置.vimrc文件

let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'

vim 插件 入门第3张

其他

https://github.com/Lokaltog/vim-powerline 已经不再维护,有新版本,但是需要安装很多东西,Python啥的。
这里用老版本就是上面的链接,在 .vimrc中添加Plugin 'Lokaltog/vim-powerline'后在vim中执行PluginInstall就可以了

vim使用系统的粘贴板

https://www.cnblogs.com/jpfss/p/9040561.html

参考

https://github.com/yangyangwithgnu/use_vim_as_ide
https://saul-mirone.github.io/2017/06/20/vim-config/
http://yuez.me/cong-ling-da-jian-he-pei-zhi-osxkai-fa-huan-jing/
http://yuez.me/jiang-ni-de-vim-da-zao-cheng-qing-qiao-qiang-da-de-ide/
https://blog.csdn.net/zhangpower1993/article/details/52184581
http://www.wklken.me/posts/2015/06/07/vim-plugin-tagbar.html
YouCompleteMe https://vimjc.com/vim-youcompleteme-install.html
YouCompleteMe https://www.jianshu.com/p/d908ce81017a?nomobile=yes
关于vundle : https://zhuanlan.zhihu.com/p/54078065

免责声明:文章转载自《vim 插件 入门》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ssh密钥登录多页应用 Webpack4 配置优化与踩坑记录下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Sublime Text 3 插件安装及Vim 模式设置

1、安装Sublime Text 3 下载安装:http://www.sublimetext.com/3 Package Control安装:https://sublime.wbond.net/installation 2、如何安装插件 在第1步中安装好后 按 Ctrl+Shift+P ,输入insta 在下拉菜单选择 Install Package 按回...

打造一款高逼格的Vim神器

点击上方“开源Linux”,选择“设为星标” 回复“学习”获取独家整理的学习资料! 作者:枫上雾棋 链接:https://segmentfault.com/a/1190000011466454 Vim 是一个上古神器,本篇文章主要持续总结使用 Vim 的过程中不得不了解的一些指令和注意事项,以及持续分享一个前端工作者不得不安装的一些插件,而关于 Vi...

cscope的用法

一,一般源文件中生成索引文件 为了方便使用,编写了下面的脚本来更新cscope和ctags的索引文件: #!/bin/shfind . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.filescscope -bkq -i cscope.filesctags -R 这个命令会生成三个文件:c...

Yapi部署

官方文档:https://hellosean1025.github.io/yapi/devops/index.html#%E5%AE%89%E8%A3%85 一:本地开发(可视化部署) npm install -g yapi-cli --registry https://registry.npm.taobao.org # 报错的话需要加上sudo yap...

Linux设置禁止用户登陆

Linux设置禁止用户登陆 vim /etc/shadow 第二栏(密码栏)设为*,会丢失密码 usermod -L username # -L Lock; -U Unlock chsh username -s /sbin/nologin 或直接改文件vim /etc/passwd修改mysql:mysql❌501:501::/mnt/mysql:/sb...

2020系统综合实践 第7次实践作业 11组

目录 1.在树莓派中安装opencv库 1.1 安装依赖 1.2 下载OpenCV源码 1.3 安装pip 1.4 安装Python虚拟机 1.5 编译OpenCV 1.6 安装OpenCV 2.使用opencv和python控制树莓派的摄像头 3.利用树莓派的摄像头实现人脸识别 facerec_on_raspberry_pi.py face...