Learning the vi Editor/Vim/Vim on Windows
Vim is available for Microsoft Windows, but there are many issues attendant to that platform that make effective use of Vim quite challenging. This section deals with some of the issues relevant to users who are using or considering Vim for use on Windows systems.
Installation
[edit | edit source]There are a variety of installation options for users who wish to install Vim on Windows.
These include:
- Self-installing executable
- Win32s GUI executable
- Windows 3.1 GUI executable
- Win32 console executable
- Win64 binaries for x64
Moreover, if desired, a user may compile Vim from source. This may be useful or even necessary if the user wants to add support for additional options that are not compiled into one of the pre-existing binaries by default. Perhaps the most common scenario for compiling on Windows is when the user wishes to add support for a programming language (either a specific language, or a specific version of the language) that is not included in the Windows binaries by default.
When installing Vim, the user has to accommodate for any required elements that do not come with Windows by default, such as a compiler and make.
General usage
[edit | edit source]Users who are not well-acquainted with how Vim works, and the general "vi way of doing things", may find Vim especially challenging. This is especially so, if they are already comfortable with the workflow of most other text editors on Windows. Because of this, there's actually more than one way of doing things if you want to use Vim on Windows. One way of using Vim on Windows can be called standard vim workflow (Vim); another way would be the windows vim workflow (WinVim).
Using the "WinVim" style definitely has advantages for those users who are not amenable to the steep learning curve commonly associated with Vim; however, there are many features within Vim that are difficult to use when working from the "WinVim" paradigm. Whether one chooses one usage pattern over the other, or some combination of the two, is largely a matter of personal preference.
WinVim behaviour levels
[edit | edit source]The :behave mswin
configuration allows a user to set the editor behavior to reflect some aspects of the "WinVim" working style. This enables a 'scaled-down' version of the WinVim style; users who want a very detailed emulation of WinVim style, will have to do more than just set 'behave mswin'. See :help behave
for more details.
Cream editor
[edit | edit source]The Cream editor is an example of a Vim configuration that is designed for users who prefer the "WinVim" style of working.
Compatibility
[edit | edit source]For those who are familiar with UNIX-like operating systems, and leverage such systems to enhance and extend Vim, the Windows operating system may present some unexpected differences and limitations.
Path separators
[edit | edit source]Windows (by default) uses the backslash character to delimit path-steps in file paths. This can be challenging for users who are not used to this. See :help shellslash
for more details.
Command piping
[edit | edit source]The Windows command shell does not support command piping and redirection in the same way as UNIX systems. Some users may find this especially challenging, because it significantly limits the way Vim can interact with other programs external to the editor. There are workarounds, however, that allow a user to approximate some of the power that comes natively from piping and redirection.
Temporary text transport file
[edit | edit source]A temporary text transport file is one workaround that allows Vim to interact with other programs on Windows without requiring use of pipes and redirection. The basic approach is to specify one or more temporary files on the local file system that Vim and external programs use to "transport" text between each other.
Fonts and language support
[edit | edit source]In Windows XP, gVim 7.4 (7.4.280) has issues displaying non-Western characters. Even if a character is not visible, gVim retains the characters, and the same text should appear ok in a program that supports more fonts, such as an office package or a web browser.
The displayable font can be changed via Edit
menu > Select Font...
, where a font can be selected for a particular language. The Font window contains a font list of only monospace fonts, which makes the font selection scarce. An existing non-Western font can be selected, and depending on which script a font supports, the Sample area for a selected script (at Script:
) will show a non-Western script sample alongside Western characters. To confirm, whether a certain language script is supported, open the Script:
drop-down menu. For example, fonts that support Korean, have Hangul in the Script:
drop-down menu.
For most Western scripts, the following table shows a non-exhaustive selection of open-source monospaced fonts visible to gVim that offer the most language support and best legibility. The fonts must be downloaded separately, but can come with a dedicated software package. The Windows-default Lucida is displayed for comparison. (Font size requirements may differ user-by-user.)
Font name | License | Ver. | Came with | Scripts supported | Notes |
---|---|---|---|---|---|
DejaVu Sans Mono | FOSS: various licenses | 2.35 | 8: Western, Greek, Turkish, Baltic, Central European, Cyrillic, Vietnamese, Arabic | Based on Bitstream Vera. Wikipedia article: DejaVu fonts. | |
Liberation Mono | FOSS: SIL Open Font License | 2.00.1 | LibreOffice 5.0 | 8: Western, Hebrew, Greek, Turkish, Baltic, Central European, Cyrillic, Vietnamese | Metrically compatible with Courier New. OFL since version 2+. Wikipedia: Liberation fonts. |
Lucida Console | non-free | 1.60 | Windows XP SP3, MS Office 2007 | 5: Western, Greek, Turkish, Central European, Cyrillic | This is the default console font from Windows 2000 on, and the default Notepad font from Windows 2000 till Windows 8. |
Ubuntu Mono | FOSS: Ubuntu Font License | 0.80 | 6: Western, Greek, Turkish, Central European, Cyrillic | Wikipedia: Ubuntu (typeface). |
Comparison with CUA-style editors
[edit | edit source]The following table shows a comparison of some basic Vim functionality as viewed from the perspective of CUA-style editors.
This is intended as a starting place for those who may be unfamiliar with Vim, but familiar with Windows-based editors that use a standard "File :: Edit :: Help" style menu, such as Notepad.exe, which is available on most Windows installations by default.
### -------------------- 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]