Vim basics



 


Vim is a highly configurable text editor that is known for its efficiency and power. It was designed as a more advanced version of the vi editor, which was included in Unix systems. Vim is available on a wide variety of platforms, including Linux, MacOS, and Windows. It is known for its modal editing, which allows users to switch between different modes for different tasks, such as inserting text, navigating the document, and executing commands. Vim also has a large number of built-in features and can be extended with plugins to add even more functionality.

I recently started learning vim and I think it has made writing code more enjoyable for me. So I'm sharing with you all so you can give it a try.

The most important thing to know is that vim has three modes

  1. Normal mode - Usually used to move around in a file
  2. Insert mode - Used when editing and writing code
  3. Visual mode - Used for selecting and manipulating code

Here are some basic vim commands:

1. Cursor Movement

  • Use the h, j, k, and l keys to move the cursor left, down, up, and right, respectively. [ like using arrow keys]

  • Use the 0 (zero) key to move the cursor to the beginning of the line.

  • Use the $ key to move the cursor to the end of the line.

  • Use the G key to move the cursor to the end of the file.

  • Use the gg key to move the cursor to the beginning of the file.

  • Use the % key to jump to matching brackets or parentheses.

  • Use the f key followed by a character to jump to the next occurrence of that character.

  • Use the F key followed by a character to jump to the previous occurrence of that character.

  • Use the t key followed by a character to jump to the character before the next occurrence of that character.

  • Use the T key followed by a character to jump to the character after the previous occurrence of that character.

2. Insert Mode actions
  • i - insert before the cursor

  • I - insert at the beginning of the line

  • a - insert (append) after the cursor

  • A - insert (append) at the end of the line

  • o - append (open) a new line below the current line

  • O - append (open) a new line above the current line


3. Editing
  • dd - delete the current line

  • D - delete from the cursor to the end of the line

  • x - delete the character under the cursor

  • X - delete the character before the cursor

  • p - paste the clipboard after the cursor

  • P - paste the clipboard before the cursor

  • u - undo the last change

  • U - undo all changes to the current line

  • . - repeat the last change

  • :w - write (save) the changes to the file

  • :q - quit Vim

  • :wq - write (save) the changes and quit Vim

  • :q! - quit Vim and discard all changes


More vim resources:

Comments

Popular Posts