Mastering Vim: Essential Keyboard Shortcuts for Productivity and Efficiency

Vinodha kumara
DevOps.dev
Published in
4 min readMar 14, 2023

--

source: Linuxacademy

Vim is a powerful and highly customisable text editor that is widely used by programmers and system administrators. It offers a wide range of features and capabilities, and can be customised to fit the specific needs of the user. It offers a wide range of features and capabilities, such as syntax highlighting, search and replace, and support for multiple file formats. Vim can be intimidating at first, but with practice and patience, it can become a valuable tool for anyone who needs to work with text files. Whether you are a beginner or an experienced user, mastering Vim can help you become more efficient and effective in your work.

In this blog, we will explore some of the most useful Vim shortcuts that every user should know.

Vim shortcuts

1. Basic Navigation The most basic Vim commands allow you to move the cursor around the text document. Here are some of the most common navigation commands:

  • h: Move left
  • j: Move down
  • k: Move up
  • l: Move right
  • w: Move to the beginning of the next word
  • b: Move to the beginning of the previous word
  • 0: Move to the beginning of the line
  • $: Move to the end of the line
  • gg: Move to the beginning of the document
  • G: Move to the end of the document

2. Editing Vim also offers a variety of commands for editing text. Here are some of the most common editing commands:

  • i: Insert text before the cursor
  • a: Append text after the cursor
  • A: Append text to the end of the line
  • o: Open a new line below the current line and start insert mode
  • O: Open a new line above the current line and start insert mode
  • x: Delete the character under the cursor
  • dd: Delete the current line
  • yy: Copy the current line
  • p: Paste the copied or deleted text after the cursor
  • u: Undo the last command
  • Ctrl-r: Redo the last undone command

3. Search and Replace Vim also offers powerful search and replace capabilities. Here are some of the most useful commands for search and replace:

  • /: Search forward for a pattern
  • ?: Search backward for a pattern
  • n: Repeat the last search in the same direction
  • N: Repeat the last search in the opposite direction
  • :s/search/replace/g: Replace occurrences of ‘search’ with ‘replace’
  • :%s/search/replace/g: Replace all occurrences of ‘search’ with ‘replace’ in the entire document

4. Modes Vim has multiple modes that allow you to perform different tasks. Here are the most common modes:

  • Normal mode: This is the default mode that you start in. It is used for navigation and editing commands.
  • Insert mode: This mode is used for inserting new text into the document.
  • Command mode: This mode is used for entering commands that affect the entire document.
  • Visual mode: This mode is used for selecting and manipulating text.
  • v — start visual mode, mark lines, then perform an operation (such as d-delete)
    V — start linewise visual mode
    Ctrl + v — start blockwise visual mode
    o — move to the other end of marked area
    O — move to other corner of block
    aw — mark a word
    ab — a block with ()
    aB — a block with {}
    ib — inner block with ()
    iB — inner block with {}
    Esc — exit visual mode
    Visual Commands
    > — shift text right
    < — shift text left
    y — yank (copy) marked text
    d — delete marked text
    ~ — switch case

5. Customisation Vim allows you to customise the editor to fit your specific needs. Here are some customization commands:

  • :set number: Display line numbers
  • :set tabstop=4: Set tab width to 4 spaces
  • :set autoindent: Automatically indent new lines
  • :set expandtab: Convert tabs to spaces
  • :set shiftwidth=4: Set indentation level to 4 spaces

Conclusion

The above list of shortcuts is just the tip of the iceberg; Vim offers many more commands and customizations that can be learned with practice. By mastering Vim shortcuts, you can become a more efficient and effective programmer or system administrator.

If you found this article helpful, please don’t forget to hit the Follow and Clap buttons to help me write more articles like this.
Thank You 🖤

You can contact me on: LinkedIn emailme

--

--

DevSecOps, MLOps, Cloud Computing, DE, ML, DL, Programmer, Blogger, Volunteer