Vim quickies/ cheatsheet
Rubin

Rubin @rubiin

About: Self taught developer,FOSS lover, linux enthusiast

Location:
Kathmandu, Nepal
Joined:
Dec 17, 2017

Vim quickies/ cheatsheet

Publish Date: Sep 30 '19
223 28

Vim Cheatsheet

Contents
Generally helpful stuff
Navigating around text
Working with multiple files
Searching
Manipulating text
Visual Advanced selection
Working with NERDTree
Commands

Generally helpful stuff

Open a file for editing             :e path/to/file.txt
Return to Normal mode               ESC   or <CTRL>+C
Enter fullscreen mode Exit fullscreen mode

Navigating around text

You have to be in Normal mode. Use ESC to get out of Visual, Replace, or Insert mode.

(left)                       h
(down)                       j
(up)                         k
(right)                      l
next word                    e
Jump to the first line       gg
Jump to the last line        G
Enter fullscreen mode Exit fullscreen mode

Entering Text

Insert text before cursor               i
Insert text after cursor                a
Enter fullscreen mode Exit fullscreen mode

Working with multiple files

Open a file in a horizontal split   :sp path/to/file.txt
Open a file in a vertical split     :vsp path/to/file.txt
Move to a split window page         <CTRL>+w and a direction key (h, j, k, or l)
Move to next window pane            <CTRL>w w
Make selected pane bigger           CTRL>w +  (yes, you need the shift key for the plus)
Make selected pane smaller          <CTRL>w -
Enter fullscreen mode Exit fullscreen mode

Searching

Search for a word                           /<word>
Go to next match                            n
Find and replace on line                    :s/<find>/<replace>
Find and replace globally                   :%s/<find>/<replace>//gc
Go to first quote, replace text in quotes:  ci"
Enter fullscreen mode Exit fullscreen mode

Manipulating text

cut the current line                dd
copy the current line               yy
paste below current line            p
paste above current line            P
Remove the character under cursor   x
Remove the character before cursor  X
Delete the word under cursor        de
Delete to the end of the line       d$

Remove five lines starting here     5dd
Copy five lines starting here       5yy 

indent this line                    >>
indent five lines starting here     5>>

Replace mode (overtype)             r
Enter fullscreen mode Exit fullscreen mode

Visual Advanced selection

Visual mode                         v
Visual Line mode                    V
Visual Block mode                   <CTRL>v
Enter fullscreen mode Exit fullscreen mode

Working with NERDTree

Open the NERDTree                   :NERDTree
Toggle the NERDTree on and off      :NERDTreeToggle
Open selected file                  <ENTER>
Open selected file in horiz. split  i
Open selected file in vert. split   v
File menu                           m
Help                                ?
Enter fullscreen mode Exit fullscreen mode

Commands:

Run a command                           :!<command>
Open a shell                            :sh
Enter fullscreen mode Exit fullscreen mode

For interactive tutorial, try openvim.com

Follow me on Github: www.github.com/rubiin

Comments 28 total

  • Mahendra Choudhary
    Mahendra ChoudharySep 30, 2019

    I use vim very often and always hard time to remember all the commands , thanks for this cheat sheet brother

    • Rubin
      RubinSep 30, 2019

      Anytime bro. It takes heck lot of time to get used to Vi , I myself find forgetting many commands , and whenever I do i visit this cheetsheet

  • zchtodd
    zchtoddSep 30, 2019

    I've been working with Vim for quite a while, but there's always something new to learn. Still to this day I'll hit a sequence of keys by mistake and something will happen that I've never seen before.

    • Rubin
      RubinSep 30, 2019

      thats the beauty of vim

  • Ben Sinclair
    Ben SinclairSep 30, 2019

    "Delete the word under cursor" should be diw, de only works for the same purpose if you're already at the start of the word.

    "Replace mode (overtype)" should be R, r will only let you change a single character.

    • Vlastimil Pospichal
      Vlastimil PospichalOct 2, 2019

      de is good for delete word from cursor to end. It is good for different purpose.

    • Jasper Zanjani
      Jasper ZanjaniOct 3, 2019

      Your comment made me go back to Oualline's Vim Book to research this. I totally did not know about the i and a motion commands! Great tip!

  • Ganesh Prasad
    Ganesh PrasadSep 30, 2019

    There is a catch with visual block mode. If you're running vim in a terminal that maps Ctrl+v to paste action, then Ctrl+v won't work for visual block mode in vim. However, vim also maps Ctrl+q to visual block mode in defaults. IMO, it's safer to memorize Ctrl+q as the key combination for visual block mode.

    • Rubin
      RubinSep 30, 2019

      Cool. Haven't tried that one yet

    • Ben Sinclair
      Ben SinclairOct 4, 2019

      Unless your OS maps C-q to "quit application" :)

  • bagus prabangkoro
    bagus prabangkoroSep 30, 2019

    I've been using vim for few weeks, and it'getting natural and saves my time a lot! I like its clear rule, text object (sentence, paragraph, word, tag), or action (delete, copy, change).

    • Rubin
      RubinSep 30, 2019

      Yeah. If you are doing things on console, you can see it's power

    • Rubin
      RubinSep 30, 2019

      BTW you can check openvim.com if you are starting out

  • Christian Sánchez
    Christian SánchezSep 30, 2019

    To understand more about movements/navigation in vim I would recommend to read the section 03 in the Vim user manual, just execute:

    :h usr_03
    
    • Rubin
      RubinSep 30, 2019

      I have also added a link to an interactive site

  • Rubin
    RubinSep 30, 2019

    I have added a link to an interactive vim tutorial at the end of the post so anyone starting out with vim can try it out online

  • David Dal Busco
    David Dal BuscoSep 30, 2019

    I think I basically use only i a x / n dd : wq since years 😁

    Thx for new tips 👍

    • Rubin
      RubinOct 1, 2019

      Anytime

  • Kento Ohgi
    Kento OhgiOct 3, 2019

    ctrl-[ is better then ctrl-c cuz that dose not trigger the |InsertLeave| autocommand event.

  • Tony Pellicccio
    Tony PellicccioOct 3, 2019

    Left out one command I love, cw - or change word. Saves a lot of time.

  • Oinak
    OinakOct 3, 2019

    Very good article!

    Thanks for sharing

    in Searching section, where you say:

    Find and replace globally :%s/<find>/<replace>//gc

    I think you may mean

    Find and replace globally :%s/<find>/<replace>/gc

    and maybe could comment that the final 'c' is for asking for confirmation on each replacement.

    Thanks for your work and time.

  • salvadorrueda
    salvadorruedaOct 3, 2019

    'u' for undo the last change and
    '.' for repeat the last command are two commands I use most frequently despite :wq (write and quit)

  • Jasper Zanjani
    Jasper ZanjaniOct 3, 2019

    Damn, it's a helluva confidence boost when you look at a cheatsheet and know EVERY SINGLE item

  • Jasper Zanjani
    Jasper ZanjaniOct 3, 2019

    delete to end of line is also D

  • gdahboy
    gdahboyOct 6, 2019

    i like very much vim , but i like more IDE . Jetbrains product and Xcode and i am feedup using FakeVim . so can i integrate Vim in these IDE

    • Rubin
      RubinOct 6, 2019

      Yes. You can try the vim bindings plugins

  • /
    /Jun 10, 2020

    To toggle the case=> `
    This would be pretty useful to correct the typos.

    To repeat the previous command=> .

Add comment