You are at https://maschinenpistole.neocities.org


Vim: A Beginner's Guide


Vim is a powerful, free and open-source text editor. It is an "Improved" version of Vi, designed to be more user-friendly and packed with more features.

It's been used for over 30 years now, and is MY personal favorite text/code editing program.



Now I know a lot of people who can't figure out how to work with Vim. Many people I know can't even figure out how to EXIT Vim,

So this page is just going to be a guide/reference for using Vim.

And if you still need some help, You could run vimtutor (After installing Vim), which is a 30-minute long tutorial that guides you through Vim shortcuts.



So downloading Vim isn't too technical. Vim has been ported to many different operating systems. I'll show you how to install Vim on Debian here.

Just run "apt install vim" and your package manager should download Vim from it's repositories and install it.



And if you get an output similar to this, It means Vim has been installed.

Now if you're using a different GNU/Linux distribution, You can use it's own package manager to install Vim.

Almost all package managers have the prebuilt binary for Vim available in their repositories.


If you are using a different Operating System, Like Mac, BSD or Windows, or you want to compile Vim manually, Refer to Vim's download page.

https://www.vim.org/download.php


Once you've installed Vim, and run it in the terminal with the command "vim" (Or run the GUI program "gvim"), You'll get a screen that looks something like this...



And you're in Vim!

Now here's a list of keyboard commands for Vim. Some of these are used very frequently, others, not so much.

You needn't memorize ALL of these. Just remember to hit "I" for when you want to edit the text, use arrow keys to move around, and once you're done, Run ":wq!" to save and exit.

Other commands listed here make some repetitive tasks easier, or perform some functions that would take a long time to manually perform, especially with large files.



(Hit ESC to make sure you're in Normal Mode to run these commands)

(These Commands are CaSe-SeNsItIvE)



k - Move cursor up

j - Move cursor down

l - Move cursor right

h - Move cursor left



(Arrow keys can be used for navigation too)



:q! - Force quit without saving (Be sure to use '!', especially when viewing a file without editing it)

:w - Save

:w * - Save with a name '*'. (Does not save with a filetype. Include it while saving)

:wq! - Save and Force quit

x - Delete Character at cursor

i - Insert Mode (For general typing)

a - Append Mode

dw - Delete text to start of next word (Excluding first character)

de - Delete to end of selected word (Including last character)

d$ - Delete to end of line

0 - Move cursor to the beginning of the line.

(Typing a number before an operator repeats it that many times)

*w - Go to the beginning of the word * Numbers ahead

*e - Go to the end of the word * Numbers ahead

d*w - Delete * words ahead of the cursor (Including the word where the cursor is placed)

dd - Deletes a full line

*dd - Deletes * Number of lines

u - Undo the last command

U - Undo all the consecutive changes made to the line.

Ctrl-r - Undo the last 'Undo's.

p - Place the text last deleted (with a 'd' operator) after the cursor.

r - Replace the character under the cursor with a different character.

ce - Deletes the word under the cursor and puts you in Insert mode to replace it.

cw - Does the same as 'ce'. (Can be used as c*w to "change" * number of words)

cc - Does the same as 'ce' but for a full line.

c$ - Does the same as 'cc' but preserves anything on the line before the cursor.

(Remember to exit Insert mode after a 'c' command before running anything else)

Ctrl-g - Shows file location and status

gg - Go to the beginning of the file

G - Go to the end of the file

*G - Places the cursor at the beginning of the *th line

/* - Search for '*', Any word/phrase.

(During a / search, 'n' finds the next instance, 'N' finds the previous instance)

% - Press on an opening/closing parenthesis to find the other corresponding parenthesis.

('%' works for all types of parentheses, except for '<>')

(Probably because '<>' are greater-than and less-than signs, not considered to be angular brackets)

:s/x/y - Substitutes a word/phrase 'x' with 'y'. (Only the first instance after the cursor)

:s/x/y/g - Substitutes all instances of 'x' on a line with 'y'.

%s/x/y/g - Substitutes all instances of 'x' in a file with 'y'.

%s/x/y/gc - Substitutes all instances of 'x' in a file with 'y', confirms substitution of each instance.

:! * - Executes an external command '*', shows it output, and drops you back into vim.

(For example on GNU/Linux systems, :!ls would give you a listing of all the files in your working directory.)



v - Puts you in Visual Mode, moving up/down highlights text, which can be copied/saved.

:r * - Retrieves and pastes content from a saved file titled '*'.

:r !* - Retrieves the output of a command '*' and pastes it at the cursor.

:o - "Opens" a line below the cursor and puts you in insert mode.

:O - "Opens" a line above the cursor and puts you in insert mode.


This list is incomplete, and more commands will be added soon. Thank you for viewing!