vim: 学习资料——基础

来源:互联网 发布:netstat -ano linux 编辑:程序博客网 时间:2024/05/17 06:49

1. Ubuntu下 各个版本的 vim

ubuntu 14.04
root@sha-Inspiron-3847:~# vim
The program 'vim' can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-athena
* vim-gtk
* vim-nox

默认安装的是 vim-tiny
root@sha-Inspiron-3847:~# which vi
/usr/bin/vi
root@sha-Inspiron-3847:~# ll /usr/bin/vi
lrwxrwxrwx 1 root root 20 4月 30 2016 /usr/bin/vi -> /etc/alternatives/vi*
root@sha-Inspiron-3847:~# ll /etc/alternatives/vi*
lrwxrwxrwx 1 root root 17 4月 30 2016 /etc/alternatives/vi -> /usr/bin/vim.tiny*

ubuntu下预装的版本是vim.tiny,这个更靠近纯vi了,不能使用小键盘和方向键,在编辑模式下,移动光标会变成A B C D等字符并换行。

vim

后来自己装了 vim 完整版

------注意最后修改了 alternative
root@sha-Inspiron-3847:~# apt-get upgrade
root@sha-Inspiron-3847:~# apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libbonobo2-0 libbonobo2-common libgconf2-4 libgnome2-0 libgnome2-bin
libgnome2-common libgnomevfs2-0 libgnomevfs2-common libidl-common libidl0
libntdb1 liborbit-2-0 liborbit2 python-ntdb
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
vim-runtime
Suggested packages:
ctags vim-doc vim-scripts
The following NEW packages will be installed:
vim vim-runtime
0 upgraded, 2 newly installed, 0 to remove and 11 not upgraded.
Need to get 5,838 kB of archives.
After this operation, 28.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main vim-runtime all 2:7.4.052-1ubuntu3.1 [4,882 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main vim amd64 2:7.4.052-1ubuntu3.1 [955 kB]
Fetched 5,838 kB in 5s (1,075 kB/s)
Selecting previously unselected package vim-runtime.
(Reading database ... 170221 files and directories currently installed.)
Preparing to unpack .../vim-runtime_2%3a7.4.052-1ubuntu3.1_all.deb ...
Adding 'diversion of /usr/share/vim/vim74/doc/help.txt to /usr/share/vim/vim74/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim74/doc/tags to /usr/share/vim/vim74/doc/tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:7.4.052-1ubuntu3.1) ...
Selecting previously unselected package vim.
Preparing to unpack .../vim_2%3a7.4.052-1ubuntu3.1_amd64.deb ...
Unpacking vim (2:7.4.052-1ubuntu3.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up vim-runtime (2:7.4.052-1ubuntu3.1) ...
Processing /usr/share/vim/addons/doc
Setting up vim (2:7.4.052-1ubuntu3.1) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
vim包信息
sha@sha-Inspiron-3847:~/Work/PythonDemos$ apt-cache show vim
Package: vim
Priority: optional
Section: editors
Installed-Size: 2185
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
Architecture: amd64
Version: 2:7.4.052-1ubuntu3.1
Provides: editor
Depends: vim-common (= 2:7.4.052-1ubuntu3.1), vim-runtime (= 2:7.4.052-1ubuntu3.1), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.4),libpython2.7 (>= 2.7), libselinux1 (>= 1.32), libtinfo5
Suggests: ctags, vim-doc, vim-scripts
Filename: pool/main/v/vim/vim_7.4.052-1ubuntu3.1_amd64.deb
Size: 955402
MD5sum: 0cb0afb28c718636c6dbc5445f5591ce
SHA1: d97bf79e2b68eee339f7712402375d27c378e38b
SHA256: 5baed263442197c6d38a661cf3d482d03c0b85c4a04f2e951229a08e8215849d
Description-en: Vi IMproved - enhanced vi editor
Vim is an almost compatible version of the UNIX editor Vi.
.
Many new features have been added: multi level undo, syntax
highlighting, command line history, on-line help, filename
completion, block operations, folding, Unicode support, etc.
.
This package contains a version of vim compiled with a rather
standard set of features. This package does not provide a GUI
version of Vim. See the other vim-* packages if you need more
(or less).
Description-md5: 59e8b8f7757db8b53566d5d119872de8
Homepage: http://www.vim.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: ubuntu-usb, cloud-image, server, edubuntu-desktop-gnome, edubuntu-usb

vim.basic 应该也支持python? 编译的时候 用了 libpython
sha@sha-Inspiron-3847:~/Work/PythonDemos$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:43:18)
Included patches: 1-52
Extra patches: 8.0.0056
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version without 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 -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
+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"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim -lm -ltinfo -lnsl -lselinux -lacl -lattr -lgpm -ldl -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions

关注 一下 vim-gnome 和 vim-gtk 带 gui 吧,

--vim-gnome

vim-gnome 包信息

sha@sha-Inspiron-3847:~/Work/PythonDemos$ apt-cache show vim-gnome
Package: vim-gnome
Priority: extra
Section: editors
Installed-Size: 2570
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
Architecture: amd64
Source: vim
Version: 2:7.4.052-1ubuntu3.1
Provides: editor, gvim, vim, vim-lua, vim-perl,vim-python, vim-ruby, vim-tcl
Depends: vim-gui-common (= 2:7.4.052-1ubuntu3.1), vim-common (= 2:7.4.052-1ubuntu3.1), vim-runtime (= 2:7.4.052-1ubuntu3.1), libacl1 (>= 2.2.51-8), libbonoboui2-0 (>= 2.15.1), libc6 (>= 2.15), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.12.0), libgnome2-0 (>= 2.17.3), libgnomeui-0 (>= 2.22.0), libgpm2 (>= 1.20.4), libgtk2.0-0 (>= 2.24.0), libice6 (>= 1:1.0.0), liblua5.2-0, libpango-1.0-0 (>= 1.14.0), libperl5.18 (>= 5.18.2),libpython2.7 (>= 2.7), libruby1.9.1 (>= 1.9.2.0), libselinux1 (>= 1.32), libsm6, libtcl8.6 (>= 8.6.0), libtinfo5, libx11-6, libxt6
Suggests: cscope, vim-doc, ttf-dejavu, gnome-icon-theme
Filename: pool/main/v/vim/vim-gnome_7.4.052-1ubuntu3.1_amd64.deb
Size: 1094788
MD5sum: c3401ff9a41c61b32b7775b3381cef20
SHA1: f2ad6c8c304145d5658b767b9589f46aca2b88a2
SHA256: 909e95085f5edf29482550e080554c4ca4391164d9691fe90612916e3bb6a966
Description-en: Vi IMproved - enhanced vi editor -with GNOME2 GUI
Vim is an almost compatible version of the UNIX editor Vi.
.
Many new features have been added: multi level undo, syntax
highlighting, command line history, on-line help, filename
completion, block operations, folding, Unicode support, etc.
.
This package contains a version of vim compiled with a GNOME2 GUI
and support for scripting with Lua, Perl, Python, Ruby, and Tcl.
Description-md5: cd4a76134bce59404c52749b68c94208
Homepage: http://www.vim.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
-》似乎是重新编译过的 vim 还多了 gvim 和vim-python 等

装一下 vim-gnome 看看 个gvim 什么样,可能又会改变一些 vim 相关的软链接
sha@sha-Inspiron-3847:~/Work/PracticeVim/code$ sudo apt-get install vim-gnome
[sudo] password for sha:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libgconf2-4 libntdb1 python-ntdb
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libbonoboui2-0 libbonoboui2-common libgnomecanvas2-0 libgnomecanvas2-common
libgnomeui-0 libgnomeui-common libruby1.9.1 libyaml-0-2 ruby ruby1.9.1
vim-gui-common
Suggested packages:
ri ruby-dev ruby1.9.1-examples ri1.9.1 graphviz ruby1.9.1-dev ruby-switch
cscope vim-doc ttf-dejavu
The following NEW packages will be installed:
libbonoboui2-0 libbonoboui2-common libgnomecanvas2-0 libgnomecanvas2-common
libgnomeui-0 libgnomeui-common libruby1.9.1 libyaml-0-2 ruby ruby1.9.1
vim-gnome vim-gui-common
0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,380 kB of archives.
After this operation, 17.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]
。。。。
Setting up libruby1.9.1 (1.9.3.484-2ubuntu1.3) ...
Setting up vim-gnome (2:7.4.052-1ubuntu3.1) ...
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/editor (editor) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/gvim (gvim) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/gview (gview) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/rgview (rgview) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/rgvim (rgvim) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/evim (evim) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/eview (eview) in auto mode
update-alternatives: using /usr/bin/vim.gnome to provide /usr/bin/gvimdiff (gvimdiff) in auto mode


sha@sha-Inspiron-3847:~/Work/PracticeVim/code$ 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

gvim

--vim-gtk

sha@sha-Inspiron-3847:~/Work/PythonDemos$ apt-cache show vim-gtk
Package: vim-gtk
Priority: extra
Section: universe/editors
Installed-Size: 2562
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
Architecture: amd64
Source: vim
Version: 2:7.4.052-1ubuntu3.1
Provides: editor, gvim, vim, vim-lua, vim-perl, vim-python, vim-ruby, vim-tcl
Depends: vim-gui-common (= 2:7.4.052-1ubuntu3.1), vim-common (= 2:7.4.052-1ubuntu3.1), vim-runtime (= 2:7.4.052-1ubuntu3.1), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.12.0), libgpm2 (>= 1.20.4), libgtk2.0-0 (>= 2.24.0), libice6 (>= 1:1.0.0), liblua5.2-0, libpango-1.0-0 (>= 1.14.0), libperl5.18 (>= 5.18.2), libpython2.7 (>= 2.7), libruby1.9.1 (>= 1.9.2.0), libselinux1 (>= 1.32), libsm6, libtcl8.6 (>= 8.6.0), libtinfo5, libx11-6, libxt6
Suggests: cscope, vim-doc, ttf-dejavu, gnome-icon-theme
Filename: pool/universe/v/vim/vim-gtk_7.4.052-1ubuntu3.1_amd64.deb
Size: 1093074
MD5sum: 14de54f06f1fa620377684611a4a701f
SHA1: bc760727c1e7fc1bf61aeeaa05fc6122f147f4fe
SHA256: 7f97346b8d80560050df805bde17375d80e8aaccd721020116eddef98d050b2d
Description-en: Vi IMproved - enhanced vi editor -with GTK2 GUI
Vim is an almost compatible version of the UNIX editor Vi.
.
Many new features have been added: multi level undo, syntax
highlighting, command line history, on-line help, filename
completion, block operations, folding, Unicode support, etc.
.
This package contains a version of vim compiled with a GTK2 GUI
and support for scripting with Lua, Perl, Python, Ruby, and Tcl.
Description-md5: 2c68094b1efcc4728d91370c494d0111
Homepage: http://www.vim.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

各版本区别

注意上面各个包信息中 红色的部分,看起来主要是 gui 以及 langage support 的 区别
--》 vim-gnome 和 vim-gtk 看起来 提供的功能差不多,就是 gui 的框架略不同? 但是 gnome 也是 基于 gtk呀??
https://askubuntu.com/questions/33260/difference-between-vim-gtk-and-vim-gnome
Both packages provide the same application, but compiled with different dependencies (e.g. vim-gnome depends on libgnome2). Vim-gtk is important only to people who use Kubuntu (or some lightweight desktop environment) and don't want to install GNOME libraries. If you use the standard Ubuntu desktop, the dependencies are already present, and you can safely use vim-gnome. I agree that it could be confusing.


langage support 有什么用? scripting support

https://askubuntu.com/questions/281886/what-are-the-differences-between-the-different-vim-packages-available-in-ubuntu
Python support
Before 16.04, the above packages (other than vim-tiny) included Vim with scripting support for Python 2. From 16.04 onwards, they all support Python 3, and there are corresponding *-py2packages (vim-gnome-py2, for example) which provide a Vim command with Python 2 support. Both can be installed together, and the commands will be, for example, vim.gnome and vim.gnome-py2 respectively. Otherwise, the *-py2 packages provide the same feature set as the corresponding packages.

Extra scripting languages are need for some cool plugins out there

关于剪贴板 clipboard

用 vim -version 可以看到 版本支持的feature
比如上面的 vim.basic 里 是 -clipboard

那我装的 vim.basic 应该不支持, 确实没看到 + 寄存器,但是 可以直接 复制出系统见贴版的内容啊,插入模式下 shift+insert 或者 直接右键菜单粘帖

http://blog.csdn.net/gaoyang_feifei/article/details/8027491
https://www.zhihu.com/question/54654847

2. vim 官方文档

2.1 vimtutor

30分钟的 简单练习,熟悉基本操作
sha@sha-Inspiron-3847:~$ vimtutor

2.2 user manual 与 reference

关于文档,分两种
1. 用户手册 usr_doc
面向任务的使用说明书,由简入繁,能象书一样从头读到尾。
2. 参考手册 reference
详细描述 Vim 的每一个命令的详细资料。

reference 中重要的
intro.txt

index.txt*
This file contains a list of all commands for each mode, with a tag and a
short description. The lists are sorted on ASCII value.


user manual 重要的章节
ch3 移动光标
ch5 选项 vmrc 插件
ch8 分割窗口
ch10 修改 排版
ch21 会话
ch22 文件浏览器 目录结构显示
ch24 快速插入 补全
ch25 编辑带格式的文本
ch28 折叠
ch30 编辑 c 程序
ch40 map autocmd
ch41 vim 脚本 插件 函数 表达式

如何查看这些文档: 有以下几种途径可以看到这些文档

vim内使用帮助

打开 vim 然后
:help<Enter> or <F1> for on-line help 总入口 也就是 help.txt,然后可以链接到其他文档
:help user-manual<Enter># 进入 usr_toc.txt user manual 的 目录

sha@sha-Inspiron-3847:/usr/share/vim/vim74/doc$ ls
arabic.txt if_mzsch.txt os_unix.txt tabpage.txt usr_27.txt
autocmd.txt if_ole.txt os_vms.txt tags usr_28.txt
change.txt if_perl.txt os_win32.txt tagsrch.txt usr_29.txt
cmdline.txt if_pyth.txt pattern.txt tags.vim-tiny usr_30.txt
debugger.txt if_ruby.txt pi_getscript.txt term.txt usr_31.txt
debug.txt if_sniff.txt pi_gzip.txt tips.txt usr_32.txt
develop.txt if_tcl.txt pi_netrw.txt todo.txt usr_40.txt
diff.txt indent.txt pi_paren.txt uganda.txt usr_41.txt
digraph.txt index.txt pi_spec.txt undo.txt usr_42.txt
editing.txt insert.txt pi_tar.txt usr_01.txt usr_43.txt
eval.txt intro.txt pi_vimball.txt usr_02.txt usr_44.txt
farsi.txt map.txt pi_zip.txt usr_03.txt usr_45.txt
filetype.txt mbyte.txt print.txt usr_04.txt usr_90.txt
fold.txt message.txt quickfix.txt usr_05.txt usr_toc.txt
ft_ada.txt mlang.txt quickref.txt usr_06.txt various.txt
ft_sql.txt motion.txt quotes.txt usr_07.txt version4.txt
gui.txt netbeans.txt README.Debian usr_08.txt version5.txt
gui_w16.txt options.txt recover.txt usr_09.txt version6.txt
gui_w32.txt os_390.txt remote.txt usr_10.txt version7.txt
gui_x11.txt os_amiga.txt repeat.txt usr_11.txt vi_diff.txt
hangulin.txt os_beos.txt rileft.txt usr_12.txt vim2html.pl
hebrew.txt os_dos.txt russian.txt usr_20.txt visual.txt
helphelp.txt os_mac.txt scroll.txt usr_21.txt windows.txt
help.txt os_mint.txt sign.txt usr_22.txt workshop.txt
help.txt.vim-tiny os_msdos.txt spell.txt usr_23.txt
howto.txt os_os2.txt sponsor.txt usr_24.txt
if_cscop.txt os_qnx.txt starting.txt usr_25.txt
if_lua.txt os_risc.txt syntax.txt usr_26.txt

--》VIM7.3添加中文帮助文档 还没试过

html文档

中文 http://vimcdoc.sourceforge.net/
http://vimdoc.sourceforge.net/htmldoc/usr_toc.html

source forge 经常打不开!

pdf版本

sourceforge 上下载的
在电子教程-》linux-》vim 里面下了 reference 和
manual: usr_doc
referece: 完整

3.其他好用的 教程

书 "VIM实用技巧 practical vim: edit text at the speed of thought"
1-7章 为基础一点的操作
下载了英文版 pdf
示例和代码https://pragprog.com/titles/dnvim/source_code
已经下载放在
sha@sha-Inspiron-3847:~/Work/PracticeVim$ ll
total 28
drwxrwxr-x 3 sha sha 4096 Sep 12 20:21 ./
drwxrwxr-x 4 sha sha 4096 Sep 12 15:58 ../
drwxr-xr-x 22 sha sha 4096 Apr 21 2014 code/
-rw-rw-r-- 1 sha sha 11669 Sep 12 20:21 dnvim-code.tgz

别人写的这本书的笔记
http://www.jianshu.com/p/42ef98846b11

vi/vim使用进阶, 介绍了 一些插件? 目录http://easwy.com/blog/archives/advanced-vim-skills-catalog/
此博文的作者翻译了 vim实用技巧https://www.amazon.cn/%E5%9B%BE%E4%B9%A6/dp/B00JONY3W0

4. VIM 基础知识与实用小技巧

vim键盘图



个人使用VIM的一些总结

4.1 vim的几种基本模式

这里讲四种,还有其他的 详细见 :help vim-modes

4.1.1 普通模式 normal mode

In Normal mode you can enter all the normal editor commands. If you start the editor you are in this mode (unless you have set the 'insertmode' option, see below). This is also known as command mode

默认先进入普通模式,其他模式下 按<Esc> 键返回普通模式
普通模式下的命令 有 操作符命令 和 动作命令
操作符命令:
比如 c 修改, d 删除 , y复制到寄存器,p 粘帖,x,
动作命令 motion:
控制光标的移动 ? 比如 h 左, j 下, k 上, l右, $行尾巴,w下一词首,<c - f> / <c - b>上翻/下翻 (同PgUp/PgDn?)
G 到最后一行?
命令重复的次数 动作命令前 加上数字 比如 3h: 向左移动3次, 4w:移动到往后第4个词首
结合使用: d2w 删除到往后第2个词首

4.1.2 插入模式 insert mode

In Insert mode the text you type is inserted into the buffer. See |Insert-mode|.If the 'showmode' option is on "-- INSERT --" is shown at the bottom of the window.
普通模式下 按 i, o, a等 进入 插入模式

4.1.3 可视模式 visual mode

This is like Normal mode, but the movement commands extend a highlighted area.When a non-movement command is used, it is executed for the highlighted area.See |Visual-mode|.If the 'showmode' option is on "-- VISUAL --" is shown at the bottom of the window.

分 字符可视模式: v 用来切换; 行可视模式: V 用来切换; 列块可视模式: <C - v> (即 Ctrl + v)切换

4.1.4 命令行模式 command line mode

普通模式下 按 : 进入命令行模式
可以执行 vim 的Ex命令
:{cmd}
比如,用 :set 命令改变vim的 配置选项
:set mouse=ato enable the mouse in all mode (in xterm or GUI). 那就可以用鼠标来控制光标的移动 这个有用,还有其他值可选 参见 :h mouse
:set number 显示行号
详细见 3.3

可以用 反引号 (backtick expansion)来 执行shell 命令,并把结果作为参数 传递给 vim 命令
比如 :{cmd} `{shell cmd}`
:args `cat .chapters`
参见 :h backtick-expansino


可以执行shell 命令
:!{cmd}Execute {cmd} with the shell. See also the 'shell' and 'shelltype' option.

可以进行正则表达式查找
/ 正向 ? 反向


4.2 配置vim的选项

参考书 Appendix

4.2.1在命令行模式下动态修改vim的设置

vim有很多选项可以用来定制其行为
--》完整的选项列表 参见 :h option-list
--》如何配置选项 参见 :h:options
选项分为 toggle option(布尔选项),number option, string option
:se[t] {option}={value} or :se[t] {option}:{value}
Set string or number option to {value}.
:se[t] {option}+={value} *:set+=*
Add the {value} to a number option, or append the {value} to a string option. When the option is a comma separated list, a comma is added, unless the value was empty.
:se[t] {option}-={value} *:set-=*
Subtract the {value} from a number option, or remove the {value} from a string option, if it is there.
:se[t] {option}? Show value of {option}.

:se[t] {option} Toggle option: set, switch it on. Number option: show value. String option: show value.
:se[t] no{option} Toggle option: Reset, switch it off.

set 是全局设置, setlocal 只为当前缓冲区 或窗口设置,在后面提到的 filetype plugin中也很有用


例子
:set mouse=a 设置在所有模式下 激活鼠标
:set tabstop=2
:set nu 设置显示行号
:set foldmethod? 显示 foldmethod=manual
:set compatible? 显示 nocompatible
:set fileencodings? 显示fileencodings=ucs-bom,utf-8,default,latin1

4.2.2 将配置信息写入vimrc文件

可以将定制化的选项写入文件加以保存,然后 通过 :source {file} 命令 将设置项应用于当前会话
.vimrc 文件会在vim启动时自动被加载
在 vim 内部打开 vimrc 文件 :edit $MYVIMRC我试的没成功,可能因为没有目前没有创建过这个文件?


4.2.3 为特定类型文件应用个性化设置 FileType 与 autocmd(缩写au)

比如不同文件使用不同的缩进方式
这里 ruby文件 两个空格缩进,javascript文件 4个空格缩进
filetype on
autocmd FileType ruby setlocal ts=2 sts=2 sw=2 et "这里用了缩写ts:tabstop sts:softtabstop sw:shiftwidth et:expandtab
autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noet
!!?注意这里用了 setlocal, 这种文件类型事件的处理是不是都要用 local 应该是,

还可以用文件类型插件 ftplugin 来为不同类型文件做定制,如果特定类型文件的定制很多的话
这一样 就不在vimrc中设置,而是 在 ~/.vim/after/ftplugin/javascript.vim
要使用 plugin 则必须保证 插件功能激活
filetype plugin on
更多参见 :help ftplugin-name 关于 plguin 的位置

:help ftplugin
*41.12* Writing a filetype plugin *write-filetype-plugin* *ftplugin*

A filetype plugin is like a global plugin,except that it sets options and defines mappings for the current buffer only. See |add-filetype-plugin| for
how this type of plugin is used.
....
Now write this in the "after" directory, so that it gets sourced after the distributed "vim.vim" ftplugin |after-directory|. For Unix this would be
"~/.vim/after/ftplugin/vim.vim". Note that the default plugin will have set "b:did_ftplugin", but it is ignored here.
OPTIONS
To make sure the filetype plugin only affects the current buffer use the >
:setlocal

??? 这里为什么是 .vim/after/ftplugin/ :help ftplugin-name 里面说的是 .vim/ftplugin/

4.3 vim 多文件管理,缓冲区 buffer,窗口,标签页

文件与缓冲区的区别

Just like any other text editor, Vim allows us to read files, edit them, and save our changes. When we discuss our workflow, it’s tempting to say that we’re editing a file, but that’s not what we’re actually doing.
Instead, we’re editing an in-memory representation of a file, which is called a buffer in Vim’s terminology.

Files are stored on the disk, whereas buffers exist in memory. When we open a file in Vim, its contents are read into a buffer, whichtakes the same name as the file. Initially, the contents of the buffer will be identical to those of the file, but the two will diverge as we make changes to the buffer.

4.3.1 打开多个文件与缓冲区管理

4.3.1.1如何打开多个文件

1argument list模式,打开Vim编辑器时,携带多个文件路径参数。
例如
vim test1 test2 test3
运行 :arg
显示
[test1] test2 test 3

这个 argument list 是可以改变的, 也就说 使用不带参数的 vim 以后 还可以修改 arglist 打开其他文件
参见 书 技巧 37
arg: {arglist}其中 arglist 可以用 通配符来 匹配多个文件, 这样 可以用来打开 比如指定类型文件爱你
这样会一下清空并重新设置参数列表, 但是 清空参数列表,[那些原来列表中的文件依然在缓冲区里面]

参见 :help starstar-wildcard
比如 :args **/*.js **/*.css 匹配以及递归子目录下的 js和css 文件
arg命令 的 参数还可以是 一个 shell 命令执行的结果 比如使用 arg: `cat .chapters`

遍历参数列表中的文件
:n[ext]切换到下一个文件
:N[ext]切换到上一个文件 同 :prev
:2n切换到下下个文件

:[count]n[ext] [++opt] [+cmd] *:n* *:ne* *:next* *E165* *E163*
Edit [count] next file.This fails when changes have been made and Vim does not want to |abandon| the current buffer. Also see |++opt| and |+cmd|. {Vi: no count or ++opt}.
:[count]n[ext]![++opt] [+cmd]
Edit [count] next file,discard any changes to the buffer. Also see |++opt| and |+cmd|. {Vi: no count or ++opt}.

[count]N[ext][count] [++opt] [+cmd] *:Next* *:N* *E164*
Edit [count] previous file in argument list.This fails when changes have been madeand Vim does not want to |abandon| the current buffer. Also see |++opt| and |+cmd|. {Vi: no count or ++opt}.
加上!会强制 切换, 那修改了的缓冲区内容呢? 参考下面的 “4.4.1.3 隐藏的缓冲区”



--》启动vim的时候以分割窗口的方式打开多个文件 (关于分割窗口详见 3.4.2)
选项
-o[N] Open N windows (default: one for each file)
-O[N] Like -o but split vertically
例子: vim -o test1 test2

2buffer list模式,就是在进入Vim编辑器后,打开多个缓冲区进行编辑。
参见 书 第7章

:edit {filename} 以文件路径打开任何文件 载入缓冲区
:write 把缓冲区内容写入磁盘

4.3.1.2 管理缓冲区 缓冲区列表与缓冲区切换

http://www.cnblogs.com/MuyouSome/archive/2013/04/30/3051744.html
缓冲区(Buffer)是一块内存区域,里面存储着正在编辑的文件。如果没有把缓冲区里的文件存盘,那么原始文件不会被更改。
缓冲区列表
:buffers命令将会列出当前编辑中所有的缓冲区状态。在这个状态列表中,前面的数字是缓冲区的数字标记,第二个标记就是缓冲区当前的状态,紧接着是与缓冲区所关联的文件名。 网上的一些资料里用的

:files显示目前打开了哪些文件
:ls 书中用的
上面三个什么区别
我当前的
sha@sha-Inspiron-3847:~/Work/PracticeVim/code/files$ ls
a.txt b.txt letters mvc mvc_paths.vim
sha@sha-Inspiron-3847:~/Work/PracticeVim/code/files$ vim *.txt


注意,缓冲区列表 和 前面说的 参数列表 argument list 中的内容可能不一样
:buffers
1 "test1" line 1
2 "test2" line 0
3 # "test" line 1
4 "3" line 0
5 %a "app.js" line 1
Press ENTER or type command to continue
:args
[app.js] test1


有如下几种状态:
  - (非活动的缓冲区)
  a (激活缓冲区)#应该是指光标所在的缓冲区
  h (隐藏的缓冲区)
  % (当前的缓冲区)#是指当前窗口可见的缓冲区,因为可以分割窗口,可能有多个
  # (交换缓冲区)#书中说是轮换文件,按<C-^>可以在当前文件和论换文件中切换# symbol represents the alternate file. We can quickly toggle between the current and alternate files by pressing <C-^>
  = (只读缓冲区)
  + (已经更改的缓冲区) 如果现在保存,则写入磁盘,+消失; 如果从已更改的缓冲区切换出去,但没保存,会有提示

更多关于缓冲区
http://blog.csdn.net/icycolawater/article/details/77946139

切换缓冲区与遍历缓冲区列表
:buffers
列示缓冲区状态
:buffer {filename/number}
编辑指定缓冲区
:ball(ba默认水平分屏)
编辑所有缓冲区
:bnext(bn)
到下一缓冲区
:bprevious(bp)
到前一缓冲区
:blast
到最后一个缓冲区
:bfirst
到第一个缓冲区
:badd
增加缓冲区
:bdelete
删除缓冲区
:bunload
卸载缓冲区 ???

This happens when a buffer is modified, but is forced (with '!')关于删除缓冲区,如果 缓冲区的内容被 修改了,执行删除会跳出提示
E89: No write since last change for buffer 1 (add ! to override)
感觉跟 在 激活缓冲区的 时候 输入:q 作用差不多
那该怎么办。 用 :bd! 1

可以对上面的切换命令创建按键映射项 Mappings
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>

--> 关于<silent> 参考 :help <silent>
To define a mapping which will not be echoed on the command line, add "<silent>" as the first argument. Example: >
:map <silent> ,h /Header<CR>
The search string will not be echoed when using this mapping. Messages from the executed command are still given though.

4.3.1.3 隐藏的缓冲区

参考技巧 38
默认情况下,vim不让我们从一个 修改过的缓冲区 切换到 另一个

:help buffer-!
*:buffer-!*
If the option 'hidden' ('hid') is set,abandoned buffers are kept for all commands that start editing another file: ":edit", ":next", ":tag", etc. The commands that move through the buffer list sometimes make the current buffer hidden although the 'hidden' option is not set.This happens when a buffer is modified, but is forced (with '!') to be removed from a window, and 'autowrite' is off or the buffer can't be written.

You can make a hidden buffer not hidden by starting to edit it with any command. Or by deleting it with the ":bdelete" command.

其他命令 包括 :bnext! : next! :buffer! [number] 等强制切换命令

退出 vim 会话时,系统会提示

如果启用了 hidden选项 :set hidden (默认是 nohidden) 则切换时不用 !

4.3.2 使用分割窗口

参考书 技巧39
窗口是缓冲区的显示区域,参见:h windows,
即可以打开多个窗口显示同一个缓冲区,也可以在每个窗口载入不同的缓冲区
<C-w> 代表 Ctrl+w 同时按 ctrl和w
<C-w>w 代表 按下Ctrl+w 再按w

创建分割窗口

:sp[lit] {filename} 水平打开一个新的窗口,并载入filename,没有filename则为当前文件
:[N]sp[lit] [++opt] [+cmd] *:sp* *:split*
Split current window in two. The result is two viewports on the same file. Make new window N high (default is to use half the height of the current window). Reduces the current window height to create room (and others, if the 'equalalways' option is set, 'eadirection' isn't "hor", and one of them is higher than the current or the new window).

:vsp[lit] {filename} 水平打开一个新的窗口,并载入filename,没有filename则为当前文件
<C-w>s 水平切分当前窗口,新窗口仍显示当前缓冲区
<C-w>v 垂直切分当前窗口,新窗口仍显示当前缓冲区 ?相当与 :vsplit?

:new {filename}     ??用水平分割形式新建文件filename,不提供filename 则为[no name]?水平分割?(好像载入已经在缓冲区的文件也可以用)
:[N]new [++opt] [+cmd] *:new*
Create a new window and start editing anempty file in it.Make new window N high (default is to use half the existing height). Reduces the current window height to create room (and others, if the 'equalalways' option is set and 'eadirection' isn't "hor").

<C-w>n ??水平新建一个窗口并且创建一个新的缓冲区,未命名的文件 ?同:new

--》 :edit {filename} 可以把另一缓冲区 载入当前窗口
<C-w>s 然后 :edit {filename} 相当与 :sp[lit] {filename}


在窗口间切换

<C-w> w 用于在窗口间循环切换
<C-w> j 光标移动到下一窗口
<C-w> k 光标移动到上一窗口
<C-w> l 光标移动到右一窗口
<C-w> h 光标移动到左一窗口
--》 如果支持鼠标的话,也可以用鼠标来激活窗口 :set mouse=a

关闭窗口

:close 关闭活动窗口 (??书上说或者用 <C-w>cCtrl+w q退出光标所在的窗口,试了似乎都可以?
:on[ly] 或者<C-w>o 只保留活动窗口,关闭其他所有窗口

改变窗口大小及重排列  

参见 :h window-resize   
     CTRL-W+    增大窗口,默认增量为1
    CTRL-W-    减小窗口,默认值为1
    CTRL-W=    可以将几个窗口的大小变得相等。
也可以用鼠标操作,方便

4.3.3 打开标签页

每个标签包含一个或多个窗口, 标签页与缓冲区 不是一一对应的
VIM的标签页 像是 划分了多个 工作区,就像 linux 下的 多个虚拟桌面一样

:tabedit {filename}
We can open a new tab page with the :tabedit {filename} command. If we omit the {filename} argument, then Vim creates a new tab page containing an empty buffer.
省略文件名则 打开空缓冲区

Alternatively, if thecurrent tab page contains more than one window, we can use the<C-w>T command, which moves the current window into a new tab page (see :h CTRL-W_T ).

If the active tab page contains only a single window, the:close command will close the window and the tab page with it. Or we can use the :tabclose command, which closes the current tab page no matter how many windows it contains
we can use the :tabonly command.
Command Effect
:tabe[dit] {filename} Open {filename} in a new tab
<C-w>T Move the current window into its own tab
:tabc[lose] Close the current tab page and all of its windows
:tabo[nly] Keep the active tab page, closing all others

$ vim -o *.txt
:tabedit


tabs命令 列出所有的标签页
:tabs


窗口, 标签页 的切换, 如果激活了鼠标 会比较方便

4.4 vim插件 plugin

原创粉丝点击