For a UCLA student who has taken CS 31 and 32.
Based on material from The Missing Semester of Your CS Education
We're going to be using a version of vim called Neovim. Instructions to install it are available here. In general, we recommend using Chocolatey if you're on Windows, Homebrew if you're on macOS, and your default package manager if you're on Linux.
Vim has a long and storied history. It stands for "Vi IMproved", where vi was another text editor. vi
was in turn based on a text editor called ex
, which was based on a program called ed
, which was based on an editor called QED written by Ken Thompson at Bell Labs in 1966.
Two Bit History covers the history of Vim more in depth if you're interested!
Vim can be used entirely through a keyboard – a fairly radical approach from most GUI applications we're familiar with. This leads to a large learning curve at first, but promises increased efficiency, especially for common tasks.
Vim is a modal text editor: as the name implies, Vim is in different modes when inserting/editing/selecting text.
The most common modes of Vim are:
- Normal: for moving around a file and making edits
- Insert: for inserting text
- Visual (plain, line, or block) mode: for selecting blocks of text
Keys have different meanings in different modes. For example, the x
in insert mode will just insert a literal character ‘x’, but in normal mode, it will delete the character under the cursor, and in visual mode, it will delete the selection.
Vim shows the mode it is in in the bottom left corner of the screen. By default, it is in normal mode.
Vim is one of the most customizable text editors available. There's an entire scripting language used to configure settings! There's also a very large plugin community that extends Vim capabilities in various ways.
Press i
to enter insert mode. Now try typing some text! Press <ESC>
to leave insert mode and go back into normal mode.
Command mode can be entered by typing :
in normal mode. Your cursor will jump to the command line at the bottom of the screen upon pressing :. This mode has many functionalities, including opening, saving, and closing files, and quitting Vim.
Some common commands are:
:q
quit (close window):w
save (“write”):wq
save and quit:e {name of file}
open file for editing:help {topic}
open help- e.g.,
:help :w
opens help for the :w command - e.g.,
:help w
opens help for the w movement
- e.g.,
You should spend most of your time in normal mode, using movement commands to navigate the buffer. Movements in Vim are also called “nouns”, because they refer to chunks of text.
vi was originally developed on a ADM-3A computer, which had the following layout.
Note that the Ctrl key is where the caps lock key usually is and the Escape key is right above it! Typing esc or ctrl was much more ergonomic back in the good ol' vi days than it is now. Because of this, many people remap either esc or ctrl to their caps lock key. We recommend you play around with this.
https://stevelosh.com/blog/2012/10/a-modern-space-cadet/#s13-control-escape
The de facto introduction to vim is via an interactive tutorial called vimtutor. You can access it by opening Neovim:
nvim
then typing: :Tutor
. Let's try it out!
- https://www.moolenaar.net/habits.html
- :h
- http://vimcasts.org/
- https://sanctum.geek.nz/arabesque/vim-koans/
- https://learnvimscriptthehardway.stevelosh.com/
VimAwesome is a great list of plugins.
- minpac
- ALE
- FZF
- vim-commentary
- vim-surround
- vim-fugitive
- NERDTree
- vim-gitgutter
- vim-airline