Vim Command

(resources: https://vim.fandom.com/wiki/Moving_lines_up_or_down)

  • + jump to next line

  • G jump to last line of the file

  • o insert new line

  • ggVG selects all content. gg moves to first line. V starts visual mode. G jumps to last line thereby selecting from first to last line

  • To go to first line of a file press Escand chose one of the following:

    • gg, or

    • :1, or

    • 1G, or

    • 1gg

  • Ctrl o +

    • 0 ==> go to start of the line

    • $ ==> go to end of file

    • 1 + G ==> jump to the first line

    • 2 + G ==> jump to the second line

    • o ==> insert in a new line

    • a ==> insert after cursor

    • A ==> insert at the of the line

    • i ==> insert before cursor

    • G+o ==> insert at the end of a file

  • vim + myfile.txt ==> insert at the end of a file (add an automatic G)

  • /" dt" ==> find the first quote and delete till next quote

  • dw ==> delete word

  • di" ==> delete word within "

  • da" ==> delete word within " including the "

  • dG ==> delete from cursor until the end of the file

  • d$ ==> delete from cursor until the end of the line

  • x delete character

  • :s/toReplace/withWord in the line

  • :%s/toReplace/withWord in the file

  • :3,4s/toReplace/withWord between lines

  • Cntr + r ==> redo

  • /word ==> find a word

Visual mode

Comment in/comment out

To comment in:

  1. Press Esc

  2. Press Ctrl-v

  3. Select lines

  4. Press I

  5. Insert the character to put at the beginning of the line

  6. Press Esc

To comment out:

  1. Press Esc

  2. press Ctrl-v

  3. Select lines

  4. Press x

  5. Press Esc

Select and delete

  1. Go to the first line

  2. V

  3. move down to last line

  4. d

Last updated