Software:Vim (text editor)

From HandWiki
(Redirected from Vim script)
Short description: Improved version of the Vi keyboard-oriented text editor
Vim
Vimlogo.svg
Vim-(logiciel)-console.png
Vim running in a terminal emulator
Original author(s)Bram Moolenaar
Initial releaseError: first parameter is missing. ()
Stable release8.2.0000[1] (13 December 2019; 5 years ago (2019-12-13)) [±]
Written inC, Vim script
Operating systemUnix, Linux, Windows NT, MS-DOS, macOS, iOS, Android, Haiku, AmigaOS, MorphOS
TypeText editor
LicenseVim[2][3][4]

Vim (/vɪm/;[5] vi improved) is a free and open-source, screen-based text editor program. It is an improved clone of Bill Joy's vi. Vim's author, Bram Moolenaar, derived Vim from a port of the Stevie editor for Amiga[6] and released a version to the public in 1991. Vim is designed for use both from a command-line interface and as a standalone application in a graphical user interface.[7] Since its release for the Amiga, cross-platform development has made it available on many other systems. In 2018, it was voted the most popular editor amongst Linux Journal readers;[8] in 2015 the Stack Overflow developer survey found it to be the third most popular text editor,[9] and in 2019 the fifth most popular development environment.[10]

History

Vim's forerunner, Stevie (ST Editor for VI Enthusiasts), was created by Tim Thompson for the Atari ST in 1987[11][12] and further developed by Tony Andrews[11][13] and G.R. (Fred) Walter.[14][15] It was one of the first popularized clones of Vi, and did not use Vi's source code. The source code for Vi used the Ed text editor developed under AT&T, and therefore Vi could only be used by those with an AT&T source license.[citation needed] Basing Vim on the source code for Stevie meant the program could be distributed without requiring the AT&T source license.

Basing his work on Stevie, Bram Moolenaar began working on Vim for the Amiga computer in 1988, with the first public release (Vim v1.14) in 1991.[16][17][better source needed]

At the time of its first release, the name "Vim" was an acronym for "Vi IMitation", but this changed to "'Vi IMproved" late in 1993.[18]

Release history

Date Version Changes and additions
June, 1987 N/A Tim Thompson releases Stevie (ST editor for VI enthusiasts), a limited vi clone for the Atari ST, posting the source on Usenet.[11][12]
June, 1988 N/A Tony Andrews improves Stevie, and ports it to Unix and OS/2, releasing version 3.10 on Usenet.[11][13]
1988 1.0 Bram Moolenaar creates Vi IMitation for the Amiga, based on Stevie, never publicly released
November 2, 1991 1.14[19] First public release for the Amiga on Fred Fish disk #591[20]
1992 1.22[19] Port to Unix, never publicly released.[18] Vim now competes with vi.
December 14, 1993 2.0[21] This is the first release using the name Vi IMproved.[18]
August 12, 1994 3.0[19] Support for multiple windows
May 29, 1996 4.0[19][22] Graphical user interface
February 19, 1998 5.0[19][23] Syntax highlighting, basic scripting (user defined functions, commands, etc.)
April 6, 1998 5.1 Bug fixes, various improvements
April 27, 1998 5.2 Long line support, file browser, dialogs, popup menu, select mode, session files, user defined functions and commands, Tcl interface, etc.
August 31, 1998 5.3 Bug fixes, etc.
July 25, 1999 5.4 Basic file encryption, various improvements
September 19, 1999 5.5 Bug fixes, various improvements
January 16, 2000 5.6 New syntax files, bug fixes, etc.
June 24, 2000 5.7 New syntax files, bug fixes, etc.
May 31, 2001 5.8 New syntax files, bug fixes, etc.
September 26, 2001 6.0[19][24] Folding, plugins, multi-language, etc.
March 24, 2002 6.1 Bug fixes
June 1, 2003 6.2 GTK2 and libgnome2 support, Arabic language support, :try command, minor features, bug fixes
June 7, 2004 6.3 Bug fixes, translation updates, mark improvements
October 15, 2005 6.4 Bug fixes, updates to Perl, Python, and Ruby support
May 7, 2006 7.0[25] Spell checking, code completion, tab pages (multiple viewports/window layouts), current line and column highlighting, undo branches, and more
May 12, 2007 7.1 Bug fixes, new syntax and runtime files, etc.
August 9, 2008 7.2[26] Floating point support in scripts, refactored screen drawing code, bug fixes, new syntax files, etc.
August 15, 2010 7.3 Lua support, Python3 support, Blowfish encryption, persistent undo/redo
August 10, 2013 7.4[27] A new, faster regular expression engine.
September 12, 2016 8.0[28] Asynchronous I/O support, jobs, lambdas, etc.
May 18, 2018 8.1[29] Terminal window support and terminal gdb plugin.
December 13, 2019 8.2[30] Popup windows, text properties.
June 28, 2022 9.0[31] Vim9 script
January 2, 2024 9.1[32] Classes and objects support for Vim9 script, smooth scrolling, virtual text

License

Vim is released under the Vim license, which includes some charityware clauses that encourage users who enjoy the software to consider donating to children in Uganda.[4] The Vim license is compatible with the GNU General Public License through a special clause allowing distribution of modified copies under the GNU GPL version 2.0 or later.[4]

Interface

gVim 7.3

Like vi, Vim's interface is not based on menus or icons but on commands given in a text user interface; its GUI mode, gVim, adds menus and toolbars for commonly used commands but the full functionality is still expressed through its command line mode. Vi (and by extension Vim) tends to allow a typist to keep their fingers on the home row, which can be an advantage for a touch typist.[33]

Vim has a built-in tutorial for beginners called vimtutor, which is usually installed along with Vim, but is a separate executable and can be run with a shell command.[34] The Vim Users' Manual details Vim's features and can be read from within Vim, or found online.[35][36]

Vim also has a built-in help facility (using the :help command) which allows users to query and navigate through commands and features.

Registers

Vim features various special memory entries called registers (not to be confused with hardware or processor registers). When cutting, deleting, copying, or pasting text the user can choose to store the manipulated text in a register. There are 36 general-purpose registers associated with letters and numbers ([a-z0-9]) and a range of special ones that either contain special values (current filename, last command, etc.) or serve a special purpose.[7]:85

Modes

Vim modes

Like vi, vim supports multiple editing modes. Depending on the mode, typed characters are interpreted either as sequences of commands or are inserted as text. In Vim there are 14 editing modes, 7 basic modes and 7 variants:[37]

  • Normal mode – used for editor commands. This is generally the default mode and by default hitting returns the editor to this mode.
  • Insert mode – used for typing text in a way similar to most modern editors. In this mode, opened text in buffers can be modified with the text entered from the keyboard.[38][33]:12
  • Visual mode – used to select areas of text. Commands can be run on the selected area – moving, editing, filtering via built-in or external command, etc.
    • Visual linewise, a subtype of visual mode which selects one or more whole lines
    • Visual blockwise, another subtype which selects a rectangular block of text across one or more lines
  • Select mode – similar to visual, but the commands are not interpreted, instead, highlighted text is directly replaced by input from the keyboard; similar to the selection mode used in editors on Microsoft Windows platforms
  • Command-line or Cmdline mode – provides a single line input at the bottom of the Vim window. Commands (beginning with ) and some other keys for specific actions (including pattern search and the filter command) activate this mode. On completion of the command, Vim returns to the previous mode.[38][33]:12
  • Ex mode mode – accepts a sequence of commands.
  • Terminal-Job mode - Interacting with a job in a terminal window.

Customization

Vim is highly customizable and extensible, making it an attractive tool for users who demand a large amount of control and flexibility over their text editing environment.[39] Text input is facilitated by a variety of features designed to increase keyboard efficiency. Users can execute complex commands with "key mappings," which can be customized and extended. The "recording" feature allows for the creation of macros to automate sequences of keystrokes and call internal or user-defined functions and mappings. Abbreviations, similar to macros and key mappings, facilitate the expansion of short strings of text into longer ones and can also be used to correct mistakes. Vim also features an "easy" mode for users looking for a simpler text editing solution.[40]

There are many plugins available that extend or add new functionality to Vim. These plugins are usually written in Vim's internal scripting language, vimscript (also known as VimL),[41] but can be written in other languages as well.

There are projects bundling together complex scripts and customizations and aimed at turning Vim into a tool for a specific task or adding a major flavour to its behaviour. Examples include Cream, which makes Vim behave like a click-and-type editor, or VimOutliner, which provides a comfortable outliner for users of Unix-like systems.

Features and improvements over vi

Vim has a vi compatibility mode, but when that mode is not used, Vim has many enhancements over vi.[42] However even in compatibility mode, Vim is not entirely compatible with vi as defined in the Single Unix Specification[43] and POSIX (e.g., Vim does not support vi's open mode, only visual mode). Vim's developers state that it is "very much compatible with Vi".[44]

Some of Vim's enhancements include completion functions, comparison and merging of files (known as vimdiff), a comprehensive integrated help system, extended regular expressions, scripting languages (both native and through alternative scripting interpreters such as Perl, Python, Ruby, Tcl, etc.) including support for plugins, a graphical user interface (gvim), limited integrated development environment-like features, mouse interaction (both with and without the GUI), folding, editing of compressed or archived files in gzip, bzip2, zip, and tar format and files over network protocols such as SSH, FTP, and HTTP, session state preservation, spell checking, split (horizontal and vertical) and tabbed windows, Unicode and other multi-language support, syntax highlighting, trans-session command, search and cursor position histories, multiple level and branching undo/redo history which can persist across editing sessions, and visual mode.

While running, Vim saves the user's changes in a swap file with the ".swp" extension. This file can be used to recover after a crash. If a user tries to open a file and a swap file already exists, Vim will warn the user, and if the user proceeds, Vim will use a swap file with the extension ".swo" (or, if there is already more than one swap file, ".swn", ".swm", etc.).[45][46] The feature can be disabled.[47]

Vim script

Vim script (also called Vimscript or VimL)[48] is the scripting language built into Vim.[49] Based on the ex editor language of the original vi editor, early versions of Vim added commands for control flow and function definitions. Since version 7, Vim script also supports more advanced data types such as lists and dictionaries and a simple form of object-oriented programming. Built-in functions such as map() and filter() allow a basic form of functional programming, and Vim script has lambda since version 8.0. Vim script is mostly written in an imperative programming style.

Vim macros can contain a sequence of normal-mode commands, but can also invoke ex commands or functions written in Vim script for more complex tasks. Almost all extensions (called plugins or more commonly scripts) of the core Vim functionality are written in Vim script, but plugins can also utilize other languages like Perl,[50] Python,[51] Lua,[52] Ruby,[53] Tcl,[54] or Racket.[55] These plugins can be installed manually, or through a plugin manager such as Vundle, Pathogen, or Vim-Plug.

Vim script files are stored as plain text, similarly to other code, and the filename extension is usually .vim. One notable exception to that is Vim's config file, .vimrc.

Examples

" This is the Hello World program in Vim script.
echo "Hello, world!"

" This is a simple while loop in Vim script.
let i = 1
while i < 5
  echo "count is" i
  let i += 1
endwhile
unlet i

Availability

While vi was originally available only on Unix operating systems, Vim has been ported to many operating systems including AmigaOS (the initial target platform), Atari MiNT, BeOS, DOS, Windows starting from Windows NT 3.1, OS/2, OS/390, MorphOS, OpenVMS, QNX, RISC OS, Linux, BSD, and Classic Mac OS.[56] Also, Vim is shipped with Apple macOS.[57]

Independent ports of Vim are available for Android[58][59] and iOS.[60]

Neovim

Neovim
Neovim-logo.svg
Neovim v0.9.0-dev intro screen.png
Other namesNVim
Initial releaseError: first parameter is missing. ()
Written inC, Vim script, Lua
Operating systemMicrosoft Windows and Unix-like
LicenseApache-2.0

Neovim[61] is a fork of Vim that strives to improve the extensibility and maintainability of Vim.[62] Some features of the fork include built-in Language Server Protocol (LSP) support, support for asynchronous I/O, and support for Lua scripting using luaJIT language interpreter.[63][lower-alpha 1] The project is free software and its source code is available on GitHub.[64]

Neovim has the same configuration syntax as Vim (unless vim9script is used); thus the same configuration file can be used with both editors, although there are minor differences in details of options.[65] If the added features of Neovim are not used, Neovim is compatible with almost all of Vim's features.[66]

The Neovim project was started in 2014, after a patch to Vim supporting multi-threading was rejected.[67] Neovim had a successful fundraising in March 2014, supporting at least one full-time developer.[68][69]

Several frontends are under development which make use of Neovim's capabilities.[70][71][72]

With the 0.5 release of Neovim on July 2, 2021, it gained built-in support for the LSP, Tree-sitter, and more complete Lua support – including the support for configuration scripts written in Lua instead of VimL.[73]

Gallery

See also

Notes

  1. LuaJIT is directly listed as a third-party dependency for the program build.

References

  1. "Releases". https://github.com/vim/vim/releases. 
  2. "vim/LICENSE". 20 October 2021. https://github.com/vim/vim/blob/master/LICENSE. 
  3. "Vim License". https://spdx.org/licenses/Vim.html. 
  4. 4.0 4.1 4.2 "Vim: uganda.txt". https://vimhelp.org/uganda.txt.html#license. 
  5. Vim documentation: intro : "Vim is pronounced as one word, like Jim, not vi-ai-em. It's written with a capital, since it's a name, again like Jim."
    • The original interview: Moolenaar, Bram (18 April 2005). "Rozhovor: Bram Moolenaar" [Interview: Bram Moolenaar]. LinuxEXPRES (Interview) (in čeština). Interviewed by Zapletal, Lukáš. question 2. Archived from the original on 28 December 2023. Retrieved 3 January 2024.
    • Translation: Bram Moolenaar (n.d.). "Interview with Bram Moolenaar, as published in the Czech magazine LinuxEXPRES, English version.". https://moolenaar.net/interv_czech_en.html. 
  6. 7.0 7.1 McDonnell, Mark (2014). Pro vim. [Berkeley]. ISBN 978-1-4842-0250-0. OCLC 897466496. https://www.worldcat.org/oclc/897466496. 
  7. "Best Editor | Linux Journal". https://www.linuxjournal.com/content/best-editor-0. 
  8. "Stack Overflow Developer Survey 2015 § IV. Text Editor". Stack Overflow. https://insights.stackoverflow.com/survey/2015#tech-editor. 
  9. "Stack Overflow Developer Survey 2019 Results". Stack Overflow § VII. Development Environments. https://insights.stackoverflow.com/survey/2019#development-environments-and-tools. 
  10. 11.0 11.1 11.2 11.3 Thompson, Tim (2000-03-26). "Stevie". http://nosuch.com/tjt/stevie/. 
  11. 12.0 12.1 Tim Thompson (1987-06-28). "A mini-vi for the ST". Newsgroupcomp.sys.atari.st. Usenet: 129@glimmer.UUCP. Archived from the original on 9 November 2012. Retrieved 2010-12-27.
  12. 13.0 13.1 Tony Andrews (1988-06-06). "v15i037: Stevie, an "aspiring" VI clone for Unix, OS/2, Amiga". Newsgroupcomp.sources.unix. Usenet: 893@fig.bbn.com. Archived from the original on 9 November 2012. Retrieved 2010-12-27.
  13. "intro.txt" (in en). Vim. 20 January 2015. https://vimhelp.appspot.com/intro.txt.html. 
  14. "vim(1)". Vim. 11 April 2006. http://linux.die.net/man/1/vim. "Vim is based on Stevie, worked on by: Tim Thompson, Tony Andrews and G.R. (Fred) Walter. Although hardly any of the original code remains." 
  15. Moolenaar, Bram (10 October 2000). "The continuing story of Vim". http://moolenaar.net/vimstory.pdf. 
  16. "The history of Vim – Jovica Ilic". 5 June 2014. https://jovicailic.org/2014/06/the-history-of-vim/. 
  17. 18.0 18.1 18.2 "VILE (Vi Like Emacs) – Frequently Asked Questions (FAQ)". https://invisible-island.net/vile/vile.faq.html#clone_began. 
  18. 19.0 19.1 19.2 19.3 19.4 19.5 Moolenaar, Bram (2002-01-15). "Vim, an open-source text editor". http://www.free-soft.org/FSM/english/issue01/vim.html. 
  19. "Textfiles.com". http://cd.textfiles.com/fredfish/v1.6/FF_Disks/571-600/FF_591/Contents. 
  20. "Filewatcher". http://www.filewatcher.com/b/ftp/ftp.twaren.net/pub/Unix/Editors/Vim/old.0.0.html. 
  21. "Official Vim Manual, Version 4 summary". 2004-03-12. http://www.vim.org/htmldoc/version4.html. 
  22. "Official Vim Manual, Version 5 summary". 2004-01-17. http://www.vim.org/htmldoc/version5.html. 
  23. "Official Vim Manual, Version 6 summary". 2004-03-12. http://www.vim.org/htmldoc/version6.html. 
  24. "Vim Reference Manual, Version 7". 2016-07-17. https://vimhelp.org/version7.txt.html. 
  25. "Google Groups". http://groups.google.com/group/vim_announce/browse_thread/thread/2c89671dd928812f. 
  26. Google Discussiegroepen . Groups.google.com. Retrieved on 2013-12-09.
  27. Bram Moolenaar. "Vim 8.0 released!". https://groups.google.com/forum/#!topic/vim_announce/EKTuhjF3ET0. 
  28. Bram Moolenaar. "Vim 8.1 is released!". https://www.vim.org/vim-8.1-released.php. 
  29. Bram Moolenaar. "Vim 8.2 is released!". https://www.vim.org/vim-8.2-released.php. 
  30. Bram Moolenaar. "Vim 9.0 is released!". https://www.vim.org/vim90.php. 
  31. Christian Brabandt. "Vim 9.1 is released!". https://www.vim.org/vim-9.1-released.php. 
  32. 33.0 33.1 33.2 Lamb, Linda; Robbins, Arnold (1998). Learning the Vi Editor. O'Reilly Media, Inc.. p. 305. ISBN 9781565924260. https://archive.org/details/learningvieditor00lamb/page/305. 
  33. Moolenaar, Bram (3 November 2010). "Vim documentation: usr_01". http://vimdoc.sourceforge.net/htmldoc/usr_01.html#tutor. 
  34. Vim help files at vimhelp.org
  35. Oualline, Steve (April 2001). Vi IMproved (VIM). New Riders Publishers. ISBN 0-7357-1001-5. http://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf. Retrieved 11 October 2021. 
  36. Moolenaar, Bram. "Vim: intro.txt". https://vimhelp.org/intro.txt.html. 
  37. 38.0 38.1 "CS107 The Vim Editor". https://web.stanford.edu/class/cs107/resources/vim.html. 
  38. Melendez, Steven (28 October 2014). "Why Vim, An '80s Text Editor, Is Still The UI Of Choice For Power Users". https://www.fastcompany.com/3037629/why-vim-an-80s-text-editor-is-still-the-ui-of-choice-for-power-users. 
  39. "Tips: Making Vim easy". 2007-04-10. https://www.linux.com/news/tips-making-vim-easy. 
  40. "Vim documentation: usr_41". https://vimhelp.org/usr_41.txt.html#vim-script-intro. 
  41. Vim help system (type ":help" within Vim)
  42. The Open Group (2008), "vi — screen-oriented (visual) display editor", Single Unix Specification, Version 4 (IEEE Std 1003.1–2008), http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html, retrieved 2010-12-27 
  43. "Vim FAQ". 2004-01-02. https://vimhelp.org/vim_faq.txt.html#faq-1.3.  (question 1.3)
  44. "Vim documentation: recover". http://vimdoc.sourceforge.net/htmldoc/recover.html. 
  45. "How to handle swapfiles in Vim". https://cs.longwood.edu/VimSwap.html. 
  46. "'swapfile' option". 10 October 2020. https://vimhelp.org/options.txt.html#'swapfile'. 
  47. Klein, Benjamin. "The VimL Primer: Edit Like a Pro with Vim Plugins and Scripts by Benjamin Klein | The Pragmatic Bookshelf". https://pragprog.com/book/bkviml/the-viml-primer. 
  48. "Vim documentation: usr_41". https://vimhelp.org/usr_41.txt.html. 
  49. Verdoolaege, Sven; Gerassimof, Matt. "Vim documentation: if_perl". http://vimdoc.sourceforge.net/htmldoc/if_perl.html. 
  50. Moore, Paul. "Vim documentation: if_pyth". http://vimdoc.sourceforge.net/htmldoc/if_pyth.html. 
  51. Carvalho, Luis. "Vim documentation: if_lua". http://vimdoc.sourceforge.net/htmldoc/if_lua.html. 
  52. Maeda, Shugo. "Vim documentation: if_ruby". http://vimdoc.sourceforge.net/htmldoc/if_ruby.html. 
  53. Wilken, Ingo. "Vim documentation: if_tcl". http://vimdoc.sourceforge.net/htmldoc/if_tcl.html. 
  54. Khorev, Sergey. "Vim documentation: if_mzsch". http://vimdoc.sourceforge.net/htmldoc/if_mzsch.html. 
  55. ":help sys-file-list"
    "Vim Online: Downloads". http://www.vim.org/download.php. 
  56. "Mac OS X Manual Page For vim(1)". developer.apple.com. Apple Inc.. https://developer.apple.com/library/mac/#DOCUMENTATION/Darwin/Reference/ManPages/man1/vim.1.html. 
  57. "VimTouch, the development has stalled on this app". https://github.com/momodalo/vimtouch. 
  58. "DroidVim, under active development". https://github.com/shiftrot/droidvim. 
  59. "Vim – Applidium, mobile agency in Paris". http://applidium.com/en/applications/vim/. 
  60. "Neovim: vim, out of the box". http://neovim.io/. 
  61. "Neovim Vision". https://neovim.io/charter/. 
  62. "Nvim documentation: vim_diff". https://neovim.io/doc/user/vim_diff.html. 
  63. "GitHub – neovim/neovim: Vim-fork focused on extensibility and usability". 2019-08-29. https://github.com/neovim/neovim. 
  64. "Switching to NeoVim". 31 March 2015. http://arusahni.net/blog/2015/03/switching-to-neovim-part-1.html. 
  65. "How to start using Neovim instead of Vim". http://veelenga.com/editors/how-to-start-using-neovim-instead-of-vim/. 
  66. Eddie Kovsky (1 February 2017). "Vim's 25th anniversary and the release of Vim 8 [LWN.net"]. lwn.net. https://lwn.net/Articles/713114/. 
  67. "Vimcasts.org blog post". http://vimcasts.org/blog/2014/03/support-neovim/. 
  68. "Neovim". 23 March 2014. https://www.bountysource.com/teams/neovim/fundraiser. 
  69. "NyaoVim frontend". 2019-08-29. https://github.com/rhysd/NyaoVim. 
  70. "Mac OS X frontend". 2019-08-29. https://github.com/rogual/neovim-dot-app. 
  71. "Neovim-Qt frontend". 2020-07-21. https://github.com/equalsraf/neovim-qt. 
  72. Ayooluwa Isaiah (3 August 2021). "New features in Neovim 0.5 [LWN.net"]. lwn.net. https://lwn.net/Articles/864712/. 

External links