top of page
nlsamkariashiva

Mastering Vim: Essential Commands for Efficient Text Editing

Vim is a powerful text editor with a wide range of commands that can enhance productivity. Here are some of the top commands and keybindings you should know to work efficiently with Vim:

Basic Navigation

  1. h, j, k, l: Move the cursor left, down, up, and right, respectively.

  2. w: Move the cursor to the beginning of the next word.

  3. b: Move the cursor to the beginning of the previous word.

  4. e: Move the cursor to the end of the current word.

  5. 0: Move the cursor to the beginning of the line.

  6. $: Move the cursor to the end of the line.

  7. gg: Go to the beginning of the file.

  8. G: Go to the end of the file.

  9. Ctrl-f: Move forward one screen.

  10. Ctrl-b: Move backward one screen.

Editing Text

  1. i: Enter insert mode before the cursor.

  2. a: Enter insert mode after the cursor.

  3. o: Open a new line below the cursor and enter insert mode.

  4. O: Open a new line above the cursor and enter insert mode.

  5. x: Delete the character under the cursor.

  6. dd: Delete the current line.

  7. yy: Yank (copy) the current line.

  8. p: Paste the yanked or deleted content after the cursor.

  9. u: Undo the last change.

  10. Ctrl-r: Redo the undone change.

  11. cw: Change (replace) the word under the cursor.

  12. ciw: Change the entire word under the cursor.

  13. daw: Delete a word, including trailing space.

Visual Mode

  1. v: Start visual mode (character-wise selection).

  2. V: Start visual line mode (select entire lines).

  3. Ctrl-v: Start visual block mode (column selection).

  4. y: Yank (copy) the selected text.

  5. d: Delete the selected text.

  6. c: Change the selected text (delete and enter insert mode).

Search and Replace

  1. /: Search forward for a pattern.

  2. ?: Search backward for a pattern.

  3. n: Repeat the search in the same direction.

  4. N: Repeat the search in the opposite direction.

  5. :%s/old/new/g: Replace all occurrences of "old" with "new" in the file.

  6. : Clear search highlighting.

File Management

  1. :w: Save the current file (write changes).

  2. :q: Quit Vim.

  3. :wq: Save and quit Vim.

  4. :q!: Quit without saving changes.

  5. :e filename: Open or edit a specified file, replacing filename with the actual file name.

  6. :x: Save and quit, similar to :wq.

  7. :saveas filename: Save the current file with a new name, replacing filename with the desired new file name.

  8. :bd: Close the current buffer without closing the window.

  9. **:ls or :buffers: List all open buffers.

  10. :bN: Switch to buffer number N, where N is the buffer number.

  11. :set number: Display line numbers.

  12. :set nonumber: Hide line numbers.


Window Management

  1. :split or :sp: Split the current window horizontally, creating a new window above the current one.

  2. :vsplit or :vsp: Split the current window vertically, creating a new window to the right of the current one.

  3. Ctrl-w w: Switch between open windows.

  4. Ctrl-w h: Move to the window to the left.

  5. Ctrl-w j: Move to the window below.

  6. Ctrl-w k: Move to the window above.

  7. Ctrl-w l: Move to the window to the right.

  8. Ctrl-w q: Close the current window.

  9. Ctrl-w o: Close all other windows except the current one.

  10. :resize N: Set the height of the current window to N lines.

  11. :vertical resize N: Set the width of the current window to N columns.

  12. Ctrl-w =: Make all windows equal height and width.


These commands and keybindings cover a wide range of basic and advanced functionalities in Vim. Learning and practicing them will significantly enhance your efficiency in using this versatile editor.

2 views0 comments

Comments


bottom of page