若是你以为这个页面广告太多,欢迎移步博客阅读:Vim 插键及配置html
编辑器之神 —— Vimpython
平日使用vim常常编辑文件,想一想使用时的痛点,决定研究一下插件的使用。git
Vim的扩展一般也被成为bundle或插件。github
软件版本:编程
众多文章中都提到Vundle,那我就选用它好了!ubuntu
有一个 Vim 的插键网站,专门有相关插键的配置介绍:VimAwesomevim
~/.vim/bundle
路径下。git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
~/.vimrc
的顶部(前提是,你自己.vimrc
里一开始没有什么其余内容)。set nocompatible " be iMproved, required filetype off " 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' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo " Plugin 'tpope/vim-fugitive' " 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/'} " Install L9 and avoid a Naming conflict if you've already installed a " different version somewhere else. " Plugin 'ascenator/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 - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line
将须要安装的插键放入.vimrc
文件中便可,例如:segmentfault
Plugin 'scrooloose/nerdtree' "Plugin 'scrooloose/nerdtree' " 若是暂时不启用,就将该插件注释掉
打开vim,而后输入:windows
vim # 打开 vim :PluginInstall :PluginList # 查看已安装插键列表
# 注释下面这段话 # Plugin 'Valloric/YouCompleteMe'
而后centos
:PluginUpdate # 这个命令自己能够一键升级全部插件 :PlugginClean
参考:
:h vundle
Plugin 'scrooloose/nerdtree' "F2开启和关闭树" map <F2> :NERDTreeToggle<CR> let NERDTreeChDirMode=1 "显示书签" let NERDTreeShowBookmarks=1 "设置忽略文件类型" let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$'] "窗口大小" let NERDTreeWinSize=25
Plugin 'klen/python-mode' " https://vimawesome.com/plugin/python-mode
编写 Python 文件保存时,就会进行语法检查了:
let g:pymode_rope = 1 let g:pymode_rope_completion = 1 let g:pymode_rope_completion_bind = '<C-p>' "为了自动补全有效,须要将 set paste 设置不启用 let g:pymode_rope_goto_definition_bind = '<C-c>g' let g:pymode_python = 'python' " 默认检查 Python2 "Autofix PEP8 errors nnoremap <leader>f :PymodeLintAuto<CR>
快捷键:
K 显示内置函数文档 <leader>r 运行 python 文件 # let mapleader=", " " 设置 leader 为空格,那么`,+r`就能够运行 python 文件了
参考:
一个状态栏美化工具,颜控必备。附带功能能够一目了然的区分各类编辑状态。
Plugin 'vim-airline/vim-airline' "https://github.com/vim-airlin e/vim-airline Plugin 'vim-airline/vim-airline-themes' " https://github.com/v im-airline/vim-airline-themes https://github.com/vim-airline/vi m-airline/wiki/Screenshots
To use solarized dark, set :AirlineTheme solarized and add the following to your .vimrc: let g:airline_solarized_bg='dark'
配置:
let g:airline_powerline_fonts = 1 let g:airline_theme='deus' let g:Powerline_symbols='fancy' let Powerline_symbols='fancy' set t_Co=256 " 状态栏就有颜色了
安装:
Plugin 'Yggdroot/indentLine'
配置:
let g:indentLine_enabled = 1 let g:indentLine_color_term = 239 map <leader>m :IndentLinesToggle<CR> # 解决vim复制代码时,缩进线也被复制的问题 https://github.com/Yggdroot/indentLine/issues/261
为了这个插件可以有效果,也是折腾了半天。在 CentOS 平台是正常的,可是在 Mac 上的缩进线显示不正确,为什么会这样呢?SOF-Why is apple vim compiled WITHOUT conceal feature?,原来 Mac 上自带的 Vim 版本虽然是8.0版本,可是没有concel
这个 Feature ,而indentLine
插件要显示对齐线依赖这个,坚线和星号在使用 conceal 功能。
那么该怎么添加这个特性呢?搜了一圈,能够从新安装 Vim,能够参考这篇文章安装 Vim。
通过安装设置以后,能够经过vim --version|grep con
或者:echo has("conceal")
查看是否已经具备 conceal 特性:
ag 的语法:
ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]
ag 这个 vim 插键主要是基于这个项目 ggreer/the_silver_searcher
ag --list-file-types # 查看支持自定义哪些文件类型
安装了这个插键后,在 vim 的命令模式下,可使用:Ag [options] {pattern} [{directory}]
搜索了。
安装 vim 插键以前,机器自己须要ctags
:
# ubuntu sudo apt-get install ctags # centos sudo yum install ctags # mac brew install ctags
在这时使用 vim-tagbar 插件能够帮你快速了解当前文件中的类、方法等。
Plugin 'majutsushi/tagbar' " https://github.com/majutsushi/tagbar
配置:
nmap <F8> :TagbarToggle<CR>
关于 tagbar 的使用,看查看这篇文章 wklken-大纲式导航
目前主要涉及的是 Python 开发,因此,YCM 目前没有配置,以下仅供参考。
Plugin 'Valloric/YouCompleteMe'
sudo apt-get install build-essential cmake sudo apt-get install python-dev python3-dev cd ~/.vim/bundle/YouCompleteMe ./install.py --all cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/
"YouCompleteMe配置相关 let g:ycm_server_python_interpreter='/usr/bin/python' let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
安装主题的方法比较简单,例如须要安装molokai
主题,手动安装则按照以下步骤操做:
molokai.vim
文件,放入~/.vim/colors
中~/.vimrc
文件中加入行colorscheme molokai
便可。由于我在 VSCode 和 Iterm2 中都采用了 Dracula 的主题,所以,vim 主题我也一样偏心它,能够采用插键的方式安装:
Plugin 'dracula/vim' :PluginInstall
~/.vimrc
文件中加入行colorscheme dracula
便可。主题相关的命令:
:colorscheme "查看当前主题 :colorscheme space tab "列出全部主题 :colorscheme your-theme "切换主题
为了让vim使用起来更加驾轻就熟,先作一些简单的配置。
编辑VIM配置文件,可能一开始没有这个文件,不过不要紧,直接vi ~/.vimrc
保存这个文件便可。
今天学习到<leader>
这个概念,很强大,快捷键很方便!
nnoremap
将一个组合快捷键映射为另外一个快捷键。关于leader
以及其余map
知识,能够查看以下文章:
参考多人的配置,打造属于本身的Vim配置,这个配置不涉及插件的设置,由于经常生产环境是网络不通的,要迅速配置能用:
let mapleader="," " 设置 leader let g:mapleader = ',' " 分屏窗口移动, Smart way to move between windows map <C-j> <C-W>j map <C-k> <C-W>k map <C-h> <C-W>h map <C-l> <C-W>l " Go to home and end using capitalized directions " H和L跳转到行首行末, 实在不想按0和$, 太远 noremap H ^ noremap L $ " 命令行模式加强,ctrl - a到行首, -e 到行尾 cnoremap <C-a> <Home> cnoremap <C-e> <End> " 去掉搜索高亮 noremap <silent><leader>/ :nohls<CR> " 快速保存和退出 " Quickly close the current window nnoremap <leader>q :q<CR> " Quickly save the current file nnoremap <leader>w :w<CR> syntax on " 自动语法高亮 set cursorline " 突出显示当前行 set encoding=utf-8 set fileencoding=utf-8 set fileformat=unix "从Win上复制文件时,避免换行符错误 set hlsearch " 搜索时高亮显示被找到的文本 set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感 set incsearch " 输入搜索内容时就显示搜索结果 set laststatus=2 " 显示状态栏 (默认值为 1, 没法显示状态栏) set magic " 设置魔术 set nocompatible " 关闭 vi 兼容模式 set number " 显示行号 set paste " 解决拷贝的时遇到注释会自动注释后续全部行的问题 set ruler " 打开状态栏标尺 set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4 set softtabstop=4 " 使得按退格键时能够一次删掉 4 个空格 set smartindent " 开启新行时使用智能自动缩进 set tabstop=4 " 设定 tab 长度为 4 set ambiwidth=double " 设置为双字宽显示,不然没法完整显示如:☆
vim配置文件中的注释,末尾用"
隔开便可。保留注释,对于了解配置内容有利。
mac上iterm2中,你会发现你想复制terminal上的东西的时候,死活复制不了,这时按住 Option (Alt)
键就好了。
若是是在Windows平台上利用mobaxterm等工具,tmux也没法复制内容,按住shift
键便可。
注释掉这句话set mouse=a