Skip to content

Instantly share code, notes, and snippets.

@youshy
Last active October 2, 2020 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youshy/53997f4cb827d1e9f847d558d0f4b260 to your computer and use it in GitHub Desktop.
Save youshy/53997f4cb827d1e9f847d558d0f4b260 to your computer and use it in GitHub Desktop.
VIM-Academy-Cheat-Sheet

Academy VIM Cheatsheet

Why VIM?

It's fast, free, open-source, basically installed everywhere, you can customize it however you want and you look swish with using terminal (remember Matrix?).

9/10 if you'll SSH into a server you'll have to use VIM so why not to learn it and use it daily?

Basics

Movement

Movement in VIM happens a bit differently. Basic movement:

  • h- move left
  • j - move down
  • k - move up
  • l - move right

Of course you can use arrow keys, but the biggest benefit in using hjkl is that your hands doesn't have to move from the middle low on keyboard. Speed is key!

Modes

VIM has three different modes:

  • Normal - where you move around, paste, etc
  • Insert - where you type
  • Visual - where you highlight stuff, copy, etc

You might think that this is increasing the difficulty of using VIM but in reality, this helps you to work faster.

Normal mode is the one you start with.

Insert is where you type. Access by typing i to start typing from the current cursor placement.

Visual allows you to highlight stuff and do something with it. Access by typing v.

Command line allows you to use commands (inside and outside VIM). Access by typing :.

To exit from any mode to Normal mode, use esc.

Also, remember one thing - leave insert mode when you've finished typing. VIM promotes editing first approach, rather than writing first approach found in VS Code and similar.

Saving & Exiting

A lot of memes here, but it's simple:

:q to quit.

:w to save.

:wq to save and quit.

More Advanced

Advanced Movement

How to move around faster:

  • w - move to the beginning of the next word
  • e - move to the end of the next word
  • b - move to the beginning of the previous word
  • 0 - move to the beginning of the line
  • $ - move to the end of the line
  • gg - move to the top of the file
  • G - move to the bottom of the file
  • } - move to the next paragraph
  • { - move to the previous paragraph

Most of the commands takes a number in front of it, so - f.e. to move to line 50 in this file, use :50 or to move 10 lines up, use 10k

Also, you can invoke insert mode faster:

  • a - start insert after current character
  • A - start insert at the end of the current line
  • I - start insert at the beginning of the current line
  • o - start insert below the current line
  • O - start insert above the current line

Copy/Paste/Delete

  • y - Copy (in visual mode)
  • yy - Copy the whole line (in normal mode)
  • p - Paste the line (in normal mode)
  • P - Paste the line above current line (in normal mode)
  • dd - Delete whole line (in normal mode, available to paste, so it's basically copy and delete)

VIM Setup

So, if you start using VIM, the barebones version might be VERY unappealing. What to do to make it nicer?

In the root (~) of your system, create (or open) a file called .vimrc. This is how VIM will understand what to load prior to the usage.

Bear in mind, some plugins will negatively impact startup time so YMMV

What I think is the good starting point:

" Show where you are
set number
" Show the ruler on left hand side
set ruler

" If you're still scared about not using mouse
set mouse
" Performance boost when using macros
set lazyredraw

" Use spaces instead of tabs
set expandtab

" Be smart when using tabs
set smarttab

" 1 tab == 2 spaces
set shiftwidth=2
set tabstop=2

" Linebreak on 500 characters
set lbr
set tw=500

set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines

Learn More

First thing would be using :help <command-name> with anything you're doing. The manual in VIM is immensely helpful.

Second, run vimtutor daily. One month of running it, everyday, before work and you're golden.

If you like books, there's one called Practical Vim - really good one, shows a lot of tricks.

If you like youtube, there's more than one channel you can watch to expand your VIM horizons (f.e. Primagen).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment