• VIM插件安装与配置



    前言

    在某些情况下只能用vim编辑器,而没有类似vscode的图形化界面,为vim配置一系列插件即可方便的在vim下编程


    插件管理工具

    VundleVim


    vim-plug
    将插件的地址添加进去,然后打开vim输入PlugInstall即可自动安装

    
    " vim-plug
    call plug#begin('~/.vim/plugged')
    "plug插件管理,全异步安装,不仅支持在线安装,更支持下载好的离线包直接安装。
    "且安装完后,可以注释掉相关指令很方便的关闭对应插件。下面基本都是离线安装的例子
    "Plug 'vim-scripts/vim-gutentags'
    Plug 'mhinz/vim-startify'
    Plug 'vim-scripts/taglist.vim'
    Plug 'preservim/nerdcommenter'
    Plug 'vim-airline/vim-airline'
    Plug 'ludovicchabant/vim-gutentags'
    Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
    Plug 'octol/vim-cpp-enhanced-highlight'
    Plug 'ycm-core/YouCompleteMe'
    Plug 'luochen1990/rainbow'
    call plug#end()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    所有的插件都会安装在~/.vim目录下

    1. vimrc通用配置

    ~目录下将下面的内容放入.vimrc(若没有则新建一个)文件内

    "通用配置
    syntax on  " 开启语法高亮
    colorscheme peachpuff "vim配置方案
    set number  " 显示行号
    set hls "搜索时高亮显示被找到的文本
    set scrolloff=3 " 上下可视行数
    set incsearch   " 搜索时高亮显示被找到的文本
    set ignorecase smartcase "搜索时默认不区分大小写,只有搜索关键字中出现一个大字母时才区分大小写
    set enc=utf-8  "编码设置
    set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 "编码自动识别
    set mouse=n "鼠标普通模式
    " set cursorline "选中行出现下划线
    set autowriteall "可使切换文件时,修改的文件被自动保存
    set autoread "打开文件监视。如果在编辑过程中文件发生外部改变(比如被别的编辑器编辑了),就会发出提示。
    set hidden  " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
    map qq :qa!<CR> "多窗口不保存关闭
    map ww :wqa! "多窗口保存关闭
    "vim自动打开跳到上次的光标位置
    if has("autocmd")
            au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
    endif
    set nocompatible  "设置backspace的工作方式
    set backspace=indent,eol,start " 设置backspace的工作方式
    " 自动去除尾行空格和tab
    " From: Vigil 
    function RemoveTrailingWhitespace()
        if &ft != "diff"
            let b:curcol = col(".")
            let b:curline = line(".")
    		"去掉每一尾行的空格和Tab
    		silent! %s/\s\+$//
    		"去掉文件最后无内容的行尾
    		" silent! %s/\(\s*\n\)\+\%$//
            call cursor(b:curline, b:curcol)
        endif
    endfunction
    " autocmd BufWritePre * call RemoveTrailingWhitespace()
    " TAB会被显示成 >— 而行尾多余的空白字符显示成 -
    map   :ter "在vim内终端
    set listchars=tab:>-,trail:-
    map   :set list " 显示空格和tab
    map   :set list! " 取消显示空格和tab
    map   cq " 手动关闭QuickFix窗口
    autocmd FileType qf nnoremap   :cclose "打开QuickFix窗口选择后自动关闭
    
    
    " vim-plug
    call plug#begin('~/.vim/plugged')
    "plug插件管理,全异步安装,不仅支持在线安装,更支持下载好的离线包直接安装。
    "且安装完后,可以注释掉相关指令很方便的关闭对应插件。下面基本都是离线安装的例子
    "Plug 'vim-scripts/vim-gutentags'
    Plug 'mhinz/vim-startify'
    Plug 'vim-scripts/taglist.vim'
    Plug 'preservim/nerdcommenter'
    Plug 'vim-airline/vim-airline'
    Plug 'ludovicchabant/vim-gutentags'
    Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
    Plug 'octol/vim-cpp-enhanced-highlight'
    Plug 'ycm-core/YouCompleteMe'
    Plug 'luochen1990/rainbow'
    call plug#end()
    
    "Tlist插件配置
    let Tlist_Show_One_File           = 1 " 只显示当前文件的tags
    "let Tlist_Auto_Open               = 1 " 打开vim自动打开Tlist
    "let Tlist_GainFocus_On_ToggleOpen = 1 " 打开Tlist窗口时,光标跳到list窗口
    let Tlist_Exit_OnlyWindow         = 1 " 如果Tlist窗口是最后一个窗口则退出Vim
    let Tlist_Use_Left_Window         = 1 " 在左侧窗口中显示
    let Tlist_File_Fold_Auto_Close    = 1 " 自动折叠
    let Tlist_Auto_Update             = 1 " 自动更新
    "  打开 Tlist 窗口,在左侧栏显示
    map  :TlistToggle
    
    "nerdcommenter插件快速注释
    let g:NERDSpaceDelims            = 1      " 在注释符号后加一个空格
    let g:NERDCompactSexyComs        = 1      " 紧凑排布多行注释
    let g:NERDDefaultAlign           = 'left' " 逐行注释左对齐
    let g:NERDAltDelims_java         = 1      " JAVA 语言使用默认的注释符号
    let g:NERDCustomDelimiters       = {'c': {'left': '/*', 'right': '*/'}} " C 语言注释符号
    let g:NERDCommentEmptyLines      = 1      " 允许空行注释
    let g:NERDTrimTrailingWhitespace = 1      " 取消注释时删除行尾空格
    let g:NERDToggleCheckAllLines    = 1      " 检查选中的行操作是否成功
    " 选中注释
    map  NERDCommenterSexy         
    " 选中取消注释
    map  NERDCommenterUncomment 
    
    "airline状态栏配置
    "这个是安装字体后 必须设置此项"
    let g:airline_powerline_fonts = 1
    
    "打开tabline功能,方便查看Buffer和切换,省去了minibufexpl插件
    let g:airline#extensions#tabline#enabled = 1
    let g:airline#extensions#tabline#buffer_nr_show = 1
    
    let g:airline#extensions#tabline#formatter = 'unique_tail'
    
    " " 关闭状态显示空白符号计数
    let g:airline#extensions#whitespace#enabled = 0
    let g:airline#extensions#whitespace#symbol = '!'
    " " 设置consolas字体"前面已经设置过
    " " set guifont=Consolas\ for\ Powerline\ FixedD:h11
    if !exists('g:airline_symbols')
      let g:airline_symbols = {}
    endif
    "
    " " unicode symbols
    let g:airline_left_sep = ''
    let g:airline_right_sep = ''
    let g:airline_symbols.crypt = '🔒'
    let g:airline_symbols.linenr = ''
    let g:airline_symbols.maxlinenr = ''
    let g:airline_symbols.branch = ''
    let g:airline_symbols.paste = ''
    let g:airline_symbols.spell = ''
    let g:airline_symbols.notexists = ''
    let g:airline_symbols.whitespace = 'Ξ'
    "设置切换Buffer快捷键"
    map  :bp    " 切换到上一个
    map  :bn   " 切换到下一个
    map  :bd        " 关闭当前窗口
    map 11 :b1          " 切换到编号1
    map 22 :b2          " 切换到编号2
    map 33 :b3          " 切换到编号3
    map 44 :b4          " 切换到编号4
    map 55 :b5          " 切换到编号5
    map 66 :b6          " 切换到编号6
    map 77 :b7          " 切换到编号7
    map 88 :b8          " 切换到编号8
    map 99 :b9          " 切换到编号9
    map 00 :b10         " 切换到编号10
    
    " " 配置 ctags 的参数 "
    map  g  "ctags跳转不自动选择
    
    " gutentags 搜索工程目录的标志,当前文件路径向上递归直到碰到这些文件/目录名
    let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
    
    " 所生成的数据文件的名称
    let g:gutentags_ctags_tagfile = '.tags'
    
    " 同时开启 ctags 和 gtags 支持:
    let g:gutentags_modules = []
    if executable('ctags')
            let g:gutentags_modules += ['ctags']
    endif
    if executable('gtags-cscope') && executable('gtags')
            let g:gutentags_modules += ['gtags_cscope']
    endif
    
    " 将自动生成的 ctags/gtags 文件全部放入 ~/.cache/tags目录中,避免污染工程目录
    let g:gutentags_cache_dir = expand('~/.cache/tags')
    
    " 配置 ctags 的参数,老的 Exuberant-ctags 不能有--extra=+q,注意
    let g:gutentags_ctags_extra_args = ['--fields=+niazS']
    let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
    let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
    
    " 如果使用 universal ctags 需要增加下面一行,老的Exuberant-ctags 不能加下一行
    "let g:gutentags_ctags_extra_args += ['--output-format=e-ctags']
    " 禁用 gutentags 自动加载 gtags 数据库的行为
    let g:gutentags_auto_add_gtags_cscope = 0
    
    "LeaderF 模糊文件查找配置
    let g:Lf_ShortcutF = '<c-p>' " 文件快速搜索
    " 函数,宏,变量快速搜索
    noremap  :LeaderfTag
    let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' }
    let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git']
    let g:Lf_WorkingDirectoryMode = 'Ac'
    let g:Lf_WindowHeight = 0.30
    let g:Lf_CacheDirectory = expand('~/.vim/cache')
    let g:Lf_ShowRelativePath = 0
    let g:Lf_HideHelp = 1
    let g:Lf_StlColorscheme = 'powerline'
    let g:Lf_PreviewResult = {'Function':0, 'BufTag':0}
    
    " #############################################################################
    " cpp-enhanced-highlight c/c++ 语法高亮配置
    let g:cpp_class_scope_highlight = 1 
    let g:cpp_member_variable_highlight = 1
    let g:cpp_class_decl_highlight = 1
    let g:cpp_posix_standard = 1
    let g:cpp_experimental_simple_template_highlight = 1  " a little slow on large files
    "let g:cpp_experimental_template_highlight = 1 " fast but have corner case
    let g:cpp_concepts_highlight = 1
    let g:cpp_no_function_highlight = 1
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190

    5.标签列表插件(taglist)

    sudo apt install universal-ctags
    
    • 1

    总结

    https://vimawesome.com/

    建议用vscode,经过一番折腾,发现还是vscode好用

  • 相关阅读:
    软考-信息安全工程师-2
    轻松管理Web服务器:Linux Apache技巧与技术
    Spring Boot Actuator 介绍
    Pytest系列-快速入门和基础讲解(1)
    Flink - ProcessFunction 使用缓存详解
    mysql的缓存页对LRU的改进;预读机制;及对应的调优
    【状语从句练习题】because / because of / although / in spite of
    迭代器模式简介
    使用python电脑轻量级控制手机—adb命令和手机投屏
    http 和 https 的区别?
  • 原文地址:https://blog.csdn.net/surfaceyan/article/details/136856016