IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> vim安装bundle和使用 -> 正文阅读

[开发工具]vim安装bundle和使用

一、准备工作

安装Git(因为下面我们选择的插件管理器需要使用到它)
安装其他插件前首先需要选择一个Vim插件管理器,我这里选择的是Vundle,Vundle的工作过程中需要通过Git自动从远程创库同步插件安装包到本地仓库(Vundle的默认本地仓库位置是~/.vim/bundle/) 通过Git下载Vundle安装包:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

安装好后,如果需要安装新插件。进入vim:
PluginInstall

.vim 在~/.vimrc中添加Vundle的配置内容:

set nocompatible              " be iMproved, required
filetype on                  " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Avoid a name conflict with L9
" Plugin 'user/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList          - list configured plugins
" :PluginInstall(!)    - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!)      - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

View Code 有两种方式安装新插件,通过命令行参数的方式如:
$ vim +PluginInstall +qall
或者直接运行:$vim,然后按:PluginInstall进入命令模式,直到左下方状态栏出现Done!

提示说明插件安装成功,退出再进入就可以使用我们在~/.vimrc中配置的插件了 安装ctags软件:
$ sudo apt-get install ctags

二、常用插件的安装和使用

2.1 ctags和taglist

taglist是一个用于显示定位程序中各种符号的插件,例如宏定义、变量名、结构名、函数名这些东西 我们将其称之为符号(symbols),而在taglist中将其称之为tag。
显然,要想将程序文件中的tag显示出来,需要事先了解全部tag的信 息,并将其保存在一个文件中,然后去解析对应的tag文件。
taglist做的仅仅是将tag文件中的内容解析完后显示在Vim上而已。
tag扫描以及数 据文件的生成则是由ctags(Exuberant Ctags)这一工具完成的,所以在使用taglist之前,你的电脑需要装有ctags。

Bundle 'taglist.vim'
let Tlist_Ctags_Cmd='ctags'
let Tlist_Show_One_File=1               "不同时显示多个文件的tag,只显示当前文件的
let Tlist_WinWidt =28                   "设置taglist的宽度
let Tlist_Exit_OnlyWindow=1             "如果taglist窗口是最后一个窗口,则退出vim
"let Tlist_Use_Right_Window=1           "在右侧窗口中显示taglist窗口
let Tlist_Use_Left_Windo =1             "在左侧窗口中显示taglist窗口

使用方法:

  • 在Vim命令行下运行":Tlist"就可以打开Taglist窗口,再次运行":Tlist"则关闭。
  • 左右窗口切换Ctrl+ww
    在taglist窗口中,可以使用下面的快捷键:
<CR>          跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o             在一个新打开的窗口中显示光标下tag
<Space>       显示光标下tag的原型定义
u             更新taglist窗口中的tag
s             更改排序方式,在按名字排序和按出现顺序排序间切换
x             taglist窗口放大和缩小,方便查看较长的tag
+             打开一个折叠,同zo
-             将tag折叠起来,同zc
*             打开所有的折叠,同zR
=             将所有tag折叠起来,同zM
[[            跳到前一个文件
]]            跳到后一个文件
q             关闭taglist窗口
<F1>          显示帮助

但是!这些大部分可以被鼠标取代!!快捷键是浮云~~
set mouse=a " always use mouse

2.2 NERDTree

NERDTree是一个用于浏览文件系统的树形资源管理外挂,它可以让你像使用Windows档案总管一样在VIM中浏览文件系统并且打开文件或目录。
https://github.com/scrooloose/nerdtree

相关说明:https://blog.csdn.net/a464057216/article/details/51523860

vimrc配置信息:

Bundle 'scrooloose/nerdtree'
let NERDTreeWinPos='right'
let NERDTreeWinSize=30
map <F2> :NERDTreeToggle<CR>

2.3 vim-airline

vim-airline其实是powerline的copy,它相比powerline有几个好处:它是纯vim script,powerline则用到python;它简单,速度比powerline快。
这是一款状态栏增强插件,可以让你的Vim状态栏非常的美观,同时包括了buffer显示条扩展smart tab line以及集成了一些插件。
https://github.com/bling/vim-airline
airline的配置信息:

Bundle 'bling/vim-airline'
set laststatus=2

2.4 minibufExplorer

minibuf可以在vim中创建多了小窗口

Bundle 'fholgado/minibufexpl.vim'
let g:miniBufExplMapWindowNavVim = 1 
let g:miniBufExplMapWindowNavArrows = 1 
let g:miniBufExplMapCTabSwitchBufs = 1 
let g:miniBufExplModSelTarget = 1 
let g:miniBufExplMoreThanOne = 0 

map <F7> :MBEbp<CR>
map <F8> :MBEbn<CR>

2.5 安装YouCompleteMe(不好装)

YouCompleteMe可以自动补全c和cpp代码。
还要安装需要的环境
sudo apt install build-essential cmake python3-dev

在vimrc中加入,YouCompleteMe会从一层层往上找.ycm_extra_conf.py理论上放在home就够了。

Bundle 'Valloric/YouCompleteMe'
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口"
let g:ycm_seed_identifiers_with_syntax = 1                  " 语法关键字补全

下载完后去YouCompleteMe目录下编译
./install.sh --clang-completer

2.6 安装VIM自动补全插件:deoplete

第一步:安装所有依赖


# 安装VIM 8
# ....

# 安装Python3
# ....

# 安装vim的Python-client库pynvim
# pip2 install --user pynvim
pip3 install --user pynvim

# 安装插件 python的neovim库
# pip2 install --user neovim
pip3 install --user neovim

第二步:在vimrc中添加配置

set encoding=utf-8
set pyxversion=3
" 或
set pyxversion=2


" 在插件管理器中,比如vim-plug中,加入如下:
if has('nvim')
  Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/deoplete.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'
endif

let g:python3_host_prog = "/usr/bin/python3"    " Python3的可执行文件位置
let g:deoplete#enable_at_startup = 1

保存重启vim,并在vim中输入命令:PlugInstall安装插件。

第三步:在vim中输入测试命令

以下命令不能报错才行:


     :python3 import neovim 不报错,或
     :python2 import neovim 不报错
     :echo has('pythonx') 返回1
     :echo exepath('python3') 能够显示python3的执行文件位置,或
     :echo exepath('python2') 能够显示python2的执行文件位置
     :echo neovim_rpc#serveraddr() 能显示服务器的IP地址

使用方法
在Insert模式下,直接输入文字就会弹出自动补全。然后用Ctrl+n和Ctrl+p上下选择。

2.7 升级vim

sudo add-apt-repository ppa:jonathonf/vim 

sudo apt-get update  
sudo apt install vim 

参考配置.vimrc

""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins Manager
""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set nocompatible                  " be iMproved, required
set pyxversion=3
filetype on                     " required
" set the runtime path to include Vundle and initialize
set rtp+=/home/chen/.vim/bundle/Vundle.vim/
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'L9'
Bundle 'taglist.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'bling/vim-airline'
Bundle 'fholgado/minibufexpl.vim'
"Bundle 'Valloric/YouCompleteMe'
Bundle 'wesleyche/SrcExpl'

if has('nvim')
  Plugin 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plugin 'Shougo/deoplete.nvim'
  Plugin 'roxma/nvim-yarp'
  Plugin 'roxma/vim-hug-neovim-rpc'
endif

call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList          - list configured plugins
" :PluginInstall(!)    - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!)      - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TagList
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd='ctags'
let Tlist_Show_One_File=1               "不同时显示多个文件的tag,只显示当前文件的
let Tlist_WinWidt =28                   "设置taglist的宽度
let Tlist_Exit_OnlyWindow=1             "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window=1           "在右侧窗口中显示taglist窗口
"let Tlist_Use_Left_Windo =0             "在左侧窗口中显示taglist窗口
nnoremap <F4> :TlistToggle<CR> "设置快捷键
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let NERDTreeWinPos='left'
let NERDTreeWinSize=30
map <F2> :NERDTreeToggle<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" custom setting
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tabstop=4
set shiftwidth=4
" set expandtab
set autoindent
set hlsearch
"set tag=/home/chen/Documents/kernel/linux-source-4.15.0/tags
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" airline 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set laststatus=2
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" miniBufExpl
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
let g:miniBufExplMoreThanOne = 0

map <F7> :MBEbp<CR>
map <F8> :MBEbn<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" YouCompleteMe
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
"autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口"
"let g:ycm_seed_identifiers_with_syntax = 1                  " 语法关键字补全
"let g:ycm_auto_trigger=0
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" deoplete.nvim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:python3_host_prog = "/usr/bin/python3"
let g:deoplete#enable_at_startup = 1

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SourceExplorer
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" // The switch of the Source Explorer
nmap <C-F12> :SrcExplToggle<CR>                "打开/闭浏览窗口
let g:SrcExpl_winHeight = 7
let g:SrcExpl_refreshTime = 100
let g:SrcExpl_jumpKey = "<ENTER>"
let g:SrcExpl_gobackKey = "<SPACE>"
let g:SrcExpl_colorSchemeList = [
        \ "Red",
        \ "Cyan",
        \ "Green",
        \ "Yellow",
        \ "Magenta"
    \ ]
let g:SrcExpl_searchLocalDef = 1
let g:SrcExpl_isUpdateTags = 0
"let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."
"let g:SrcExpl_updateTagsKey = "<C-F12>"
let g:SrcExpl_prevDefKey = "<C-F10>"
let g:SrcExpl_nextDefKey = "<C-F11>"

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope 自动加载cscope.out文件
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set csverb
    set cspc=3
    "add any database in current dir
    if filereadable("cscope.out")
        cs add cscope.out
    "else search cscope.out elsewhere
    else
        let cscope_file=findfile("cscope.out",".;")
        let cscope_pre=matchstr(cscope_file,".*/")
        if !empty(cscope_file) && filereadable(cscope_file)
            set nocsverb
            set cspc=8
            exe "cs add" cscope_file cscope_pre
            set csverb
        endif
    endif
endif
  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-07-14 23:09:10  更:2021-07-14 23:09:33 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/3 8:32:28-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码