Vim

CBE 263

Overview

There are many text editors to use in the terminal:

  • Vim
  • Helix
  • Emacs
  • Sublime
  • Nano
  • Micro

Vim is standard on most machines and most code editors support vim keybindings either directly or with settings or plugins. Vim is not easy to learn, but a working knowlege is not hard, and it is extremely powerful. Using a terminal-based text editor is especially convenient (if not required) when working on remote computers, as is common in high-perforance computing.

Resources

  • Run vimtutor for a tutorial
  • Neovim The modern Vim variant

Games

Google: “vim tutorials game”

  • VimHero tutorial for building muscle memory
  • Vim master, game with 16 levels
  • Vim adventures, a Zelda style side-scrolling game to build muscle memory
  • Vim Golf “real Vim ninjas count every keystroke” (edit a file in min keystrokes)
  • Vim Genius game for muscle memory
  • Open Vim tutorial
  • Vim snake learn muscle memory of hjkl motions

Open, insert, save, quit

  • Open a file to edit
    • vim file1
  • Two modes: normal and insert
    • normal mode is for moving around and running commands
    • insert mode is for writing text
    • switch from insert mode to normal mode using (the escape key)
    • switch from normal mode to insert mode by typing:
      • i insert before the cursor
        • I to insert at the start of the line
      • a insert after the cursor
        • A append at the end of the line
      • o to start (open) a new line below
        • O to open a new line above
  • Save: :w<enter> when in normal mode.
  • Quit: :q, or ZZ in normal mode
  • Save and Quit: :wq

Move around

  • In normal mode, use the arrow keys, or
  • h, j, k , l to move left, up, down, right
  • w to move by “words”
    • W to move by separated words
  • $ to go to the end of the line
  • 0 to go to the start of the line
  • G to go to the end of the file
  • gg to go to the top of the file
  • :7 to go to line 7, etc.

copy paste

  • yy to copy (yank) current line
  • p to paste after
    • P to paste before
  • dd to delete the current line (and copy it)
  • u to undo
    • <ctrl>-r (hit control and r) to redo
  • D to delete to the end of the line
  • x to delete under the cursor