Vi... IMproved!
Humble Beginnings... Ed
A simple text editor.
Surprisingly (to me at least), the history of Vim starts here. Ed is the first text editor in our story, it was developed by Ken Thompson in August 1969. It was influenced by qed text editor, which was developed at UC Berkeley, Ken's alma mater. Thompson implemented regular expressions on qed, which was notable. Ed is a line based text editor with no GUI, just simple command line options. Start ed with a prompt: ed -p ">> " This will start ed and add an indicator to see your cursor position. There are two modes, command mode, which will have your defined cursor, and input mode, which means you're actually inputing into the program, the ">> " will disappear in input mode. "," in front of commands will apply to the whole file. >>,n Will print the whole file with line numbers for example.
Command | Description |
---|---|
[.] | places cursor at line number "." meaning any number |
[.,.]a | append to next line (default: last line of file) |
[.,.]d | delete line(s) (default: last line of file) |
[.,.]m[.] | move line(s) from [range]m[new location] |
[.,.]p | print range, current address is set to last line printed |
[.,.]n | print all with line numbers, current address is set to last line printed |
r [filename] | reads the file, and outputs the number of bytes |
wq [filename] | writes the file, outputs the number of bytes, then quits |
g/re/p | globally find lines by regular expression and print. (Also try g/re/n) |
,s/old/new/g | replace all occurances of [old] with [new] |
Here is a comprehensive list of Ed commands if for some crazy reason you want to become an Ed legend.
Change of pace... Vi
A text editor, with a GUI??
The true inspiration for Vim, came from Bill Joy in 1976 with a text editor called Vi. This was the Vi(sual) mode for a line editor called Ex, and was released as part of the first Berkely Software Distribution (BSD) / Unix release in March 1978. Ex in the form shipped with Vi was also written by Bill Joy, but had some features influenced from Charles Haley, who modified Ed calling it Em. [1]
" Ex stands for extended, because it was originally an extension of the simple line editor Ed. Similarly, "Vi" stands for Visual, because Vi is the "Visual" (full-screen) editing mode, which was eventually added to ex.The commands Ex and Vi point to the same program, started in different modes. You can start ex by running vi -e, or you can start Vi by running ex -v. Additionally, from within Ex, you can start Vi with the visual command (or vi for short). From inside Vi, you can start Ex with the command Q."
-- computerhope.com
On top of adding a GUI, Vi introduced a whole new slew of ideas and commands to the text editing experience. Some of these came from ex, and some were for Vi itself. Also instead of editing out whole lines, you can now edit indivudial characters in the lines. There are 3 modes in Vi:
- Command mode
- Insert mode
- Last Line mode
Command mode is the mode you are in when you enter Vi, it allows you to use motions and movement commands (hjkl) to move around the page. Entering insert mode requires an input command in Command mode, commonly these are i (insert), a (append), c (change), s (substitute), o (open new line). Entering last line mode requires typing colon ":" this allows you to use Ex commands.
Now for a timeless meme in the Vim community. Hopefully I can save one more poor soul from an almost certain fate.
:q! Quits Vi, the ! makes it so it quits even if you didn't write the file. The : puts you in Last Line mode. :wq Writes the file and quits. :x ZZ :x and ZZ are shorthand for :wq --- ZZ is performed in Command mode.
Command | Description |
---|---|
[.]G | places cursor at line number "." meaning any number |
dd | delete whole line |
yy | yank whole line |
p | paste |
ctrl-d ctrl-u | scroll down/up half a screen |
ctrl-f ctrl-b | page forward/backward a full screen |
f[char] | finds [char] in current line. ";" to repeat "," to go back. |
u | undo, again to redo |
J | join lines |
}{ | jump paragraphs |
/ or ? | search forward or backward |
:%s/old/new/g | replace all occurances of [old] with [new] from current file "%" |
Here is a large list of Vi commands to help you on your Vi journey.
Here comes Big Bram... Vim
We ain't editing in Kansas anymore.
Vi IMproved was influenced from Stevie (ST Editor for VI Enthusiasts) written by Tim Thompson but I couldn't find much in terms of the history of Stevie except for changing undo functionality. It seems that a vast majority of what makes Vim, Vim is Bram Moolenaar. This is the wikipedia summary on Bram:
"Bram Moolenaar is a Dutch computer programmer and an active member of the open-source software community. He is the original author, maintainer, release manager, and benevolent dictator for life of Vim a vi-derivative text editor that is very popular among programmers and power users. From July 2006 until September 2021 Moolenaar was employed by Google working in the Zürich office. He was able to spend part of his time maintaining Vim." -- wikipedia.org
Vim was released in 1991, 15 years after Vi and is massively different from Vi, it has a much larger (like seriously there's so many new features) depth of new functionality, so much that i'm going to miss probably 90% of it, but here are some of the major differences:
Interface | buffers / windows / tabs |
Modes | normal / insert / visual / terminal / command / replace |
Colors | syntax highlighting / themes |
Functionality | jump list / registers / undo history / code folding |
Motions | new combinations introduced to move around the page and edit text |
Keymaps | customizable ways to automate your vim experience |
Plugins | the true next level of Vim written by users |
While many of these changes are built in, other changes are made possible by the introduction of vimscript, which is a built in scripting language written by Bram enabling you to run Ex and Vim commands automatically when Vim starts up, or execute functions during runtime. The place to usually start with vimscript is in the .vimrc file. Click to download an example .vimrc. The vimrc file should be named .vimrc and placed in the $HOME directory.
:sourceSources the file, which means it reads the Ex commands from the current buffer, optionally you can add a filename to source a different file, adding % says to source current file. :so is the shortcut.
Command | Description |
---|---|
di[w t p ) } " ' `] | delete in w(ord), t(ag), p(aragrphs), )}(blocks), or "`'(quotes) |
V | visually select whole line, enters Visual Line mode. |
"[register]y | yank selection to register [0-9][a-z] |
"[register]p | put (paste) from register [0-9][a-z] |
u   Crtl-r | undo / redo, traverses the undo tree |
R | Enter replace mode, type to continuously replace |
:![shell command] | run shell commands in vim |
Ctrl + o   Ctrl + i | jump backward/forward in jump list |
:term | opens a terminal window in terminal mode |
m[char]   '[char] | mark a location in the file using m / jump to mark location using ' (doesn't affect jump list) |
q[char]   @[char] | Record a macro using q, use the macro using @ |
:h [keyword] | search for keyword in all the vim docs |
There is an almost endless sea of vim motions and commands, for brevity I added some that show some of the powerful features of Vim, and that I use often. For a more extensive list here's a cheat sheet of Vim commands. I wouldn't recommend trying to memorize these, just something to give you a reference point and maybe some new ideas of motions or commands to try.
A community approaches... NeoVim
To Vimfinity, and beyond!
Neovim was created as a community fork for Vim with the goals of making a faster, more collaborative and more user friendly and configurable Vim. It can basically be downloaded and run on any operating system and has hundreds of open source projects currently in the ecosystem. Here's the about on Github:
Vim-fork focused on extensibility and usability
And here's the first paragraph of the README:
Neovim is a project that seeks to aggressively refactor Vim in order to:-- Neovim
- Simplify maintenance and encourage contributions
- Split the work between multiple developers
- Enable advanced UIs without modifications to the core
- Maximize extensibility
I think Neovim does a great job on delivering on all of these goals, and a large part of the reason is because of their decision to use Lua.
What is Lua?Lua is a language created in Brazil in 1993. The Lua language was incorporated into Neovim for 5 main reasons.
Simplicity | reference manual is only 100 pages, and covers the entire language, standard lib, and C api |
Small size | 200kb binary size for Linux |
Portability | Lua is implemented in ISO C, which can be used basically anywhere |
Embeddability | Lua functions can be used inside of vimscript |
Speed | LuaJIT performs comparibly with C, does especially well with table lookups (which are common) |
For a text editor, these goals seem like an obvious win. Simplicity is really also key because it allows developers to quickly get up and running with a relatively popular and simple language instead of having to learn vimscript which only really has one use, which is to extend vim.
LSP Support
What is Language Server Protocol (LSP)? Joint project between Microsoft, Redhat and Codenvy. Bascially LSP is
a protocol for how clients should format requests to a language server. This removes the need for editors to
implement their own language servers for every language, and instead separate concerns by having all languages
implement certain actions as defined by the LSPs. Any editor with an LSP client can interact with any
language that provides an LSP server.
In LSP, the client makes JSON remote procedure calls (RPC) with a defined procedure like goToDefinition, then
the
server sends back a response, which the client interprets and executes. If done correctly it jumps to the
definition of the call. The language servers can provide a lot more functionality most coders have come to
expect out of their IDE. Including autocomplete, hover definition, type declaration, implementation, auto
formatting, variable renaming, diagnostics and more. All these things are not currently possible in Vim
without a plugin, but full featured LSP client plugins do exist for Vim/Nvim...
Why have a built in LSP client if plugins already exist? Having an LSP client built in is beneficial because
it allows not only for the community to easily configure and build plugins in a way that takes advantage of
LSP, but also makes a larger Lua library with more functionality that can be used for plugins that may not be
related to LSP.
Conclusion
Finding out the history of Vim was a lot of fun, hopefully this website can provide a good starting point to the endless (no, really) journey that is discovering Vim...
Thanks for reading! Now go out and get your Vim on, however you see fit.