vim 是 Linux 系统上的最著名的文本/代码编辑器,也是早年的 Vi 编辑器的加强版,
而 gvim 则是其 Windows 版。它的最大特色是完全使用键盘命令进行编辑,脱离了鼠标操作虽然使得入门变得困难,
但上手之后键盘流的各种巧妙组合操作却能带来极为大幅的效率提升。
因此 vim 和现代的编辑器(如 Sublime Text)有着非常巨大的差异,而且入门学习曲线陡峭,
需要记住很多按键组合和命令,如今被看作是高手、Geek们专用的编辑器。尽管 vim 已经是古董级的软件,
但还是有无数新人迎着困难去学习使用,可见其经典与受欢迎程度。另外,由于 vim 的可配置性非常强,
各种插件、语法高亮配色方案等多不胜数,无论作为代码编辑器或是文稿撰写工具都非常给力。
安装
将来要支持python开发,先安装
1
yum install python-devel
这一步比较简单,在centos上面一条命令:
1
2
3
yum install vim
vim --version
VIM - Vi IMproved 7.4
下载源码并进行编译安装(8.0有些问题,暂时不建议安装):
1
2
3
4
5
6
7
8
9
10
wget https://github.com/vim/vim/archive/master.zip
unzip master.zip
cd vim-master
# 下面的python版本支持根据需要删./configure --prefix=/usr/local/vim8
make && make install
# 卸载源码安装的vim,下面替换成你已经装好的vim命令路径make VIMRUNTIMEDIR=/usr/local/vim8/bin/vim
make uninstall
"vundlesetnocompatiblefiletypeoffsetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()Plugin'VundleVim/Vundle.vim'"git interfacePlugin'tpope/vim-fugitive'"filesystemPlugin'scrooloose/nerdtree'Plugin'jistr/vim-nerdtree-tabs'Plugin'kien/ctrlp.vim'"html" isnowfy only compatible with python not python3Plugin'isnowfy/python-vim-instant-markdown'Plugin'jtratner/vim-flavored-markdown'Plugin'suan/vim-instant-markdown'Plugin'nelstrom/vim-markdown-preview'"python sytax checkerPlugin'nvie/vim-flake8'Plugin'vim-scripts/Pydiction'Plugin'vim-scripts/indentpython.vim'Plugin'scrooloose/syntastic'"auto-completion stuff"Plugin 'klen/python-mode'Plugin'Valloric/YouCompleteMe'Plugin'klen/rope-vim'"Plugin 'davidhalter/jedi-vim'Plugin'ervandew/supertab'""code foldingPlugin'tmhedberg/SimpylFold'"Colors!!!Plugin'altercation/vim-colors-solarized'Plugin'jnurmine/Zenburn'callvundle#end()filetypepluginindenton" enables filetype detectionletg:SimpylFold_docstring_preview=1"autocompleteletg:ycm_autoclose_preview_window_after_completion=1"custom keysletmapleader=" "map<leader>g :YcmCompleterGoToDefinitionElseDeclaration<CR>"calltogglebg#map("<F5>")"colorscheme zenburn"set guifont=Monaco:h14letNERDTreeIgnore=['\.pyc$','\~$'] "ignore files in NERDTree"I don't like swap filessetnoswapfile"turn on numberingsetnu"python with virtualenv supportpy<< EOF
importos.pathimportsysimportvimif'VIRTUA_ENV'inos.environ:project_base_dir=os.environ['VIRTUAL_ENV']sys.path.insert(0,project_base_dir)activate_this=os.path.join(project_base_dir,'bin/activate_this.py')execfile(activate_this,dict(__file__=activate_this))EOF
"it would be nice to set tag files by the active virtualenv here":set tags=~/mytags "tags for ctags and taglist"omnicompleteautocmdFileTypepythonsetomnifunc=pythoncomplete#Complete"------------Start Python PEP 8 stuff----------------" Number of spaces that a pre-existing tab is equal to.auBufRead,BufNewFile *py,*pyw,*.c,*.hsettabstop=4"spaces for indentsauBufRead,BufNewFile *.py,*pywsetshiftwidth=4auBufRead,BufNewFile *.py,*.pywsetexpandtabauBufRead,BufNewFile *.pysetsofttabstop=4" Use the below highlight group when displaying bad whitespace is desired.highlightBadWhitespacectermbg=redguibg=red" Display tabs at the beginning of a line in Python mode as bad.auBufRead,BufNewFile *.py,*.pywmatchBadWhitespace/^\t\+/" Make trailing whitespace be flagged as bad.auBufRead,BufNewFile *.py,*.pyw,*.c,*.hmatchBadWhitespace/\s\+$/" Wrap text after a certain number of charactersauBufRead,BufNewFile *.py,*.pyw,settextwidth=100" Use UNIX (\n) line endings.auBufNewFile *.py,*.pyw,*.c,*.hsetfileformat=unix" Set the default file encoding to UTF-8:setencoding=utf-8" For full syntax highlighting:letpython_highlight_all=1syntaxon" Keep indentation level from previous line:autocmdFileTypepythonsetautoindent" make backspaces more powerfullsetbackspace=indent,eol,start"Folding based on indentation:autocmdFileTypepythonsetfoldmethod=indent"use space to open foldsnnoremap<space>za"----------Stop python PEP 8 stuff--------------"js stuff"autocmdFileTypejavascriptsetlocalshiftwidth=2tabstop=2syntaxon"语法高亮显示。setencoding=utf-8sethlsearch"高亮度反白setbackspace=2"可以用Backspace键删除setts=4"tab键等于4个空格setexpandtab"tab键自动变空格settabstop=4setsofttabstop=4setautoindent"自动缩进setpastetoggle=<F9>"插入模式粘贴按F9取消自动缩进setruler"可显示最后一行的状态setshowmode"左下角那一行的状态setnu"可以在每一行的最前面显示行号啦!setbg=dark"显示不同的底色色调"set cursorline "光标所在行一横线setlaststatus=2"显示当前编辑文件名setshowcmdsetmagicsetlazyredrawsethistory=100"历史记录条数sethlsearch"高亮显示搜索结果setincsearch"增量搜索,每次输入一个字母都自动搜"choose and replacevnoremap,sy:%s/<C-R>=escape(@", '\\/.*$^~[]')<CR>/
:tabnew filename在一个新的tab中打开文件
gt在不同的tab中切换,use 5gt to switch to tab 5,从1开始
:tabclose或者:q关闭当前tab
:tabmove将tab移动到指定的位置
:tabe {file} edit specified file in a new tab
:tabc close current tab
:tabc {i} close i-th tab
:tabo close all other tabs
:tabs list all tabs
:tabm 0 move current tab to first
:tabm move current tab to last
:tabm {i} move current tab to position i+1
:tabn go to next tab
:tabp go to previous tab
:tabfirst go to first tab
:tablast go to last tab
虽然Vim支持tab操作,仍有很多人更喜欢缓冲区和分割布局,你可以把缓冲区想象成最近打开的一个文件。
Vim提供了方便访问近期缓冲区的方式,只需要输入:b <buffer name or number>
就可以切换到一个已经开启的缓冲区(此处也可使用自动补全功能),你还可以通过:ls命令查看所有的缓冲区。
o 在已有窗口中打开文件、目录或书签,并跳到该窗口
go 在已有窗口中打开文件、目录或书签,但不跳到该窗口
t 在新 Tab 中打开选中文件/书签,并跳到新 Tab
T 在新 Tab 中打开选中文件/书签,但不跳到新 Tab
i split 一个新窗口打开选中文件,并跳到该窗口
gi split 一个新窗口打开选中文件,但不跳到该窗口
s vsplit 一个新窗口打开选中文件,并跳到该窗口
gs vsplit 一个新 窗口打开选中文件,但不跳到该窗口
! 执行当前文件
O 递归打开选中 结点下的所有目录
x 合拢选中结点的父目录
X 递归 合拢选中结点下的所有目录
e Edit the current dif
D 删除当前书签
P 跳到根结点
p 跳到父结点
K 跳到当前目录下同级的第一个结点
J 跳到当前目录下同级的最后一个结点
k 跳到当前目录下同级的前一个结点
j 跳到当前目录下同级的后一个结点
C 将选中目录或选中文件的父目录设为根结点
u 将当前根结点的父目录设为根目录,并变成合拢原根结点
U 将当前根结点的父目录设为根目录,但保持展开原根结点
r 递归刷新选中目录
R 递归刷新根结点
m 显示文件系统菜单 #!!!然后根据提示进行文件的操作如新建,重命名等
cd 将 CWD 设为选中目录
I 切换是否显示隐藏文件
f 切换是否使用文件过滤器
F 切换是否显示文件
B 切换是否显示书签
q 关闭 NerdTree 窗口
? 切换是否显示 Quick Help