基础配置
" 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
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
请知悉:
在 gvim 中:
.vimrc == _vimrc
~/.vim == $VIM/vimfiles
- 配置 Git,将Git的路径设置到环境变量中,这样,vundle 会自动使用 Git 下载相应的插件进行安装。
详情查看:Vundle for Windows
插件安装
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
-
CtrlSF
全局文件搜索 Vim 插件。类似ag
,awk
,ag
,vimgrep
······
配置:
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 窗口 |
-
CtrlP
Vim的模糊搜索工具,支持文件,缓冲区,MRU(Most Recently Used)文件和标签等的搜索,也支持通过正则表达式搜索(Ctrl-r进行切换)
" 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" |
-
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。
-
vim-airline
这是一款状态栏增强插件,可以让你的Vim状态栏非常的美观,同时包括了buffer显示条扩展smart tab line以及集成了一些插件。
vim-airline 其实是 powerline 的 copy,它相比 powerline 有几个好处:它是纯 vim script,powerline 则用到 python;它简单,速度比 powerline 快。
如果还想要更多主题样式,还需需要下载:vim-airline-themes
具体主题 screenshot 可以查看:Screenshots
-
delimitMate
提供引号,大括号,括号自动补全的 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
网友评论