paint-brush
Vim in 3 minutesby@claudio.santos.ribeiro
4,394 reads
4,394 reads

Vim in 3 minutes

by Cláudio RibeiroAugust 16th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<em>This article was inspired in Paul Gorman’s </em><a href="https://paulgorman.org/technical/vim5minutes.html" target="_blank"><em>article with a very similar name (vim in 5 minutes)</em></a><em>.</em>

People Mentioned

Mention Thumbnail
featured image - Vim in 3 minutes
Cláudio Ribeiro HackerNoon profile picture

This article was inspired in Paul Gorman’s article with a very similar name (vim in 5 minutes).

What is Vim?

  • Vim is a text editor.

How do I get Vim?

  • Depending on your operating system, either download and install it (windows), with apt (Linux) or brew (macOS).

How do I use Vim?

From the command line, type ‘vim’ or ‘vim {filename}’, or ‘gvim’ for the graphical version.

Vim is a modal text editor and it has 4 main modes:

  • Normal Mode: Vim starts in normal mode. It’s used to navigate through text and entering commands.

Commands are built the following way:

[operator] [count] [motions] where an operator indicates an action, count is the number of times to execute the action and motions the character or group of characters to apply.

For example:

y3w => yank ( copy ) the next 3 words.

d5j => delete 5 lines down.

In the end of this article we can find a list of operators and motions.

  • Insert mode: it is used to insert text and it is reached by entering ‘i’ while in Normal mode.

To go back to Normal mode enter ‘ESC’ ( this is valid for all modes).

  • Command mode: it is used to enter commands ( like save and exit ).

It is reached from Normal mode with ‘:{command}’ for commands or ‘/{string}’ for search or even ‘?{string}’ for backwards search.

The most common commands are:

:w => save

:wq => save and quit

:q! => quit without save

:e => reload from disk

/foo => search forward for ‘foo’

?foo => search backwards for ‘foo’

  • Visual mode: it is used to select and manipulate groups of characters.

It is reached from Normal mode with ‘v’. Normal motions change the highlighted area and normal operations will affect it.

Last but not least, Vim has some of the best help menus I’ve ever seen. To get help use:

:help

or :help {topic}

:vimtutor will launch a quick, hands-on Vim tutorial.

Vimtutor example

Summing up:

All you really need to know to start using Vim is to open a file with ‘vim {filename}’. Enter ‘i’ to start adding text. Enter ‘ESC’ when you’re done adding text. Finally, enter ‘:wq’ to save and quit, or ‘:q!’ to quit without saving.

Of course, Vim is much more than this. This article was the result of trying to sum up a quick way to introduce the bare essentials to Vim. For more detailed information check vimtutor or one of this two books:

This book will take you from Vim installation to use it as an IDE.

Extra:

As promised, here is a list of Operators and motions that can be used on Vim.

Operations









d Deletedd Delete liney Yankyy Yank linec Changeu UndoCtl-r Redor Replace character. Repeat last operation

Motions



























h Left (like left arrow)j Down (like down arrow)k Up (like up arrow)l Right (like right arrow)w Work forward/rightb Work back/leftW Whitespace work forwardB Whitespace work back0 Start of line$ End of line^ Non-whitespace start of lineCtl-f Screen forwardCtl-b Screen backgg Start of fileG End of file( Sentence back) Sentence forward{ Paragraph back} Paragraph forward% Jump to matching brace23G Jumpt to line 23`. Jump to last change* Jump to next instance of word under cursor# Jump to previous instance of word under cursorf_x_ Next character x on this lineF_x_ Previous character x on this line; Repeat f_x_ or F_x_