Learn the basic terminal commands

The Wizard's


Vim Cheat Sheet

When you run vim filename to edit a file, Vim starts out in Command Mode. This means that all the keys are used for commands, rather than typing text. Typing j won’t insert the character “j”–it will move the cursor down one line. Typing dd will delete an entire line, rather than inserting “dd.”

To start ediing a file press the letter i and you will be in Insert Mode and type esc to go back to Command Mode

Type colon : to enter save and quit commands

You can alway return to Command/normal mode by hitting your esc key

To use your mouse run :set mouse=a and to disable that run :set mouse=

You can always use your arrow keys to move around in Command Mode using the the letters on the keyboard is a cooler way to do it

Navagation in Command/Normal Mode

  • h moves the cursor one character to the left.
  • j moves the cursor down one line.
  • k moves the cursor up one line.
  • l moves the cursor one character to the right.
  • 0 moves the cursor to the beginning of the line.
  • $ moves the cursor to the end of the line.
  • w move forward one word (Shift + arrow keys) do the same
  • 5w moves the cursor forward 5 words
  • b move backward one word.
  • G move to the end of the file.
  • gg move to the beginning of the file.
  • type a line’s number and capitol G to move cursor to that line
  • Turn on line numbers :set number or the shorter version :set nu
  • Turn off line numbers :set nonumber or the shorter version :set nonu
  • Wrap at whole words: :set linebreak (prevents words from splitting across lines)

Insert Mode

  • i insert before the cursor
  • I insert at the beginning of the line
  • a insert (append/add) after the cursor
  • A insert (add) at the end of the line
  • o add (open) a new line below the current line
  • O add (open) a new line above the current line
  • Esc or Ctrl c exit insert mode

Commandline/Last Line Commands

  • :q quit Vim and return to the command line
  • :q! quit Vim without saving any changes trashing all your work
  • :w write (save) without quitting
  • :wq Write (save) your work and quit Vim
  • :qa quit all buffers
  • :wqa save/write and quit all buffers
  • :ls list all buffers
  • :bd deletes buffer in focus
  • :bd # deletes buffer specified by its number on the list (see :ls)
    • :bd # # deletes buffers specified by their numbers on the list of buffers
  • :bn will move focus to the next buffer on your list
  • :bp will move focus to the previous buffer on your list

Working with Vim Windows

To open two Vim windows aligned vertically do this
In your Terminal type vim file1.js file2.js then :vertical ball and if you run :ball you will get horizonal windows

A better way to open two Vim windows aligned vertically is to do this
In your Terminal type vim -O file1.js file2.js and that's a capitol O because a small o will open the windows horizonally

  • ctrl w w will cycle focus (move the cursor) to the next visible window
  • ctrl w | makes the current window as wide as possible, leaving only a sliver for the others
  • ctrl w = Equalizes both the width and height of all open split windows
  • ctrl w R Rotates windows clockwise and r rotates counter clockwise
  • ctrl w x swap positions of windows
  • :resize +20 resize a horizonal window that has focus 20 character widths
  • :vertical resize +10 resize a vertical window that has focus 10 character widths
  • :split filenam opens another file horizonally beside the one already open
  • :vsplit filenam opens another file vertivally beside the one already open
  • vim -o filename filename opens both files in seperate horizonal windows
  • vim -O filename filename opens both files in seperate vertical windows
    • :vsplit file2.txt adds a third vertical window to the two already open
  • :vsplit file2.txt Splitting vertically opens the new file next to your current one
  • :vert[ical] ba[ll] open all buffers as vertical windows

This article is part of the Scoroncocolo macOS Terminal Tutorial Series