Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Coderwall Tips Sign In or Up

Last Updated: September 30, 2021


·
shiva

Basic Vim commands - For getting started


#vim #unix #vi #commands

Started learning to use Vim. Some simple commands to get started.

Vim has two modes.

1. Insert mode (Where you can just type like normal text editor. Press i for insert
mode)

2. Command mode (Where you give commands to the editor to get things done .
Press ESC for command mode)

Most of them below are in command mode

x - to delete the unwanted character


u - to undo the last the command and U to undo the whole line
CTRL-R to redo
A - to append text at the end
:wq - to save and exit
:q! - to trash all changes
dw - move the cursor to the beginning of the word to delete that word
2w - to move the cursor two words forward.
3e - to move the cursor to the end of the third word forward.
0 (zero) to move to the start of the line.
d2w - which deletes 2 words .. number can be changed for deleting the
number of consecutive words like d3w
dd to delete the line and 2dd to delete to line .number can be changed for
deleting the number of consecutive words

The format for a change command is: operator [number] motion

-operator - is what to do, such as d for delete

- [number] - is an optional count to repeat the motion

- motion - moves over the text to operate on, such as w (word),

$ (to the end of line), etc.

p - puts the previously deleted text after the cursor(Type dd to delete the line
and store it in a Vim register. and p to put the line)
r - to replace the letter e.g press re to replace the letter with e
ce - to change until the end of a word (place the cursor on the u in lubw it will
delete ubw )
ce - deletes the word and places you in Insert mode
G - to move you to the bottom of the file.
gg - to move you to the start of the file.

Type the number of the line you were on and then G


% to find a matching ),], or }
:s/old/new/g to substitute 'new' for 'old' where g is globally
/ backward search n to find the next occurrence and N to search in opposite
direction
? forward search
:! to run the shell commands like :!dir, :!ls
:w - TEST (where TEST is the filename you chose.) . Save the file
v - starts visual mode for selecting the lines and you can perform operation on
that like d delete
:r - Filename will insert the content into the current file
R - to replace more than one character
y - operator to copy text using v visual mode and p to paste it
yw - (copy)yanks one word
o - opens a line below the cursor and start Insert mode.
O - opens a line above the cursor.
a - inserts text after the cursor.
A - inserts text after the end of the line.
e - command moves to the end of a word.
y - operator yanks (copies) text, p puts (pastes) it.
R - enters Replace mode until <ESC> is pressed.
ctrl-w to jump from one window to another
type a command :e and press ctrl+D to list all the command name starts with :e and
press tab to complete the command

Related protips:

Basic Vim commands - For getting started

#vim #unix #vi #commands

Written by
shiva kumar

 Recommend


Say Thanks

 Update Notifications Off


Respond

Related protips

Format JSON in vim



171.1K

15

Setup Vim, Powerline and iTerm2 on Mac OS X



118.9K

7

Automatically set paste mode in Vim when pasting in insert mode



63.53K

5

11 Responses
hauleth
Also nice is :xa which save and quit all files. In case to use it as ZZ (save and quit) I have
mapped some more:

map ZX :cq " quit and return error (helpful when using Vim with Git)
map ZA :qa " quit all buffers

map ZS :xa " quit and save all buffers

over 1 year ago


·

shiva
Nice .. Thanks @hauleth :)

over 1 year ago


·

mislav
For beginners/intermediate: Vim Revisited is my article where I present similar information but
in a more structured format.

over 1 year ago


·

shiva
@mislav i think the links is broken

over 1 year ago


·

mislav
Thanks, bad paste. Now fixed

over 1 year ago


·

cannon10100
There's also :x, which contextually saves the current document if changes have been made
and exits, or simply exits if no changes have been made. Equivalent to :wq

over 1 year ago


·

plenty
As a relatively new vim user, I'm also glad to be repeatedly exposed to command lists such as
this. It really helps.

I recommend new users go pimp out there vim with the plugins ASAP to get a better
impression of its coolness.

Me, I hooked up to this fellas github & followed his README to get a great series of bundles
that all auto-install & bring colour & interest.

https://github.com/gezpage/dotfiles

over 1 year ago


·

PyDevTeam
Thank you for the great article!

over 1 year ago


·

The GRS Solution


wow post i like and enjoy content here @TheGRSsolution

over 1 year ago


·

HuyenPham
The best movie program today is updated on the showbox application. showboxvpn provider
brings the best movie showbox app available today!

over 1 year ago


·

RyanHillier
Thank you very much for sharing this information. This is very valuable information for me
because I'm just learning.

2 months ago
·

Have a fresh tip? Share with Coderwall community!

Post


Best
#Vim Authors

shiva

880K
#vim
#ruby
#javascript
kennu

171.1K
#vim
#Python
#C++

christianrojas

118.9K
#vim
#Ruby
#JavaScript

sickill

73.6K
#vim
#Clojure
#ClojureScript

croaky

56.33K
#vim
#Ruby
#Shell


Related Tags

#vim #unix #vi #commands


Filed Under

Tools

Conquer Code in Vim With 4 Keystrokes or Less

See All Jobs




Awesome Job

Post a job for only


$299

@coderwall
 

APM product comparisons Contact
Privacy
Terms
Copyright 2021

This site is protected by reCAPTCHA and the Google


Privacy Policy
and
Terms of Service
apply.

You might also like