I. Text Editors: A Personal History
II. What is Vim?
III. Vim Basics
IV. Cool Things Vim Can Do
V. Plugins/Extensions
VI. Conclusion
- Notepad on Windows XP
- Sublime Text
- Atom
- Neovim
An extensible, idiosyncratic, keyboard-driven modal text editor with a scriptable command language
<ACTION> <COUNT> <MOVEMENT>
Examples:
d2w- delete two wordsdd- delete the current line5j- move down five linesyG- yank (copy) to the end of the file
Replaces the <COUNT> and <MOVEMENT> with text highlighting (which can be controlled with other movement keys).
Examples:
VU- convert the whole line to uppercaseCtrl-v}d- delete a column of text
For Writing Text (aka "The Boring Part")
Except: Inserting text is also considered a command in Vim, so you can use a <COUNT> to repeat the insertion.
Allows for more complex commands, including launching external programs, searching, and more.
Examples:
:w- write (save) the current file:q- quit Vim:q!- quit without saving:wq- write and quit:!<command>- run an external command:r!<filename>- Insert the output of the current command at the cursor position
h- move leftj- move downk- move upl- move rightgg- go to the first line of the fileG- go to the last line of the file
w- move to the start of the next wordb- move to the start of the previous worde- move to the end of the current word^- move to the first non-blank character of the line$- move to the end of the line)- move to the next sentence (punctuation-based)(- move to the previous sentence (punctuation-based){- move to the previous paragraph (newline-based)}- move to the next paragraph (newline-based)
y- yank (copy) the selected textd- delete the selected text (also yanks it)yy- yank an entire linedd- delete an entire line (also yanks it)p- paste the yanked text after the cursor (or after the line if you yanked a line)P- paste the yanked text before the cursor (or after the line if you yanked a line)
u- undo the last changeCtrl-r- redo the last change
:help <topic>- open the help documentation for a specific topicvimtutor- start the Vim tutor for learning Vim basics
/<term>- search forward for a term?<term>- search backward for a termn- repeat the last search in the same directionN- repeat the last search in the opposite direction*- search for the word under the cursor#- search for the word under the cursor in reverse
d<count>f<character>- delete from the cursor to the th occurrence of<character>d<count>F<character>- delete from the cursor to the th occurrence of<character>in reversed<count>/<pattern>- delete from the cursor to the next occurrence of<pattern>d<count>?<pattern>- delete from the cursor to the previous occurrence of<pattern>
:s/<pattern>/<replacement>/- find and replace first occurrence in the current line:%s/<pattern>/<replacement>/- find and replace first occurrences in each line of the entire file
/g- replace all occurrences in the line/file/i- Case insensitive replacement/c- confirm each replacement
:sort- sort the lines in the current selection:sort!- sort the lines in the current selection in reverse order
:vsplit- split the current window vertically:split- split the current window horizontallyCtrl-w h- move to the left windowCtrl-w j- move to the window belowCtrl-w k- move to the window aboveCtrl-w l- move to the right window:tabnew- open a new tab:tabnext- switch to the next tab:tabprev- switch to the previous tab
Ctrl-a- increment the number under the cursorCtrl-x- decrement the number under the cursor
Vim can record all of your keystrokes into a macro register, which can then be replayed later.
q<register>- start recording a macro into the specified registerq- stop recording the macro@<register>- play the macro from the specified register
<register>is any key fromatoz, or0to9.
A macro can invoke itself, which will cause it to repeat until the macro fails
Displays a tree-like file browser in a vim pane
"Conquer of Completion" - Implements the Language Server Protocol to provide autocompletion, linting, etc.
AI-assisted editing/completions
While putting this whole document together, I found copilot would occasionally suggest new commands that I didn't even know existed!
Provides a fancy status bar with colors and file information
Better display of csv files by column/row, and adds some vim-like commands for manipulating data
A Zettlekasten-style note-taking tool built on top of vim, using a neovim-specific plugin called Telescope.
I'm not arguing that Vim is the best text editor, or that everyone should stop using their current editor and make the switch.
I'm sure you can replicate any of these vim functions in VS Code, or Sublime Text, or whatever editor you prefer (probably not notepad).
Text editors are tools, and with any tool the most important thing is to make sure you're using it correctly. So it's worth taking the time to learn (and practice) the tools you use every day.