01. VIM 配置
02. Neovim 配置
03. IdeaVim 进阶配置
04. VsVim 配置
前言
请知悉:
在 gvim 中:
.vimrc == _vimrc
~/.vim == $VIM/vimfiles(其中,$VIM 为用户本地 Vim 安装目录)
基础配置
" change leader \ to,this will endup f{Char} a little slower.
let mapleader=';'
" no backup (not producing ~ file)
set noundofile
set nobackup
set noswapfile
" real time search result shown
set incsearch
" 搜索到文件两端时不重新搜索
set nowrapscan
" Allow to switch buffers without saving
set hidden
" encoding setting
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
" auto complete brackets
inoremap {<CR> {<C-o>o}<C-o>O
inoremap ( ()<ESC>i
inoremap < <><ESC>i
inoremap " ""<ESC>i
inoremap ' ''<ESC>i
更改 colorscheme
- 到网上下载一个 scheme,推荐:vivify
将上一步下载的主题的 .vim 文件放入到路径:~/.vim/colors(windows放入到:$VIM/vimfiles/colors)
在.vimrc(_vimrc)中添加:colorscheme SolarizedDark,然后重启 vim 或者直接输入 :source $MYVIMRC
当然更简单的方法就是使用包管理插件,但谨记设置主题是必须在主题插件加载完后(即在 plug#end() 后面进行设置才行)。
比如,这里我们下在一个主题插件 vim-hybrid-material,其具体配置如下所示:
call plug#begin(g:plugins_path)
" ...
Plug 'kristijanhusak/vim-hybrid-material'
call plug#end()
" 只有在包管理插件完成后,才表示插件安装完成,这时才能对下载的主题进行获取设置
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set background=dark
colorscheme hybrid_reverse
" making functions and language controls to be bolded
let g:enable_bold_font = 1
" make comments to be in italic
let g:enable_italic_font = 1
" make background transparent
" let g:hybrid_transparent_background = 1
let g:airline_theme = "hybrid"
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
gvim 安装 vundle
- 下载:
git clone https://github.com/VundleVim/Vundle.vim.git $VIM/vimfiles/bundle/Vundle.vim
2.配置
function IsWin32()
return has('win32')
endfunction
function IsWin32Unix()
return has('win32unix')
endfunction
function IsUnix()
return has('unix')
endfunction
function IsMac()
return has('macunix')
endfunction
" vundle configurations
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
if IsWin32()
set rtp+=$VIM/vimfiles/bundle/Vundle.vim
call vundle#begin('$VIM/vimfiles/bundle/')
elseif IsUnix() || IsWin32Unix() || IsMac()
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
endif
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" add plugin here
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
- 配置 Git,将Git的路径设置到环境变量中,这样,vundle 会自动使用 Git 下载相应的插件进行安装。
详情查看:Vundle for Windows
gvim 安装 vim-plug
下载:下载 plug.vim,并放置到安装目录的
$VIM/vimfiles/autoload
中配置:
" plug-vim configurations
call plug#begin('~/.vim/plugged')
" -------------------------------------------------------------------------
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }
" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
" -------------------------------------------------------------------------
" Initialize plugin system
call plug#end()
- 命令:如下表所示:
命令 | 描述 |
---|---|
PlugInstall [name ...] [#threads] |
安装插件 |
PlugUpdate [name ...] [#threads] |
安装或更新插件 |
PlugClean[!] |
移除插件 |
PlugUpgrade |
更新 vim-plug |
PlugStatus |
检查插件状态 |
PlugDiff |
检测插件更新的内容 |
PlugSnapshot[!] [output path] |
为当前插件状态生成一个快照 |
-
Plug
命令选项:如下表所示:
命令 | 描述 |
---|---|
branch /tag /commit
|
使用仓库的对应 branch /tag /commit 版本 |
rtp |
包含 Vim 插件的子目录 |
dir |
为插件自定义存储目录 |
as |
为插件定义别名 |
do |
安装或更新插件钩子(在安装或更新插件后,自动调用钩子函数) |
on |
按需加载插件 |
for |
按文件类型加载插件 |
frozen |
除非明确指定,否则不更新插件 |
按需加载例子:
" NERD tree 插件会在首次使用 NERDTreeToggle 命令时进行加载
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" 多个命令
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }
" 当文件类型为 clojure 时,加载插件
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" 多种文件类型
Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }
" 当首次执行 Vader 命令,且文件类型为 vader 时,加载插件
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
" 插件按需加载后执行特定代码
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
autocmd! User goyo.vim echom 'Goyo is now loaded!'
插件安装
nmap wm :NERDTreeToggle<CR>
let NERDTreeWinPos='left'
let NERDTreeWinSize=30
一些好用点:
命令/按键 | 功能 |
---|---|
o | 打开文件,相当于 <CR> |
go | 打开文件,但光标还是留在 NERDTree |
x | 关闭当前节点 |
X | 迭代关闭当前节点及子节点 |
q | 关闭 NERDTree 窗口 |
p | 跳到当前顶层根节点 |
P | 跳到最顶层根节点 |
I | 显示/隐藏 不可见文件 |
A | 最大化/最小化 窗口 |
R/r | 刷新所在节点及其子节点/当前目录(增加/删除文件···) |
m | 文件操作提示(可以进行文件/文件夹创建,删除,移动) |
删除文件快捷操作 | 选中,mdy |
<C-J>/<C-K> | 同节点移动(忽略子节点) |
更多 NERDTree 操作,请查看:KeyMappings
配置:
if executable('ag')
let g:ctrlsf_ackprg = 'ag'
endif
let g:ctrlsf_case_sensitive = 'smart'
let g:ctrlsf_default_root = 'project'
let g:ctrlsf_default_view_mode = 'normal'
let g:ctrlsf_position = 'left'
let g:ctrlsf_winsize = '30%'
nnoremap <C-f> :CtrlSF<Space>
inoremap <C-f> <ESC>:CtrlSF<Space>
" visiual and select mode
vnoremap <C-f> "1y:CtrlSF<Space><C-R>1
" visiual mode
" xnoremap <C-f> :CtrlSF<Space>
" command line mode
cnoremap <C-f> CtrlSF
常用命令:
命令/按键 | 功能 |
---|---|
:CtrlSF [pattern] | 启动搜索 |
:CtrlSFOpen | 重新打开先前关闭的搜索窗口 |
M | 以 quickfix 形式展示搜索结果 |
<C-J> | 移动到下一个匹配处 |
<C-K> | 移动到上一个匹配处 |
p | 打开预览窗口 |
P | 打开预览窗口,并将焦点移动到预览窗口 |
t | 用标签(tab)打开 |
T | 用标签(tab)打开,但是保留焦点还在 CtrlSF 中 |
O | 与 Enter 一样,但是会保留 CtrlSF 窗口 |
" Change the default mapping and the default command to invoke CtrlP
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
" set local working directory:current file
let g:ctrlp_working_path_mode = 'ra'
" exclusions
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll)$',
\ 'link': 'some_bad_symbolic_links',
\ }
" let g:ctrlp_user_command = ['.git/', 'git ls-files --cached --others --exclude-standard %s']
" The Silver Searcher
if executable('ag')
" Use ag over grep
let g:ctrlp_user_command = ['ag','ag %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .svn
\ --ignore .hg
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ -g ""' ]
endif
注意:上面配置中让 CtrlP 使用外部的扫描工具 ag(the Silver Searcher),使得其搜素速度有了质的提升 :).
一些好用点:
命令/按键 | 功能 |
---|---|
:CtrlP/:CtrlP [starting-directory] | 启动 CtrlP |
<C-d> | 切换到仅搜索文件名而不是完整路径 |
<F5> | 刷新缓存(更新新增文件,删除文件···) |
<c-r> | 切换为正则搜索 |
<c-t> or <c-v>, <c-x> | 新窗口打开文件 |
-
EasyMotion
同屏光标快速移动大法
好用点:
命令/按键 | 功能 |
---|---|
<leader><leader>w | 从光标位置起,往 下 在 单词 之间移动光标 |
<leader><leader>b | 从光标位置起,往 上 在 单词 之间移动光标 |
<leader><leader>s{char} | 全局搜索指定 字符 |
<leader><leader>f{char} | 从光标位置起,往 下 搜索指定 字符 |
可以通过:SyntasticInfo
查看当前语法检测器是否正确以及是否能正常工作,可以通过在 .vimrc/_vimrc 中指定相应类型的文件对应的语法检测器:
let g:syntastic_<filetype>_checkers = ['<checker-name>']
Syntastic 基本配置如下:
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
-
surround.vim
快速的为字符串增加/删除/修改引号/括号或者HTML标签
Mode | 命令/按键 | 功能 |
---|---|---|
Normal | ys | add a surrounding |
Normal | yS | add a surrounding and place the surrounded text on a new line + indent it |
Normal | yss | add a surrounding to the whole line |
Normal | ySs | add a surrounding to the whole line, place it on a new line + indent |
Normal | cs | change a surrounding |
Normal | ds | delete a surrounding |
Visual | s | add a surrounding |
Visual | S | add a surroudning but place tex on new line + indent it |
Insert | <C-s> | add a surrounding |
Insert | <C-s><C-s> | add a new line + surrouding + indent |
好用命令:
命令/按键 | 功能 |
---|---|
单词增加引号 | ysiw"(add surrounding " in word) |
2个单词增加引号 | ys2w" ( add surrounding " for 2 words |
一行增加引号 | yss" |
删除引号 | ds" (delete surrounding "") |
修改"为<html> | cs"<html> ( change surrounding "" to <html></html> |
visiual模式下,为当前选中字符增加引号 | S" |
-
vim-repeat:增强
.
重复执行插件功能。
安装:
Plug 'tpope/vim-repeat'
注:vim-repeat 以默认支持插件:surround.vim,如果还想支持其他插件功能,则进行如下配置:
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
-
NERD Commenter
快速注释代码插件,根据文件类型,自动选择合适的注释风格。
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
let g:NERDCustomDelimiters = { 'java': { 'left': '//'} }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
基础命令:
命令/按键 | 功能 |
---|---|
[count]<leader>cc | Comment out the current line or text selected in visual mode |
[count]<leader>cu | Uncommenets the selected line(s) |
-
markdown-preview.vim
为 vim 添加 Markdown 支持。安装配置成功该插件后,打开 markdown 文件,输入 :MarkdownPreview,则会自动弹出浏览器进行实时预览。
Usage:
" open preview window in markdown buffer
MarkdownPreview
" close the preview window and server
MarkdownPreviewStop
Default Setting:
" path to the chrome or the command to open chrome(or other modern browsers)
let g:mkdp_path_to_chrome = 'C:\Program Files (x86)\Google\Chrome\Application\chrome'
" set to 1, the vim will open the preview window once enter the markdown
" buffer
let g:mkdp_auto_start = 0
" set to 1, the vim will auto open preview window when you edit the
" markdown file
let g:mkdp_auto_open = 0
" set to 1, the vim will auto close current preview window when change
" from markdown buffer to another buffer
let g:mkdp_auto_close = 1
" set to 1, the vim will just refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
let g:mkdp_refresh_slow = 0
" set to 1, the MarkdownPreview command can be use for all files,
" by default it just can be use in markdown file
let g:mkdp_command_for_global = 0
nmap <silent> <F8> <Plug>MarkdownPreview " for normal mode
imap <silent> <F8> <Plug>MarkdownPreview " for insert mode
nmap <silent> <F9> <Plug>StopMarkdownPreview " for normal mode
imap <silent> <F9> <Plug>StopMarkdownPreview " for insert mode
注意: 该插件要求 vim 支持 python,所以要确保 vim 是支持 python,并且电脑要安装 python2 或 python3。可以在 vim 内输入 :echo has('python') || has('python3'),返回 1 表示 vim 已经支持 python。
-
markdown-preview.nvim:为 Vim 提供 markdown 支持(注:要去 Vim 版本 >=8.1 或者使用 Neovim
配置:
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install_sync() },'for':['markdown','vim-plug']}
" set to 1, nvim will open the preview window after entering the markdown buffer
" default: 0
let g:mkdp_auto_start = 0
" set to 1, the nvim will auto close current preview window when change
" from markdown buffer to another buffer
" default: 1
let g:mkdp_auto_close = 1
" set to 1, the vim will refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
" default: 0
let g:mkdp_refresh_slow = 0
" set to 1, the MarkdownPreview command can be use for all files,
" by default it can be use in markdown file
" default: 0
let g:mkdp_command_for_global = 0
" set to 1, preview server available to others in your network
" by default, the server listens on localhost (127.0.0.1)
" default: 0
let g:mkdp_open_to_the_world = 0
" use custom IP to open preview page
" useful when you work in remote vim and preview on local browser
" more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9
" default empty
let g:mkdp_open_ip = ''
" specify browser to open preview page
" default: ''
let g:mkdp_browser = g:chrome
" set to 1, echo preview page url in command line when open preview page
" default is 0
let g:mkdp_echo_preview_url = 0
" a custom vim function name to open preview page
" this function will receive url as param
" default is empty
let g:mkdp_browserfunc = ''
" options for markdown render
" mkit: markdown-it options for render
" katex: katex options for math
" uml: markdown-it-plantuml options
" maid: mermaid options
" disable_sync_scroll: if disable sync scroll, default 0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
" middle: mean the cursor position alway show at the middle of the preview page
" top: mean the vim top viewport alway show at the top of the preview page
" relative: mean the cursor position alway show at the relative positon of the preview page
" hide_yaml_meta: if hide yaml metadata, default is 1
" sequence_diagrams: js-sequence-diagrams options
let g:mkdp_preview_options = {
\ 'mkit': {},
\ 'katex': {},
\ 'uml': {},
\ 'maid': {},
\ 'disable_sync_scroll': 0,
\ 'sync_scroll_type': 'middle',
\ 'hide_yaml_meta': 1,
\ 'sequence_diagrams': {}
\ }
" use a custom markdown style must be absolute path
let g:mkdp_markdown_css = ''
" use a custom highlight style must absolute path
let g:mkdp_highlight_css = ''
" use a custom port to start server or random for empty
let g:mkdp_port = ''
" preview page title
" ${name} will be replace with the file name
let g:mkdp_page_title = '「${name}」'
注:在本人 Win10 系统上,脚本配置完后无法打开浏览器,还需手动在 Neovim 上执行:call mkdp#util#install()
-
vim-airline
这是一款状态栏增强插件,可以让你的 Vim 状态栏非常的美观,同时包括了buffer显示条扩展smart tab line以及集成了一些插件。
vim-airline 其实是 powerline 的 copy,它相比 powerline 有几个好处:它是纯 vim script,powerline 则用到 python;它简单,速度比 powerline 快。
如果还想要更多主题样式,还需需要下载:vim-airline-themes
具体主题 screenshot 可以查看:Screenshots
-
delimitMate(与 vim-multiple-cursors 有冲突,在多光标模式下,输入"
会生成<Plug>delimitMate
,暂时没有找到解决方法,故暂不使用,改用 auto-pairs)
提供引号,大括号,括号自动补全的 Vim 插件。
配置:
inoremap {<CR> {<CR>}<C-o>O
" Use this option to tell delimitMate which characters should be considered
" matching pairs. Read |delimitMateAutoClose| for details.
let delimitMate_matchpairs = "(:),[:],{:},<:>"
au FileType vim,html let b:delimitMate_matchpairs = "(:),[:],{:},<:>"
更多详细配置,请查看:doc
auto-pairs:自动补全/删除括号
fcitx:输入法状态自动切换
vim-json:A better JSON for Vim
vim-css3-syntax:css3 语法支持
vim-coloresque:为 Vim 提供 css/less/sass/html 颜色预览
vim-javascript:为 Vim 提供缩进和 JavaScript 语法支持
emmet-vim:html 扩展工具
例子:
1)新建一个html文件后,输入html:5,然后按<Ctrl+y+,
>(速度要快点),即可生成:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
2)输入p.class#id
,然后按<Ctrl+y+,
>,则会生成:
<p id="id" class="class"></p>
3)输入h1{foo}
, 然后按<Ctrl+y+,
>,则会生成:
<h1>foo</h1>
4)输入h1+h2
, 然后按<Ctrl+y+,
>,则会生成:
<h1></h1>
<h2></h2>
5)输入img^a
, 然后按<Ctrl+y+,
>,则会生成:
<img src="" alt="">
<a href=""></a>
6)输入h1>h2
, 然后按<Ctrl+y+,
>,则会生成:
<h1>
<h2></h2>
</h1>
7)输入(.foo>h1)
,相当于输入div.foo>h1
,然后按<Ctrl+y+,
>,则会生成:
<div class="foo">
<h1></h1>
</div>
8)输入ul>li*3
, 然后后按<Ctrl+y+,
>,则会生成:
<ul>
<li></li>
<li></li>
<li></li>
</ul>
9)输入ul>li.item$*3,然后后按<Ctrl+y+,
>,则会生成:
<ul>
<li class="item1"></li>
<li class="item2"></li>
<li class="item3"></li>
</ul>
更多用法,请参考:TUTORIAL
注:emmet-vim 的基本规则如下:
1. E 代表HTML标签:<E></E>
2. E#id 代表标签E有id属性:<E id=""></E>
3. E.class 代表E有class属性:<E class=""></E>
4. E[attr=foo] 代表某个特定属性:<E foo=""></E>
5. E{info} 代表标签E包含的内容是info:<E>info</E>
6. E>N 代表N是E的子元素:<E><N></N></E>
7. E+N 代表N是E的同级元素:<E></E><N></N>
8. E^N 代表N是E的同级元素:<E></E><N></N>
indentpython.vim:python代码缩进显示
vim-table-mode:markdown 自动表格创建与格式化
配置:
" markdown table improvment
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }
" 配置快捷键
nnoremap <Leader>tm :TableModeToggle<CR>
" markdown-compatible tables
let g:table_mode_corner='|'
function! s:isAtStartOfLine(mapping)
let text_before_cursor = getline('.')[0 : col('.')-1]
let mapping_pattern = '\V' . escape(a:mapping, '\')
let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction
" 插入模式下,按 || 使能插件
inoreabbrev <expr> <bar><bar>
\ <SID>isAtStartOfLine('\|\|') ?
\ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
" 插入模式下,按 __ 失能插件
inoreabbrev <expr> __
\ <SID>isAtStartOfLine('__') ?
\ '<c-o>:silent! TableModeDisable<cr>' : '__'
操作方法:
1)首先,先启动插件::TableModeToggle
,或直接使用快捷键:<Leader>tm
2)在插入模式下,输入一个|
,再输入列名,再输入另一个|
,此时 vim-table-mode 会自动进行格式化,如下图所示:
3)在第二行(无需离开插入模式),输入两次|
。插件会自动创建一条水平线,如下图所示:
4)后续输入内容时,每次输入|
后,插件就会自动依据内容大小自动调整格式,如下图所示:
5)表格完成后,就可以禁止插件功能::TableModeDisable
,或使用快捷键:<Leader>tm
,最简单的是直接在插入模式下输入:两个_
,并切换到 normal 模式即可。
-
vim-multiple-cursors:支持多光标编辑文本
配置:
Plug 'terryma/vim-multiple-cursors'
let g:multi_cursor_use_default_mapping=0
" Default mapping
let g:multi_cursor_start_word_key = '<C-n>'
let g:multi_cursor_select_all_word_key = '<A-n>'
let g:multi_cursor_start_key = 'g<C-n>'
let g:multi_cursor_select_all_key = 'g<A-n>'
let g:multi_cursor_next_key = '<C-n>'
let g:multi_cursor_prev_key = '<C-p>'
let g:multi_cursor_skip_key = '<C-x>'
let g:multi_cursor_quit_key = '<Esc>'
基本使用:
1)normal / visual 模式下:
快捷键 | 功能 |
---|---|
<C-n> | 进入多光标选择模式 |
<C-x> | 忽略当前文本,跳到下一位置 |
<C-p> | 忽略当前文本,跳到上一位置 |
<A-n> | 直接选择所有符合的文本 |
g<C-n> | 忽略单词边界,进行选中 |
g<A-n> | 忽略单词边界,选中所有 |
当文本选中后,就可以使用在 visual 模式下的任何命令进行修改,比如:c
, s
, I
, A
都可以直接进行编辑。
你也可以在选中后,按下 v
,然后就可以直接使用 normal 模式下的命令进行操作。
-
limelight.vim:专注于写作
使用方法:
命令 | 描述 |
---|---|
Limelight [0.0 ~1.0] |
打开 [Limelight] |
Limelight! |
关闭 [Limelight] |
Limelight!! [0.0 ~ 1.0] |
切换 [Limelight] |
配置:
" Hyperfocus-writing in Vim
Plug 'junegunn/limelight.vim'
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240
" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'
" Default: 0.5
let g:limelight_default_coefficient = 0.7
" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 1
" Beginning/end of paragraph
" When there's no empty line between the paragraphs
" and each paragraph starts with indentation
let g:limelight_bop = '^\s'
let g:limelight_eop = '\ze\n^\s'
" Highlighting priority (default: 10)
" Set it to -1 not to overrule hlsearch
let g:limelight_priority = -1
命令 | 描述 |
---|---|
:Goyo |
切换 Goyo |
:Goyo [dimension] |
打开或调整尺寸 |
:Goyo! |
关闭 Goyo |
配置:
" distraction free writing mode
Plug 'junegunn/goyo.vim'
let g:gyo_width=80
let g:goyo_height='85%'
let g:goyo_linenr=0
nmap <Leader>ll :Goyo<CR>
xmap <Leader>ll :Goyo<CR>
"进入goyo模式后自动触发limelight,退出后则关闭
function! s:goyo_enter()
if executable('tmux') && strlen($TMUX)
silent !tmux set status off
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
endif
Limelight
" ...
endfunction
function! s:goyo_leave()
if executable('tmux') && strlen($TMUX)
silent !tmux set status on
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
endif
Limelight!
" ...
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
更多配置方法,请查看:Customization
-
tabular:文本对齐工具
使用方法::Tabularize
,其格式为:
[对齐方式[此方式后添加的空格数量]]
注:对齐方式 左l
、右r
、中c
。需要与前面用/
隔开。
例子:
1)将以下文本以逗号对齐::Tabularize /,
2)将以下代码的注释进行对齐::Tabularize /\/\/
3)将以下文本以冒号进行分割,并将第一部分内容(第一个冒号前)的所有文本右对齐,并添加一个空格;将中间部分内容居中对齐,并添加一个空格;最后将剩余部分文本左对齐,但不添加空格::Tabularize /:/r1c1l0
-
far.vim:文本查找和替换插件
使用方法:
:Far foo bar **/*.py
:Fardo`
命令讲解:
命令 | 描述 |
---|---|
:Far {pattern} {replace-with} {file-mask} [params] |
查找文本 |
:Fardo [params] |
进行文本替换 |
:F {pattern} {file-mask} [params] |
只进行文本查找 |
例子:
1)查找当前文件所在目录的所有含有main
的.py`文件:
:F main **/*.py
2)查找当前文件所在目录的所有含有main
的.py文件,并替换成
"MAIN"`:
" 查找
:Far main MAIN **/*.py
" 替换
:Fardo
-
indentLine:缩进指示线
配置:
" do not highlight conceal color(not background)
let g:indentLine_setColors = 1
" customize conceal color
" Vim
let g:indentLine_color_term = 239
" GVim
let g:indentLine_color_gui = '#A4E57E'
" none X terminal
let g:indentLine_color_tty_light = 7 " (default: 4)
let g:indentLine_color_dark = 1 " (default: 2)
" Background (Vim, GVim)
let g:indentLine_bgcolor_term = 202
" let g:indentLine_char = 'c'
" let g:indentLine_char_list = ['|', '¦', '┆', '┊']
" change conceal behaviour
let g:indentLine_concealcursor = 'inc'
let g:indentLine_conceallevel = 2
-
tagbar:显示代码标签插件
安装:
1)Vim 版本:>= 7.3.1058
2)由于 tagbar 本身并不生成标签文件(tags
file),因此我们需要安装标签文件生成工具,如 Exuberant Ctags 5.5 或者 Universal Ctags(推荐)
3)安装并配置:
Plug 'majutsushi/tagbar', { 'on': 'TagbarOpenAutoClose' }
" set ctags bin path
let g:tagbar_ctags_bin = 'D:\config\ctags\ctags.exe'
" let g:tagbar_ctags_bin = '/usr/bin/ctags'
map <silent> <leader>tb :TagbarOpenAutoClose<CR>
-
vim-signature:标签增强工具
配置:
let g:SignatureMap = {
\ 'Leader' : "m",
\ 'GotoNextLineByPos' : "]<Leader>", " jump to next mark
\ 'GotoPrevLineByPos' : "[<Leader>", " jump to prev mark
\ 'ListBufferMarks' : "m/", " show all marks
\ }
更多自定义配置,请查看:Customization Refer
-
undotree:为 Vim 提供可视化的历史记录。对于大多数编辑器来说,当修改历史为:A -> B -> A -> C 时,最终的结果就是:A -> C。但 Vim 的历史记录并不是上述的线性记录,而是采用类似树形的结构进行记录。因此,A -> B -> A -> C 的全部修改变更都会被保留。借助于 undotree 该插件,我们就可以直接查看修改历史,并选择需要的记录进行回退。
配置:
nnoremap <Leader>ud :UndotreeToggle<CR>
" 持久化历史记录
if has("persistent_undo")
set undodir=$HOME."/.undodir"
set undofile
endif
在历史记录可视化界面中:
Markers | Description |
---|---|
> number < |
表示当前状态 |
{ number } |
表示下一个回退状态(redo) |
[ number ] |
表示最新状态 |
s |
表示保存状态 |
S |
表示最新保存状态 |
内置命令:以下只列举部分常用命令
命令 | 列举 |
---|---|
Files [PATH] |
递归搜索 PATH 目录(默认当前目录),类似:FZF
|
Commands |
列举所有命令 |
Lines [QUERY] |
搜索缓冲区行内容 |
BLines [QUERY] |
搜索当前缓冲区行内容 |
Ag [PATTERN] |
ag 搜索结果(ALT-A 选择全部,ALT-D 取消所有) |
Rg [PATTERN] |
rg 搜索结果(ALT-A 选择全部,ALT-D 取消所有 ) |
History |
列举打开的文件历史记录 |
History: |
列举执行的命令历史记录 |
History/ |
列举执行的搜索历史记录 |
Marks |
搜索标记 |
Colors |
搜索主题 |
Buffers |
搜索缓冲区 |
Tags [QUERY] |
搜索项目 Tags(ctags -R ) |
BTags [QUERY] |
搜索当前项目 Tags(ctags -R ) |
Maps |
列举 normal 模式下的按键映射 |
GFiles [OPTS] |
列举 Git 文件(git ls-files ) |
GFiles? |
列举 Git 文件(git status ) |
Commits |
列举 Git commits(要求安装:fugitive.vim) |
BCommits |
列举当前缓冲区的 Git commits |
注:在搜索到所需文件后,按住CTRL-T
/ CTRL-X
/CTRL-V
可以在新标签 / 水平分割 / 垂直分割 上打开新文件。
安装及配置:
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
if has('nvim') || has('gui_running')
let $FZF_DEFAULT_OPTS .= ' --inline-info'
endif
" Hide statusline of terminal buffer
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" In Neovim, you can set up fzf window using a Vim command
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10new' }
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
nnoremap <silent> <Leader>ag :Ag <C-R><C-W><CR>
xnoremap <silent> <Leader>ag y:Ag <C-R>"<CR>