vim 插件 入門


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插件

用於列出目錄樹,效果如下圖

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. 

解決:

然后再執行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'

其他

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM