The Vim Reference

Recently I decided to learn vim after hearing how much Ben Awad loves it. I though maybe it could boost my productivity too. I am still getting use to it, but right now it seems pretty fun.

Now to the reference. Here are some useful commands and what …


This content originally appeared on DEV Community and was authored by Richard

Recently I decided to learn vim after hearing how much Ben Awad loves it. I though maybe it could boost my productivity too. I am still getting use to it, but right now it seems pretty fun.

Now to the reference. Here are some useful commands and what they do:

Using Vim

  • Open Vim: vim filename
  • Closing Vim:
    • :wq -> save and quit
    • :q -> quit and not save
    • :w -> save and not quit

Movements

  • Hitting gg will take you to the top of file
  • G takes you to the bottom
  • } and { navigate code blocks
  • o adding a new line and put into insert mode
  • O adding a new line above and put into insert mode
  • w will jump to next word b will take you back
  • :number will take you to line number
  • 0 will take you to the start of the line
  • 0 + w or ^ will take you to the first word of a line
  • h j k l to move up down left and right
  • a move over by 1 and set insert mode
  • A jump to end and set insert mode

Editing

  • Hitting "i" in command mode lets you insert
  • Hitting shift + i will set insert mode at the beginning of the line
  • Then esc puts you back into command mode
  • Hitting dd will delete a line and copy to clip board
  • Hitting d + } will delete a whole block of code
  • Hitting 10 dd will delete 10 lines
  • Hitting u will undo
  • Hitting ctrl + r will redo
  • Hitting yy will copy a line
  • p to paste bellow P to paste above
  • x remove a letter where the cursor is
  • number x remove number letters before cursor
  • ~ swap the case of the letter prefix with number for multiple characters
  • . redo

  • $ will take you to the end of a line

  • W will jump spaces and B reverses that

  • f + char find and place cursor on char

  • t + charfind and place cursor before char

  • % take you to and from closing brackets

  • d + % remove code between brackets

  • c + w change mode and word will remove a word and set insert mode

  • D remove everthing from cursor onwards

  • c + t + char edit from cursor to char

  • C change whole line

  • d + t + char delete from cursor to char

  • * take you to occurances of the word where your cursor is

  • ; take you to next instance after using a find command

  • r + char replace letter at cursor with char prefix with number for multiple replaces

  • R allow to replace lots of letters into replace mode

  • /word highlight all occurances of word

Macros

  • Press q to start recording then select a hotkey. Now run some commands and hit q to end. Then hit @ hotkey to replay a command. Prefix @ with a number to replace that many times

Visual Mode: V

  • Select text with movement commands then you can hit:
    • d to delete
    • After selected > or < to indent code.
  • shift + v selects the whole line and puts you into visual mode.
  • v + move select from cursor while move

Visual Block Mode

ctrl + v enter visual block mode. Now you can select columns and hit r to replace things.
In visual block mode hitting shift i will allow you to type and then after you hit esc the text will appear in all places selected.

Thank you for referring to this guide, I hope you found it useful.

Photo by Bich Tran from Pexels


This content originally appeared on DEV Community and was authored by Richard


Print Share Comment Cite Upload Translate Updates
APA

Richard | Sciencx (2021-05-22T17:37:33+00:00) The Vim Reference. Retrieved from https://www.scien.cx/2021/05/22/the-vim-reference/

MLA
" » The Vim Reference." Richard | Sciencx - Saturday May 22, 2021, https://www.scien.cx/2021/05/22/the-vim-reference/
HARVARD
Richard | Sciencx Saturday May 22, 2021 » The Vim Reference., viewed ,<https://www.scien.cx/2021/05/22/the-vim-reference/>
VANCOUVER
Richard | Sciencx - » The Vim Reference. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/22/the-vim-reference/
CHICAGO
" » The Vim Reference." Richard | Sciencx - Accessed . https://www.scien.cx/2021/05/22/the-vim-reference/
IEEE
" » The Vim Reference." Richard | Sciencx [Online]. Available: https://www.scien.cx/2021/05/22/the-vim-reference/. [Accessed: ]
rf:citation
» The Vim Reference | Richard | Sciencx | https://www.scien.cx/2021/05/22/the-vim-reference/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.