admin 管理员组文章数量: 887021
提高效率:善用工具、刻意练习。
preface:
- 偶然想用vim的插件,搜了下打算安装jedi,后面不可收拾,发现插件贼香,便删了sublime,一切代码都从vim,真正觉悟vim的强大。
- vim插件太多,常用即可。知晓相关配置即可
前置环境:
- mac、python
- vim:
- 用系统自带的不够用vim --version(只提示支持python2,不支持python3)
- 需要brew install vim安装(特别耗时)
- vim --version(显示提示支持python3即可)
插件:
-
vundle
- 功能:管理其他插件的插件,首先安装。
- 安装:
- git clone http://github/gmarik/vundle.git ~/.vim/bundle/vundle
- .vimrc配置
- : BundleInstall
- 使用:
- # 安装插件
:BundleInstall
# 更新插件
:BundleUpdate
# 清除不需要的插件
:BundleClean
# 列出当前的插件
:BundleList
# 搜索插件
:BundleSearch
- # 安装插件
- 参考:
- https://www.jianshu/p/f2b0fa840973
- https://wwwblogs/20143605--pcx/p/10894820.html
-
Jedi-vim
- 功能:python自动提示
- 安装:
- git clone --recursive https://github/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vim
- Bundle 'davidhalter/jedi-vim’
- :BundleInstall
- 配置:
- let g:jedi#environment_path = "/Users/shifeng/anaconda3/bin/python"
- 若不配置,则默认调用系统自带的python,而不是第三方python
- 其他设置配置详见git:https://github/davidhalter/jedi-vim
- 使用:
- import numpy as np
- np.:“点”的时候,自动提示,上下可选,回车可确定,esc可退出自动提示
- 第一次点的时候,加载可能比较慢
- 参考:https://vimjc/jedi-vim-plugin.html
-
YouCompleteMe
- 功能:各种语言的自动补全。本质基于jedi-vim实现的
- 安装:
- # 翻墙下载,不然贼慢,特么一晚上都下载不完,翻墙后1分钟不到就下载完成了
- git clone https://github/Valloric/YouCompleteMe.git
- 放到.vim/bundle文件夹下
- git submodule update --init --recursive
- ./install.py #安装python版本即可
- 安装好了,使用失败(可能漏了啥,这个插件比较重量级?我就没用它了)
- 参考:
- https://github/ycm-core/YouCompleteMe#full-installation-guide
- https://juejin/post/6844903753443704846
https://blog.csdn/lqzixi/article/details/112682645
https://blog.csdn/fangkailove/article/details/106365539
-
flake8
- 功能:python的语法检查插件,神器。
- 安装:
- pip install flake8
- Plugin 'nvie/vim-flake8'
- 配置:
- " flake8插件
- " 我的python安装在/Users/shifeng/anaconda3/bin/,pip也在该路径下
autocmd FileType python map <buffer> <F3> :call flake8#Flake8()<CR>
autocmd BufWritePost *.py call flake8#Flake8()
let g:flake8_cmd="/Users/shifeng/anaconda3/bin/flake8"
let g:flake8_quickfix_location="right" "topleft left right "
- 修改源码:
- 问题:E501 line too long,默认设置得是超过79,就提示E501,但宽屏足够看,不需要替换
修改:
/Users/shifeng/anaconda3/lib/python3.7/site-packages/flake8/defaults.py文件中
MAX_LINE_LENGTH = 160
- 问题:E501 line too long,默认设置得是超过79,就提示E501,但宽屏足够看,不需要替换
- 使用:每次保存即可弹出flake8的quickFix
- 参考:
- https://vimjc/vim-flake8-plugin.html
https://blog.csdn/qq_40702130/article/details/111837191
- https://vimjc/vim-flake8-plugin.html
-
autopep8
- 功能:自动将代码改成符合PEP8规范,与flake8两者配合食用效果极佳
- 安装:
- pip install autopep8
~/.vimrc添加:
Plugin 'tell-k/vim-autopep8'
:PluginInstall安装即可
- pip install autopep8
- 使用:
- :Autopep8 --range 11 13:对指定的11到13行进行pep8自动替换
:Autopepe8:对全局代码进行格式风格替换
- :Autopep8 --range 11 13:对指定的11到13行进行pep8自动替换
- 配置
- “ F8按键自动启动autopep8、设置最大长度160,默认为79
autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>
let g:autopep8_max_line_length=160
- “ F8按键自动启动autopep8、设置最大长度160,默认为79
- 参考
- https://github/tell-k/vim-autopep8
- https://www.codercto/a/72232.html
-
nerdcommenter
- 功能:快速注释
- 安装
-
Bundle 'scrooloose/nerdcommenter'
let mapleader = ','
nnoremap <C-l> gt
nnoremap <C-h> gT
nnoremap <leader>t : tabe<CR>
-
- 使用
- <leader>按键设置为逗号
,ci:即可注释(或者,cc?)
,cu:即可解开注释
V,ci:V进入可视界面,然后进行注释
- <leader>按键设置为逗号
- git:https://github/preservim/nerdcommenter
-
AutoComplPop
- 功能:自动补齐(补齐已经编辑过的变量名,与jedi-vim不一样,两者配合使用效果极佳)
- 安装:
- 下载:http://www.vim/scripts/script.php?script_id=1879
解压
放到.vim/下
重启即可
- 下载:http://www.vim/scripts/script.php?script_id=1879
- 配置
- " autocomplpop插件配置:
" 中文输入时,取消比较好。不然弹出bug:E764:没有设定选项'omnifunc'
" :AcpEnable "启用auto-popup
" :AcpDisable "停止auto-popup
let g:AutoComplPop_IgnoreCaseOption=1
set ignorecase
let g:acp_behaviorKeywordCommand="\<C-x>\<C-o>"
let g:acp_completeOption = '.,w,b,u,t,i'
"vim启动时启用auto-popup(默认启动时候就已经启动了auto-popup了
let g:acp_enableAtStartUp = 1
" 输入一个字母即可补全
" let g:acp_behaviorKeywordLength = 1
" 自动弹出是由键映射,对于通过移动来避免自动弹出是很有用
" let g:AutoComplPop_MappingDriven = 1
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP
"autocmd FileType c set omnifunc=ccomplete#Complete
- " autocomplpop插件配置:
- 参考:
- 官网:https://www.vim/scripts/script.php?script_id=1879
- https://blog.csdn/G_BrightBoy/article/details/19498983
- https://blog.csdn/u011127242/article/details/78509774
-
delimitMate
- 功能:自动补全引号(单引号/双引号/反引号), 括号(()[]{})
- 安装:
- Bundle 'Raimondi/delimitMate'
:BundleInstall
- Bundle 'Raimondi/delimitMate'
- 文档:https://vimjc/vim-delimitmate-plugin.html
-
color
- 安装:下载颜色
- git clone https://github/AlessandroYorba/Alduin.git (背景颜色太难看了)
- git clone https://github/tomasr/molokai.git (还可以)
- 移动到~/.vim/colors
- 配置文件
- syntax enable
- set background=dark
- colorscheme molokai
- 安装:下载颜色
-
nerdtree
- 功能:实现文件夹
- 安装:
- Bundle 'scrooloose/nerdtree'
let NERDTreeWinPos='left'
let NERDTreeWinSize=25
let g:NERDTreeNodeDelimiter = "\u00a0"
"let g:NERDTreeNodeDelimiter = ''
"map <F2> :NERDTreeToggle<CR>
map <C-n> :NERDTreeToggle<CR>
- Bundle 'scrooloose/nerdtree'
- 使用
- Ctrl +N 开启左侧文件夹,再执行一次则关闭
上下按键移动,回车进入文件夹
目录树的使用主要通过在vim的command模式下键入如下命令,即可达到相应的效果。
?: 快速帮助文档(再按一次关闭文档)
o:打开文件,目录或者书签,和我们在对应节点上按回车键一个效果
go:打开文件,但是光标仍然停留在目录中
t:在新的tab上打开选定的节点
T:与t相同,但是光标仍然停留在目录中
i:在新窗格中打开文件
gi:和i 相同,但是光标仍然停留在目录中
s:在水平窗格打开一个文件
gs:和s相同,但是光标仍然停留在目录中
A:放大NERDTree窗口
p:跳到根节点
P:跳转到当前节点的父节点
K:跳转到当前目录的第一个节点
J:跳转到当前目录的最后一个节点
u:把上层目录设置为根节点
- Ctrl +N 开启左侧文件夹,再执行一次则关闭
- 参考:
- https://wwwblogs/littlewrong/p/6535728.html
- https://juejin/post/6844903537416077325
-
asyncrun
- 功能:vim里执行shell
- 文档:https://github/skywind3000/asyncrun.vim/blob/master/README-cn.md
-
tagbar
- 功能:(忘了,不那么常用?)
- 安装:
- Plugin 'majutsushi/tagbar'
:BundleInstall
- Plugin 'majutsushi/tagbar'
- 配置
- 配置:
" Tagbar
let g:tagbar_width=35
let g:tagbar_autofocus=1
let g:tagbar_left = 1
nmap <F3> :TagbarToggle<CR>
- 配置:
- 参考
- https://juejin/post/6844903537416077325
坑
- 执行:BundleInstall安装时,vim可能有缓存,需要退出.vimrc后再进入执行,否则找不到新改的
- vim配置时,某插件详细配置及说明文档放到最后面,不用放到call vundle#begin()、end()(其之间用于安装)之间,是比较好的习惯。
- quickeFix可能有冲突,需要进行配置
示例
- 解释
- 窗口1:flake8的quickfix窗口,提示PEP8风格问题
- 有的时候也能提示bug,某个变量没有预先定义(这一点非常重要)
- 窗口2:目录树,nerdtree插件,方便看到有哪些文件
- 窗口3:tagbar插件,每个函数、变量、class、import等归类查看
- 窗口4:当前编辑的文件
- 窗口5:输入Autopep8,自动帮你处理PEP8个格式的问题,例如
- 函数后面要两个空行,你输入一个了,自动帮你加一个空行(这种小问题居然是pep8风格)
- 第16行的lambda表达式,冒号后面少了空格,自动帮你加个(也是小问题)
- 窗口1:flake8的quickfix窗口,提示PEP8风格问题
~/.vimrc配置文件:(截止到20210130)
"语法高亮
set nonu
syntax on
"显示行号
set number
set nonu
"显示光标所在位置的行号和列号
set ruler
set wrap "自动折行
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab "将tab替换为相应数量空格
set smartindent
set backspace=2
"设置取消备份 禁止临时文件生成
set nobackup
set noswapfile
"设置匹配模式 类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
"set laststatus=2 "命令行为两行
"set fenc=utf-8 "文件编码
"set mouse=a "启用鼠标
set ignorecase "忽略大小写
set cursorline "突出显示当前行
set cursorcolumn "突出显示当前列
set fdm=marker
set report=0
" 颜色
syntax enable
set background=dark
"colorscheme alduin
colorscheme molokai
"hi term=reverse ctermfg=0 ctermbg=222 guifg=#000000 guibg=#FFE792
"jj退出insert模式
"inoremap <C-j> <ESC>
inoremap jk <ESC>
" insert模式下
" ctrl+H单词左移动,类似normal下单词b,似乎不成功:网上建议在normal模式加移动
"inoremap <C-H> <C-\><C-O>b
"inoremap <C-L> <C-\><C-O>w
"inoremap <C-h> <Left>
"inoremap <C-j> <Down>
"inoremap <C-k> <Up>
"inoremap <C-l> <Right>
"inoremap <C-d> <DELETE>
" 可视行后,逗号+c,即可复制到系统的剪切板,从vim里面复制出去
" 同理,逗号+v,将系统剪切板里的内容,copy到vim里面
nmap ,v "+p
vmap ,c "+y
nmap ,c "+y
vmap ,c :w !pbcopy<CR><CR>
nmap ,c :w !pbcopy<CR><CR>
nmap ,v :r !pbpaste<CR><CR>
""""""""""""""""""""""
"Quickly Run
""""""""""""""""""""""
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
#exec "!time python2.7 %"
if search("@profile")
exec "AsyncRun kernprof -l -v %"
exec "copen"
exec "wincmd p"
elseif search("set_trace()")
exec "!python3 %"
else
exec "AsyncRun -raw python3 %"
exec "copen"
exec "wincmd p"
endif
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
" exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
"设置vundle
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
filetype plugin indent on " required!
"vundle设置完毕
"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窗口
"Bundle 'Valloric/YouCompleteMe'
"Bundle 'skywind3000/asyncrun.vim'
Bundle 'majutsushi/tagbar'
"nmap <Leader>tb :TagbarToggle<CR> "快捷键设置
let g:tagbar_ctags_bin='ctags' "ctags程序的路径
let g:tagbar_width=20 "窗口宽度的设置
map <F3> :Tagbar<CR>
map <C-t> :Tagbar<CR>
"autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*,*.cxx call tagbar#autoopen() "如果是c语言的程序的话,tagbar自动开启
Bundle 'scrooloose/nerdtree'
Bundle 'bling/vim-airline'
set laststatus=2
Bundle 'scrooloose/nerdcommenter'
let mapleader = ','
nnoremap <C-l> gt
nnoremap <C-h> gT
nnoremap <leader>t : tabe<CR>
"vim-multiple-cursors 多光标选中
"Bundle 'terryma/vim-multiple-cursors'
"let g:multi_cursor_use_default_mapping=0
"let g:multi_cursor_start_key='<C-m>'
"let g:multi_cursor_start_word_key='g<C-m>'
"let g:multi_cursor_next_key='<C-m>'
"let g:multi_cursor_prev_key='<C-p>'
"let g:multi_cursor_skip_key='<C-x>'
"let g:multi_cursor_quit_key='<C-j>'
"MatchTagAlways
Bundle 'Valloric/MatchTagAlways'
"Markdown语法高亮
Bundle 'godlygeek/tabular'
"Bundle 'plasticboy/vim-markdown'
"markdown实时显示
Bundle 'suan/vim-instant-markdown'
"indentLine 代码缩进线标志线
Plugin 'Yggdroot/indentLine'
let g:indentLine_char = '┆'
let g:indentLine_color_term = 239
let g:indentLine_enabled = 1
"映射到ctrl+I键
"map <C-i> :IndentLinesToggle<CR>
" ************** 插件管理与设置 ************ "
" vundle 环境设置
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
" vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Lokaltog/vim-powerline' "status 美化
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
"Plugin 'garbas/vim-snipmate'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'scrooloose/nerdcommenter'
"Plugin 'preservim/nerdtree'
Plugin 'scrooloose/nerdtree'
"delimitMate 自动补全引号(单引号/双引号/反引号), 括号(()[]{})
"let b:delimitMate_autoclose = 0 #选项关闭 delimitMate 插件
Plugin 'Raimondi/delimitMate'
" 插件列表结束
Plugin 'davidhalter/jedi-vim'
"Plugin 'Valloric/YouCompleteMe'
Plugin 'majutsushi/tagbar'
Plugin 'nvie/vim-flake8'
" Plugin 'chrismetcalf/autocomplpop'
Plugin 'tell-k/vim-autopep8'
call vundle#end()
filetype on
" jedi:python自动提示.youcompleteme太难装了,换其爸爸(其内核为jedi)
let g:jedi#environment_path = "/Users/shifeng/anaconda3/bin/python"
" asyncr插件设置:vim里执行shell
let g:asyncrun_open=8
" Tagbar插件:
let g:tagbar_width=35
let g:tagbar_autofocus=1
let g:tagbar_left = 1
" flake8插件:python语法检查
autocmd FileType python map <buffer> <F3> :call flake8#Flake8()<CR>
autocmd BufWritePost *.py call flake8#Flake8()
"pip安装的flake8的路径"
let g:flake8_cmd="/Users/shifeng/anaconda3/bin/flake8"
"topleft left right "
let g:flake8_quickfix_location="topleft"
let g:flake8_quickfix_height=7
" 退出最后一个文件编辑窗口,自动退出flake8的quickfix窗口
autocmd BufEnter * if 0 == len(filter(range(1, winnr('$')), 'empty(getbufvar(winbufnr(v:val), "&bt"))')) | qa! | endif
" nerdTree插件:目录树
let NERDTreeWinPos='left'
let g:NERDTreeNodeDelimiter = "\u00a0"
"let g:NERDTreeNodeDelimiter = ''
"开启/关闭nerdtree快捷键
"map <F2> :NERDTreeToggle<CR>
map <C-n> :NERDTreeToggle<CR>
"打开NERDTree
" autocmd vimenter * NERDTree
"光标默认在主窗口
"wincmd w
"autocmd VimEnter * wincmd w
"自动开启Nerdtree
" autocmd vimenter * NERDTree
let g:NERDTreeWinSize = 25 "设定 NERDTree 视窗大小
" 开启Nerdtree时自动显示Bookmarks
" let NERDTreeShowBookmarks=1
"打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif
"当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"设置树的显示图标
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
" 过滤所有.pyc文件不显示
let g:NERDTreeHidden=0
let NERDTreeIgnore = ['\.pyc$', '\.swp', '\.swo', '\.vscode', '__pycache__']
"let g:NERDTreeShowLineNumbers=1 " 是否显示行号
"Making it prettier
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
" 新的缓冲区设置在右边
" 等同于:belowright vsp xx.txt:右新增
set splitright
" 新的缓冲区设置在下边
" 等同于:belowright sp xx.txt,下新增
set splitbelow
":leftabove sp xx.txt:上新增(leftabove==aboveleft)
":leftabove vsp xx.txt:左新增
":topleft vsp xx.txt:整个vim左新增
":topleft sp xx.txt:整个vim上新增
":botright vsp xx.txt:整个vim右新增
":botright sp xx.txt:整个vim下新增
" youcompleteMe插件:代码补全
"let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
"let g:ycm_server_python_interpreter='/Users/shifeng/anaconda3/bin/python'
"let g:ycm_server_keep_logfiles = 1
"let g:ycm_server_log_level = 'debug'
" autocomplpop插件配置:
" 中文输入时,取消比较好。不然弹出bug:E764:没有设定选项'omnifunc'
" :AcpEnable "启用auto-popup
" :AcpDisable "停止auto-popup
let g:AutoComplPop_IgnoreCaseOption=1
set ignorecase
" 前缀为ctrl+x ctrl+o来补全,改为tab不知道怎么改
let g:acp_behaviorKeywordCommand="\<C-x>\<C-o>"
" let g:acp_behaviorKeywordCommand="\<Tab>"
let g:acp_completeOption = '.,w,b,u,t,i'
"vim启动时启用auto-popup(默认启动时候就已经启动了auto-popup了
let g:acp_enableAtStartUp = 1
" 输入一个字母即可补全
" let g:acp_behaviorKeywordLength = 1
" 自动弹出是由键映射,对于通过移动来避免自动弹出是很有用
" let g:AutoComplPop_MappingDriven = 1
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP
"autocmd FileType c set omnifunc=ccomplete#Complete
" autopep8插件
autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>
let g:autopep8_max_line_length=160
let g:autopep8_ignore="E501,W293"
版权声明:本文标题:vim工具——常用插件 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726378084h948347.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论