基础配置
"+
寄存器是系统粘贴板,:reg
查看所有寄存器,如果没有这个,安装gvim
就有了
安装插件管理器 Vundle
从github上克隆
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim ~/.vimrc
配置文件加入如下内容:
" ----------------------------- Vundle Start -----------------------------
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
call vundle#end()
filetype plugin indent on
" ----------------------------- Vundle End -----------------------------
示例安装目录浏览器 NERDTree
执行vim
在vim
命令模式下:PluginSearch NERD
[图片上传失败...(image-2a61bb-1548764208123)]回车后出现这样一个左侧的分屏,将里面光标出一航填到.vimrc文件
ctlr + w + w
可以切换分屏
保存退出,在执行vim ~/.vimrc
命令模式执行PluginInstall
,当左侧窗口Plugin 'The-NERD-tree'
前面出现+
号安装完成
命令模式执行:NERDTree
启动插件,?
查看用法
" 关闭NERDTree快捷键
map <leader>t :NERDTreeToggle<CR>
""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif
" 显示行号
"let NERDTreeShowLineNumbers=1
" 是否显示隐藏文件
let NERDTreeShowHidden=0
" 设置宽度
let NERDTreeWinSize=25
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略以下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
taglist 用法
先安装ctags,这个不是插件,是一个工具,使用yum或apt安装
然后执行,添加需要的tag
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/path/yourtag /usr/include/youwant
和补全插件联合使用看wiki
这样会生成一个系统tags文件,然后配置vimrc
set tags=tags
set tags+=~/.vim/path/yourtag
:Tlist
打开taglist
快捷键 | 作用 |
---|---|
<CR> | 跳到光标下tag所定义的位置 |
o | 在一个新打开的窗口中显示光标下tag |
<Space> | 显示光标下tag的原型定义 |
u | 更新taglist窗口中的tag |
s | 更改排序方式,在按名字排序和按出现顺序排序间切换 |
x | taglist窗口放大和缩小,方便查看较长的tag |
+ | 打开一个折叠,同zo |
- | 将tag折叠起来,同zc |
* | 打开所有的折叠,同zR |
= | 将所有tag折叠起来,同zM |
[[ | 跳到前一个文件 |
]] | 跳到后一个文件 |
q | 关闭taglist窗口 |
<F1> | 显示帮助 |
一些配置
let Tlist_Ctags_Cmd = '/usr/bin/ctags' "设置ctags路径
let Tlist_Auto_Open = 1 "启动vim后自动打开taglist窗口
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,仅显示一个
let Tlist_Exit_OnlyWindow = 1 "taglist为最后一个窗口时,退出vim
let Tlist_Use_Right_Window =1 "taglist窗口显示在右侧,缺省为左侧
"let Tlist_WinHeight = 100 "设置taglist窗口大小
let Tlist_WinWidth = 40
"设置taglist打开关闭的快捷键F8
noremap <F8> :TlistToggle<CR>
"更新ctags标签文件快捷键设置
noremap <F6> :!ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++<CR>
安装 OmniCppComplete 命令补全
需要提前生成tag文件wiki
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest "preview
~/.vimrc配置
"-------------------------------基础配置------------------------
set nu "显示行号 set number
syntax on "语法高亮
set tabstop=4 "tab长度
set shiftwidth=4 "缩进长度
set mouse=a "启用鼠标
set showmatch "显示括号匹配
"inoremap { <CR>{}<Left><CR><CR><up><tab>
set autoindent "自动对齐
set smartindent "智能缩减
" ----------------------------- Vundle Start -----------------------------
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'The-NERD-tree'
Plugin 'Auto-Pairs'
Plugin 'SuperTab'
Plugin 'OmniCppComplete'
"Plugin 'taglist-plus'
Plugin 'taglist.vim'
call vundle#end()
filetype plugin indent on
" ----------------------------- Vundle End -----------------------------
" ----------------------------- NERDTree --------------------------------
" 关闭NERDTree快捷键
map <leader>t :NERDTreeToggle<CR>
""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif
" 显示行号
"let NERDTreeShowLineNumbers=1
" 是否显示隐藏文件
let NERDTreeShowHidden=0
" 设置宽度
let NERDTreeWinSize=25
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略以下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
" ----------------------------- ctags ------------------------------------
set tags=tags
set tags+=~/.vim/mytag/cpp
set autochdir
" ----------------------------- taglist ----------------------------------
let Tlist_Ctags_Cmd = '/usr/bin/ctags' "设置ctags路径
"let Tlist_Auto_Open = 1 "启动vim后自动打开taglist窗口
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,仅显示一个
let Tlist_Exit_OnlyWindow = 1 "taglist为最后一个窗口时,退出vim
let Tlist_Use_Right_Window =1 "taglist窗口显示在右侧,缺省为左侧
"let Tlist_WinHeight = 100 "设置taglist窗口大小
"let Tlist_WinWidth = 40
"设置taglist打开关闭的快捷键F8
noremap <F8> :TlistToggle<CR>
"更新ctags标签文件快捷键设置
noremap <F6> :!ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++<CR>
"-------------------------------- OmniCppComplete ------------------
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest "preview