学习 vi 编辑器/Vim/Vim 在 Windows 上
| 学习 vi 编辑器: 熟悉 — 基本任务 — 让工作更轻松 — 高级任务 — 细节 — Vi 克隆 (Vim – 基本导航 – 模式 – 技巧和窍门 – 程序员需要了解的有用内容 – 增强 Vim – Vim 在 Windows 上 – VimL 脚本语言, Vile, BB vi) — vi 参考 | 
Vim 可用于 Microsoft Windows,但该平台存在许多问题,使得有效使用 Vim 非常具有挑战性。本节将讨论一些与使用或考虑在 Windows 系统上使用 Vim 的用户相关的問題。
对于希望在 Windows 上安装 Vim 的用户,有多种安装选项。
其中包括
- 自安装可执行文件
- Win32s GUI 可执行文件
- Windows 3.1 GUI 可执行文件
- Win32 控制台可执行文件
- Win64 二进制文件(适用于 x64)
此外,如果需要,用户可以从源代码编译 Vim。如果用户希望添加对默认情况下未编译到预先存在的二进制文件中的其他选项的支持,这可能有用甚至必要。也许在 Windows 上编译最常见的场景是用户希望添加对默认情况下未包含在 Windows 二进制文件中的编程语言(特定语言或特定版本的语言)的支持。
安装 Vim 时,用户必须为 Windows 默认情况下不包含的任何必要元素(例如编译器和 make)提供支持。
不熟悉 Vim 工作原理和一般“vi 工作方式”的用户可能会发现 Vim 尤其具有挑战性。如果他们已经习惯了 Windows 上大多数其他文本编辑器的流程,尤其如此。因此,如果你想在 Windows 上使用 Vim,实际上不止一种方式。在 Windows 上使用 Vim 的一种方式可以称为*标准 vim 工作流程* (Vim);另一种方式则是*windows vim 工作流程* (WinVim)。
对于那些不适应 Vim 通常带来的陡峭学习曲线的用户来说,使用“WinVim”风格绝对有优势;然而,Vim 中的许多功能在使用“WinVim”模式时很难使用。选择使用哪种使用模式或两者结合,很大程度上取决于个人喜好。
:behave mswin 配置允许用户将编辑器行为设置为反映“WinVim”工作风格的某些方面。这使“WinVim”风格成为一个“缩减版”;那些想要非常详细地模拟 WinVim 风格的用户,必须做的不仅仅是设置“behave mswin”。有关详细信息,请参见 :help behave。
Cream 编辑器是 Vim 配置的一个示例,它专为喜欢“WinVim”工作风格的用户而设计。
对于那些熟悉类 Unix 操作系统并利用这些系统来增强和扩展 Vim 的用户来说,Windows 操作系统可能会呈现一些意想不到的差异和限制。
Windows(默认情况下)使用反斜杠字符来分隔文件路径中的路径步骤。这对于不习惯此操作的用户来说可能具有挑战性。有关详细信息,请参见 :help shellslash。
Windows 命令外壳不支持与 Unix 系统相同的方式的命令管道和重定向。一些用户可能会发现这尤其具有挑战性,因为它极大地限制了 Vim 与编辑器外部的其他程序交互的方式。但是,有一些解决方法,允许用户近似模拟管道和重定向带来的某些功能。
临时文本传输文件是一种解决方法,允许 Vim 在 Windows 上与其他程序交互,而无需使用管道和重定向。基本方法是在本地文件系统上指定一个或多个临时文件,Vim 和外部程序使用这些文件来“传输”彼此之间的文本。
在 Windows XP 中,gVim 7.4 (7.4.280) 在显示非西方字符方面存在问题。即使字符不可见,gVim 也会保留这些字符,并且相同文本在支持更多字体的程序(例如办公套件或 Web 浏览器)中应该看起来正常。
可显示的字体可以通过编辑菜单 > 选择字体...进行更改,可以选择用于特定语言的字体。字体窗口仅包含等宽字体的字体列表,这使得字体选择很少。可以选择现有的非西方字体,并且根据字体支持的脚本,所选脚本(在脚本:)的示例区域将显示非西方脚本示例以及西方字符。要确认是否支持某种语言脚本,请打开脚本:下拉菜单。例如,支持韩语的字体在脚本:下拉菜单中包含韩文。
对于大多数西方脚本,下表显示了 gVim 可见的开源等宽字体的非详尽选择,这些字体提供了最多的语言支持和最佳的可读性。这些字体必须单独下载,但可以与专用软件包一起提供。为了比较,显示了 Windows 默认的Lucida。(字体大小要求可能因用户而异。)
| 字体名称 | 许可证 | 版本 | 包含在 | 支持的脚本 | 备注 | 
|---|---|---|---|---|---|
| DejaVu Sans Mono | FOSS:各种许可证 | 2.35 | 8:西欧、希腊、土耳其、波罗的海、中欧、西里尔、越南、阿拉伯 | 基于 Bitstream Vera. 维基百科文章:DejaVu 字体. | |
| Liberation Mono | FOSS:SIL 开放字体许可证 | 2.00.1 | LibreOffice 5.0 | 8:西欧、希伯来语、希腊、土耳其、波罗的海、中欧、西里尔、越南 | 与 Courier New 度量兼容。OFL 自版本 2+ 起。 维基百科:Liberation 字体. | 
| Lucida Console | 非免费 | 1.60 | Windows XP SP3、MS Office 2007 | 5:西欧、希腊、土耳其、中欧、西里尔 | 这是从 Windows 2000 开始的默认控制台字体,以及从 Windows 2000 到 Windows 8 的默认记事本字体。 | 
| Ubuntu Mono | FOSS:Ubuntu 字体许可证 | 0.80 | 6:西欧、希腊、土耳其、中欧、西里尔 | 维基百科:Ubuntu(字体). | 
与 CUA 风格编辑器的比较
[edit | edit source]下表显示了从 CUA 风格编辑器的角度来看的一些基本 Vim 功能的比较。
这旨在作为那些可能不熟悉 Vim 但熟悉使用标准“文件 :: 编辑 :: 帮助”风格菜单的基于 Windows 的编辑器的用户的起点,例如 Notepad.exe,它默认情况下在大多数 Windows 安装中可用。
### --------------------
file                           ;;   :h files                                ;;  blank___
file                           ;;   :h buffers                              ;;  blank___
file.exit                      ;;   :qa                                     ;;  close all files and quit
file.explore                   ;;   :Vexplore .                             ;;  (:h :Vexplore)
file.explore                   ;;   vim .                                   ;;  startup on a directory
file.open                      ;;   :e .                                    ;;  open directory
file.open                      ;;   :e /foo                                 ;;  open directory
file.open                      ;;   :e /foo/bar.txt                         ;;  open file
file.open.hyperlink            ;;    <c-w>f	                                ;;  open in a new window (Ctrl-w f)
file.open.hyperlink            ;;   gf                                      ;;  open in same window
file.open.hyperlink            ;;   <c-w>gf                                 ;;  open in a new tab (Ctrl-w gf)
file.reload                    ;;   :edit                                   ;;  reload to last-saved version of the file
file.revert                    ;;   :edit                                   ;;  revert to last-saved version of the file
file.save                      ;;   :w                                      ;;  write the current buffer to file
file.save_all                  ;;   :wa                                     ;;  save all modified buffers
file.save_and_quit             ;;   ZZ                                      ;;  :help ZZ "write the current file and quit
### --------------------
autocorrect                    ;;  :help abbreviations                      ;;  blank___
### --------------------
cursor                         ;;  :help motion.txt                         ;;  cursor motions and selections
cursor.back                    ;;  ''                                       ;;  :help ''
cursor.move                    ;;  arrow keys                               ;;  the CUA way
cursor.move                    ;;  hjkl                                     ;;  the vim way
cursor.top_of_file             ;;  gg                                       ;;  compare to c-home in CUA editors
cursor.top_of_file             ;;  :normal gg                               ;;  blank___
### --------------------
edit                           ;;   blank___                                ;;  blank___
edit.cut                       ;;   blank___                                ;;  blank___
edit.copy                      ;;   blank___                                ;;  blank___
edit.copy_line                 ;;   yy                                      ;;  copy (yank) the entire line
edit.cut.by_pattern            ;;   :g/pattern/y A                          ;;  "./try-basicops-edit.txt.txt"
edit.find                      ;;   /                                       ;;  blank___
edit.find_in_files             ;;   vimgrep                                 ;;  "./try-basicops-find-replace.txt"
edit.find_results              ;;   :g//                                    ;;  href="C:/sm/docs/mydaydirs/2013/week11/vim-cua-learnbit.txt"
edit.paste                     ;;   blank___                                ;;  blank___
edit.select.line               ;;   blank___                                ;;  blank___
edit.select.all                ;;   blank___                                ;;  blank___
edit.select.pargraph           ;;   blank___                                ;;  blank___
edit.preferences               ;;   see preferences                         ;;  blank___
edit.currentfile.prefs         ;;   see preferences                         ;;  blank___
### --------------------
edit.change.uppercase           ;;                                          ;; change text to uppercase
### --------------------
edit.delete_blank_lines        ;; :g/^\s*$/:delete
edit.slash_forward             ;;   :{range}s/\\/\//                        ;;  | echo "slash forward"
edit.slash_back                ;;   :{range}s/\//\\/                        ;;  | echo "slash back"
edit.slash_forward             ;;   :s=\\=/=g                               ;;  | echo "slash forward"
edit.slash_back                ;;   :s=/=\\=g                               ;;  | echo "slash back"
edit.sort.file                 ;;   :sort                                   ;;  :h sort
edit.sort.range                ;;   :{range}sort                            ;;  :h sort   :h range
edit.sort.paragraph            ;;   blank___                                ;;  blank___
edit.sort.unique               ;;   :{range}sort u                          ;;  blank___
edit.ws_trim                   ;;   :%s=\s\+$==                             ;;  trim trailing whitespace
### --------------------
insert                         ;;   :help insert                            ;;  insert is a separate "mode" in vim
insert.autocomplete            ;;   ctrl-x // ctrl-n // ctrl-p              ;;  blank___
insert.date                    ;;   google://vim insert date                ;;  insert current system date. there are multiple ways to do this
insert.date (linux  )          ;;   :r !date                                ;;  blank___
insert.date (windows)          ;;   blank___                                ;;  blank___
insert.directory_list          ;;   :r ! ls -al;                            ;;  blank___
### --------------------
search                         ;;   blank___                                ;;  blank___
search.matching lines          ;;   :g/{pattern}/:print                     ;;  print all lines matching pattern
search.matching lines          ;;   :g/{pattern}/:print                     ;;  print all lines matching pattern
### --------------------
code.syntax_coloring           ;;   :set ft=php                             ;;  blank___
### --------------------
navigate.home                   ;; 1G                                       ;; go to top of file
navigate.home                   ;; gg                                       ;; go to top of file
navigate.home                   ;; 1gg                                      ;; go to top of file
navigate.end                    ;; 9999gg                                   ;; go to end of file (assumes file is shorter than 9999 lines)
navigate.end                    ;; G                                        ;; go to end of file
### --------------------
preferences                    ;;   vim ~/.vimrc                            ;;  easy editing of preferences
preferences.komodo             ;;   compare preferences pane in komodo      ;;  "C:\sm\docs\mydaydirs\2012\week36\editor-preferences-pane-001.png"
preferences.komodo             ;;   current file preferences in komodo      ;;  "C:\sm\docs\mydaydirs\2012\week36\editor-preferences-pane-001.png"
preferences.appearance         ;;   :set showcmd                            ;;  show keystrokes that you have typed in normal mode
preferences.cursor_position    ;;   :set ruler?                             ;;  blank___
preferences.line_num           ;;   :set number // :set nonumber            ;;  blank___
preferences.filetype           ;;   :set ft=php                             ;;  blank___
preferences.setting_change     ;;   :set ft=                                ;;  blank___
preferences.setting_view       ;;   :set ft?                                ;;  blank___
preferences.syntax_coloring    ;;   :set ft=php                             ;;  blank___
preferences.keyboard           ;;   :map                                    ;;  display key mappings
### --------------------
tools.interop                  ;;   :helpgrep away and come back            ;;  blank___
tools.python                   ;;   :echo has("python")                     ;;  blank___
tools.external                 ;;   :! drush cc all;                        ;;  example running drush
tools.external                 ;;   :! git commit -a -m "%:t"               ;;  example running git with interpolated current filename
tools.run                      ;;   :! git commit -a -m "%:t"               ;;  run the current file in another program
tools.run                      ;;   :! git commit -a -m "%:t"               ;;  run the current file as a script
tools.macro                    ;;   :helpgrep big changes                   ;;  "./try-basicops-tools.txt"
tools.repeat_command           ;;   <up>                                    ;;  "./try-basicops-tools.txt"
tools.normal_command           ;;   :normal                                 ;;  blank___
### --------------------
tools.scripting                ;;     :help user-function                   ;;  creating custom functions in vim
tools.scripting                ;;     :help vim-script-intro                ;;  creating custom functions in vim
### --------------------
window                         ;;    :help window                           ;;  "./try-basicops-windows.txt"
window.close_others            ;;    :only                                  ;;  blank___
window.equalize                ;;    ctrl-w =                               ;;  equalize the size of all windows
window.history.navigate        ;;    :pop :tag                              ;;  :h tag
window.history.forward         ;;    :ta[g]                                 ;;  :h ctrl-]
window.history.back            ;;    ctrl-O                                 ;;  :helpgrep tutorial // :help usr_01 //
window.history.back            ;;    :po[p]                                 ;;  blank___
window.rotate                  ;;    ctrl-w ctrl-r                          ;;  :help window-moving
window.rotate                  ;;    ctrl-w r                               ;;  
window.reshuffle               ;;    ctrl-w H                               ;;  two_handed_cmd
window.reshuffle               ;;    ctrl-w J                               ;;  two_handed_cmd
window.reshuffle               ;;    ctrl-w K                               ;;  two_handed_cmd
window.reshuffle               ;;    ctrl-w L                               ;;  two_handed_cmd
window.resize                  ;;    :resize +10                            ;;  height increase current window size
window.resize                  ;;    :resize -10                            ;;  height decrease current window size
window.resize                  ;;    :vertical resize -10                   ;;  width decrease current window size
window.resize                  ;;    :vertical resize +10                   ;;  width increase current window size
window.resize                  ;;    ctrl-w =                               ;;  (aka window.equalize)
window.split                   ;;    :split                                 ;;  blank___
window.split                   ;;    ctrl-w s                               ;;  blank___
window.navigate                ;;    ctrl-w + ctrl-w                        ;;  move cursor cycle thru all windows
window.scrolling               ;;    :set scrollbind                        ;;  dual pane windows scroll together
window.split.vertical          ;;    ctrl-w v                               ;;  blank___
window.split.vertical          ;;    :vsplit                                ;;  blank___
window.split.close             ;;    :close                                 ;;  closes the currently focused split
window.split.close             ;;    ctrl-w q                               ;;  closes the currently focused split
window.navigate                ;;    ctrl-w + arrow keys                    ;;  move cursor around between split windows (mouse_alternative)
window.tabs                    ;;    :h tabs                                ;;  blank___
window.tabprevious             ;;    :tabprevious                           ;;  blank___
window.tabnext                 ;;    :tabnext                               ;;  blank___
window.tabnext                 ;;    gt                                     ;;  blank___
window.tabmove                 ;;    <ctrl-arrow> (windows)                 ;;  requires MyVim_MoveTabPage
window.tabmove                 ;;    :tabmove N                             ;;  :tabmove 0 makes it the first tab // :help :tabm
### --------------------
help                           ;;   :help // :h // :help help               ;;  overview of the help system
help.find                      ;;   :helpgrep /pattern/                     ;;  search for a term in the help system (see also :copen)
help.context_specific          ;;   :helpgrep help-context                  ;;  shows the different contexts for which you can get help
help.autocomplete              ;;   ctrl-d                                  ;;  shows completions for vim help
### --------------------
### [cross-reference: influx_either_kevin_pay]
| 学习 vi 编辑器: 熟悉 — 基本任务 — 让工作更轻松 — 高级任务 — 细节 — Vi 克隆 (Vim – 基本导航 – 模式 – 技巧和窍门 – 程序员需要了解的有用内容 – 增强 Vim – Vim 在 Windows 上 – VimL 脚本语言, Vile, BB vi) — vi 参考 |