Linux command list

vim command: edit a file inside the terminal

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying vim. Nothing here can touch your real files.
user@webterm:~/project$
 

vim is the editor that runs in your terminal. Learn how to get out with `:q!`, how the modes work, and the handful of movement and editing keys worth knowing, in a real terminal in your browser.

Updated: 2026-09-06

Syntax

vim [+line] [file]

It opens the file. A name that does not exist yet opens as a new file.

Try it first

Have a look at the file before editing it.

$ cat notes.txt
buy milk
call the bank
fix the login bug

Now open it.

$ vim notes.txt

The screen turns into the editor. The first thing to learn is how to leave.

What you wantWhat to press
Quit without savingEsc:q! → Enter
Save and quitEsc:wq → Enter
Just saveEsc:w → Enter

Esc comes first because it takes you back to normal mode from wherever you were.

It has modes

What makes vim different from other editors is that keys mean different things in different modes.

ModeWhat it is forHow to get there
NormalMoving, deleting, copyingEsc
InsertTyping texti (before the cursor), a (after), o (new line below)
Command lineSaving, quitting, substituting:

A freshly opened file is in normal mode. Type there and your letters are read as commands instead of text. That is the part everyone trips on, and the whole answer is: i to write, Esc when you are done.

Moving around

In normal mode, single keys move the cursor.

KeyMovement
h j k lLeft, down, up, right
w bForward and back one word
0 $Start and end of the line
gg GTop and bottom of the file
/text then EnterSearch forward; n for the next match

Arrow keys work too, but h j k l keep your hands still.

Changing things

KeyWhat it does
xDelete the character under the cursor
ddDelete the whole line
dwDelete a word
yy then pCopy a line and paste it
ciwDelete the word and start typing in its place
uUndo
Ctrl+rRedo
.Repeat the last change

Deleting and pasting in one or two keystrokes is the reason people call vim fast.

Opening at a line

When you know which line the error is on, open there.

$ vim +12 logs/app.log

+12 puts the cursor on line 12 as the file opens.

When you actually reach for it

vim is what you type to fix a config file on a machine you reached over SSH.

SituationWhat to type
Edit a config filevim config.yml
Open at the line from a logvim +12 logs/app.log
Start a new filevim draft.txt
Only readinguse cat or less instead

Read with less, change with vim, and you will rarely have to think about which one.

Things that trip people up

Press Esc before :. Type :wq while still in insert mode and it goes into the file as text. If saving does not seem to work, Esc first.

Ctrl+S does nothing useful. In a terminal it can freeze the display instead. Saving is :w.

Directories cannot be opened.

$ vim logs
vim: logs: Is a directory

:q! is the escape hatch. :q refuses to quit while there are unsaved changes. When you have lost track of what you did, Esc then :q! puts the file back the way it was.

Practise it hands-on

webterm.appthis site

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

cat / less / man / echo

Frequently asked questions

I cannot get out of vim.
Press `Esc`, then type `:q!` and Enter. `Esc` returns you to normal mode and `:q!` quits without saving. To save first, use `:wq`.
Typing does strange things.
You are still in normal mode, where keys are commands rather than text. Press `i` to start typing, and `Esc` to go back.
How do I save?
`Esc`, then `:w`. To save and quit, `:wq`, or `ZZ` from normal mode, which does the same.
Do the arrow keys work?
They do. `h` `j` `k` `l` are worth learning anyway because your hands never leave the home row.
Why not just use nano or VS Code?
On your own machine, do. The reason to know vim is that it is on every server, so it is there when you are connected over SSH.