vimtutor入门学习, vim用户手册与参考手册
在shell下直接运行 $ vimtutor
就可以使用vimtutor来进行入门练习。vim usr_doc与reference 可以在vim命令行中使用 :help
来查询使用。
一本关于vim核心技巧的书:Vm实用技巧 (Practice Vim: Edit Text at the Speed of Thought)
包含了编辑技巧,快速移动技巧,文件管理技巧以及编程相关技巧,以vim提供的核心功能为基础,基本不涉及额外插件的使用
vi/vim使用进阶 http://easwy.com/blog/archives/advanced-vim-skills-catalog/
基础vim scripting
笨方法学Vimscript
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:42:57)
Included patches: 1-52
Extra patches: 8.0.0056
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version with GTK2-GNOME GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +syntax
+arabic +file_in_path +mouse_sgr +tag_binary
+autocmd +find_in_path -mouse_sysmouse +tag_old_static
+balloon_eval +float +mouse_urxvt -tag_any_white
+browse +folding +mouse_xterm +tcl
++builtin_terms -footer +multi_byte +terminfo
+byte_offset +fork() +multi_lang +termresponse
+cindent +gettext -mzscheme +textobjects
+clientserver -hangul_input +netbeans_intg +title
+clipboard +iconv +path_extra +toolbar
+cmdline_compl +insert_expand +perl +user_commands
+cmdline_hist +jumplist +persistent_undo +vertsplit
+cmdline_info +keymap +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python +viminfo
+cscope +lispindent -python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con_gui +lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind +X11
+dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent +xim
+emacs_tags +mouseshape -sniff +xsmp_interact
+eval +mouse_dec +startuptime +xterm_clipboard
+ex_extra +mouse_gpm +statusline -xterm_save
+extra_search -mouse_jsbterm -sun_workshop +xpm
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz -pthread -DORBIT2=1 -D_REENTRANT -I/usr/include/libgnomeui-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gtk-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/x86_64-linux-gnu/gnome-vfs-2.0/include -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/cairo -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/libpng12 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -I/usr/include/tcl8.6 -D_REENTRANT=1 -D_THREAD_SAFE=1 -D_LARGEFILE64_SOURCE=1
Linking: gcc -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lfreetype -lgconf-2 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl -lselinux -lacl -lattr -lgpm -ldl -L/usr/lib -llua5.2 -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm -L/usr/lib
比如看到 +python
代表包含了python支持的特性(feature)
在vim命令行中查看是否支持某项特性可以使用 :echo has('python')
,如果输出 1 则表示构建出的 vim 已支持 python,反之,0 则不支持。
vim 自身希望通过在 .vim/ 目录中预定义子目录管理所有插件(比如,子目录 doc/存放插件帮助文档、plugin/ 存放通用插件脚本),vim的各插件打包文档中通常也包含上述两个(甚至更多)子目录,用户将插件打包文档中的对应子目录拷贝至 .vim/ 目录即可完成插件的安装。
具体参考
4.3.1 一般安装方法
安装插件的方法,
1.一般是 把源文件解压到 ~/.vim 就可以了
4.3.2 通过vundle 管理
同过一个插件管理所有的插件 以官网 的readme 为准
https://github.com/VundleVim/Vundle.vim
网上有些例子里面的 命令和配置的和现在官网上的不一样了,
比如 下面这个链接里面 对与vimrc 文件配置的命令 似乎有点不一样 用 vundle 还是 plugin,
现在github上例子用的plugin 还有相关命令 也是变成PluginList 等 而不是 VundleList
http://blog.csdn.net/jiaolongdy/article/details/17889787/
附:参考文献
Vundle项目
vim-scripts维护的GitHub repo
配色方案
vim中
:colorscheme 显示 当前配色
:colorscheme {yourscheme} 设置 你想要的配饰
gvim中 可以通过菜单设置
?如何列出所有可用的配色?
配色方案可以和你正在使用的基础配色共同使用。GUI模式可以尝试solarized方案, 终端模式可以尝试Zenburn方案:
Plugin ‘jnurmine/Zenburn’
Plugin ‘altercation/vim-colors-solarized’
接下来,只需要添加一点逻辑判断,确定什么模式下使用何种方案就可以了:
if has(‘gui_running’)
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
用NerdTree时隐藏 .pyc文件
还想隐藏.pyc文件?那么再添加下面这行代码吧:
let NERDTreeIgnore=[‘.pyc ′,′\~ ’, ‘.swp$’] “ignore files in NERDTree
打开 语法高亮
:syntax on
for python
语法高亮加强???不懂 这样就可支持内置函数,数字,空格,异常的语法??
” For full syntax highlighting:
let python_highlight_all=1
syntax on
显示行开启显示行号:
set nu
代码折叠
:help usr_28.txt
:help fold.txt
http://blog.csdn.net/wooin/article/details/2004470
手动折叠
Try it out: Position the cursor in a paragraph and type:
zfap
You will see that the paragraph is replaced by a highlighted line. You have
created a fold. zf is an operator and ap a text object selection. You
can use the zf operator with any movement command to create a fold for the
text that it moved over. zf also works in Visual mode.
To view the text again, open the fold by typing:
zo
And you can close the fold again with:
zc
zf F-old creation
zo O-pen a fold
zc C-lose a fold
za When on a closed fold: open it. When folds are nested, you
may have to use “za” several times. When a count is given,
that many closed folds are opened.
When on an open fold: close it and set ‘foldenable’. This
will only close one level, since using “za” again will open
the fold. When a count is given that many folds will be
closed (that’s not the same as repeating “za” that many
times).
zr This will R-educe the folding. The opposite is:
zm This folds M-ore. You can repeat "zr" and "zm" to open and close nested folds
of several levels.
If you have nested several levels deep, you can open all of them with:
zR This R-educes folds until there are none left. And you can close all folds
with:
zM This folds M-ore and M-ore.
set foldmethod=syntax
set foldlevel=100 ” 启动vim时不要自动折叠代码
试了一下, c文件 管用, python文件怎么不管用???
–》 原因 The Python syntax definition that comes bundled with Vim doesn’t contain any fold directives at all,
python 折叠
针对pythod的折叠插件
tmhedberg/SimpylFold
光用 foldmethod=indent 效果不是太好,对此进行改进的插件
https://github.com/tmhedberg/SimpylFold
Plugin ‘tmhedberg/SimpylFold’
不要忘记执行安装命令::PluginInstall
专业贴士: 希望看到折叠代码的文档字符串?
let g:SimpylFold_docstring_preview=1
tagbar
https://github.com/majutsushi/tagbar/
TagList
https://github.com/vim-scripts/taglist.vim
tagbar?? 功能类似? 也是依赖tags的,ctags支持的文件 它就支持
https://github.com/majutsushi/tagbar
Plug ‘majutsushi/tagbar’ 也有python的用户使用这个
语法检查
syntastic(https://github.com/scrooloose/syntastic)
SuperTab (如果用了 youcompleteme来做代码补全就不需要了)
通过tab按键 实现补全,上面提到过
自动补全
davidhalter/jedi-vim
python autocompletion 和 goto definition
自动补全
https://github.com/Valloric/YouCompleteMe
‘Valloric/YouCompleteMe’ 这个就不需要supertab了
https://github.com/Valloric/YouCompleteMe
支持Python自动补全的最好插件是YouCompleteMe。我们再次使用Vundle安装:
Bundle ‘Valloric/YouCompleteMe’
YouCompleteMe插件其实底层使用了一些不同的自动补全组件(包括针对Python开发的Jedi),另外要安装一些C库才能正常工作。插件官方文档提供了很好的安装指南,我就不在这里重复了。切记跟随文档的步骤进行安装。
安装完成后,插件自带的设置效果就很好,但是我们还可以进行一些小的调整:
let g:ycm_autoclose_preview_window_after_completion=1
map g :YcmCompleter GoToDefinitionElseDeclaration
上面的第一行确保了在你完成操作之后,自动补全窗口不会消失,第二行则定义了“转到定义”的快捷方式。
snipmate https://github.com/garbas/vim-snipmate
插入代码片段?
python 缩进
tabstop 等的设置 要设置成4个空格的宽度
符合 pep8
https://github.com/vim-scripts/indentpython.vim
pep8 代码风格检查
还可以通过这个小巧的插件,添加PEP8代码风格检查:
Plugin ‘nvie/vim-flake8’
vim-flake8
https://github.com/nvie/vim-flake8
vim-flake8 is a Vim plugin that runs the currently open file through Flake8, a static syntax and style checker for Python source code. It supersedes both vim-pyflakes and vim-pep8.
Flake8 is a wrapper around PyFlakes (static syntax checker), PEP8 (style checker) and Ned’s MacCabe script (complexity checker).
和下面的python-mode有重合?
结合上面的提到的 语法检查 syntastic
标识不必要的空白和tab?
” Use the below highlight group when displaying bad whitespace is desired.
highlight BadWhitespace ctermbg=red guibg=red
” Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile .py,.pyw match BadWhitespace /^\t+/
” Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile .py,.pyw,.c,.h match BadWhitespace /\s+$/
综合方案 Plugin ‘klen/python-mode’ ?
https://github.com/klen/python-mode. 重定向到
https://github.com/python-mode/python-mode
语法检查,pep8风格,重构refactoring,代码补全依靠 rope 以及这个插件? https://github.com/python-rope/ropevim
用了很多其他python库文件,去检查
代替了 klen/rope-vim
超级搜索
想要在Vim中搜索任何文件?试试ctrlP插件吧:
Plugin ‘kien/ctrlp.vim’
Git集成
想要在Vim中执行基本的Git命令?vim-fugitive插件则是不二之选。
Plugin ‘tpope/vim-fugitive’
请看Vimcasts的这部视频,了解更多情况 。
Powerline状态栏
Powerline是一个状态栏插件,可以显示当前的虚拟环境、Git分支、正在编辑的文件等信息。
这个插件是用Python编写的,支持诸如zsh、bash、tmux和IPython等多种环境。
Plugin ‘Lokaltog/powerline’, {‘rtp’: ‘powerline/bindings/vim/’}
所需即所获:像 IDE 一样使用 vim
主要是针对C/C++的,但是有些功能是通用的,完整的介绍了程序开发所需的各个功能和如何通过配置vim来实现,讲的很系统。
Vim与Python真乃天作之合:打造强大的Python开发环境
Vim as a python IDE 主要借助插件python-mode
两个命令把 Vim 打造成 Python IDE
https://github.com/fisadev/fisa-vim-config
http://fisadev.github.io/fisa-vim-config/
用 Vim 写 Python 的最佳实践是什么?
https://www.zhihu.com/question/19655689
手把手教你把Vim改装成一个IDE编程环境(图文)