Vim - Basics

Get Help

:h[elp] - read the friendly manual!
:vert h _topic_ - vertical help split

# build in tutorial

Open a file

vim existingfile.txt
vim newfile.txt

:e[dit] {file} - open a file
:vie[w] - set read only
:ene[w] - edit a new, unnamed file

:pw[d] - print working directory
:cd - change working directory
:cd - - back to last directory

Write and quit

:q[uit] - quit current window
:w[rite] - write buffer to file
:sav[e] - save buffer as
:wq - write and close current window
same as :x and ZZ

:q! - force quit dont write ZQ

Vim’s Command mode

: - enter cmdline mode
TAB - command completion
:history - command history
q : - open command window

Suspend and resume

CTRL-Z - suspend vim :sus[pend]
( $ jobs to list, $ fg to bring vim back)
:!{cmd} - execute a shell cmd
:r[ead] !{cmd} - dump cmd output
:shell - start a new shell
'0 - get back where you left Vim (:marks)
:ol[dfiles] - list recently edited files
:bro[wse] ol[dfiles] - :ol with prompt


A window is a viewport onto a buffer. You can use multiple windows on one buffer, or several windows on different buffers.

CTRL-W commands

Opening and closing:

s - split current window :vs[plit]
v - split vertical :sp[lit]
n - new empty file :new / :vne[w]
q - quit current window :q[uit]
o - close all other :on[ly]

Moving around:

ARROWS - move between windows
p - move to previous window
w - next window
r / R - rotate windows
x - swap windows


= - size all windows evenly
- - decrease hight :res[ize] -N
+ - increase height :res[ize] +N
_ - max heigt
< - decrease width :vert res -N
> - increase witdh :vert res +N
| - max width


A buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.


**:ls** - list all buffers
**:bd**[elete] [N] - delete buffer [N]
**:b**[uffer] [N] - open buffer [N]
**:sb**[uffer] [N] - split open buffer [N]
**:bn**[ext] - next buffer
**:bp**[revious] - previous buffer
**:ba**[ll] - open all buffer in windows


Each time you exit Vim it will store this information in a file, the viminfo
file. When Vim starts again, the viminfo file is read and the information

The viminfo file is designed to store status information:

  • Command-line and Search pattern history
  • Text in registers
  • Marks for various files
  • The buffer list
  • Global variables


A Session keeps the Views for all windows, plus the global settings.

**:mks**[ession][!] [file] - create a session file, [!] overrides
**:so**[ource] [file] - restore session from file
startup with session $ vim -S mySession.vim


A View is a collection of settings that apply to one window.

**:mkvie**[w] [file] - create a view of the current window
:loadview - …