Introduction to Vim

Vim, short for Vi IMproved, is an enhanced version of the classic Unix text editor, Vi. Highly customizable, Vim offers features tailored for efficient text editing.


Modes in Vim

Vim operates in different modes, each with specific functions:

  1. Normal Mode: Default for navigation and executing commands.
  2. Insert Mode: For inserting and editing text.
  3. Visual Mode: Selecting and manipulating text visually.
  4. Command-Line Mode: Entering Vim commands.

Basic Navigation

  • h, j, k, l: Move left, down, up, and right respectively.
  • 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 current line.
  • $: Move to the end of the current line.
  • gg: Move to the beginning of the file.
  • G: Move to the end of the file.
  • Ctrl + f: Scroll down one page.
  • Ctrl + b: Scroll up one page.

Editing Text

  • i: Enter Insert Mode before the cursor.
  • a: Enter Insert Mode after the cursor.
  • o: Open a new line below and enter Insert Mode.
  • O: Open a new line above and enter Insert Mode.
  • x: Delete the character under the cursor.
  • dd: Delete the current line.
  • yy: Yank (copy) the current line.
  • p: Paste yanked or deleted text after the cursor.
  • u: Undo the last action.
  • Ctrl + r: Redo the last undone action.

Visual Mode

  • v: Select text character by character.
  • V: Select entire lines.
  • Ctrl + v: Select rectangular blocks of text.

Command-Line Mode

  • :w: Save changes.
  • :q: Quit Vim.
  • :q!: Quit Vim without saving changes.
  • :wq or :x: Save changes and quit.
  • :e [file]: Open a file for editing.
  • :set nu: Show line numbers.
  • :set nonu: Hide line numbers.

Advanced Features

  • Search: / followed by the search term. Press n for next occurrence.
  • Substitution: :%s/old/new/g to replace all “old” with “new”.
  • Buffers: :ls to list open buffers, :b [number] to switch buffer.
  • Tabs: :tabnew [file] to open a file in a new tab, gt to switch tabs.

Customization

  • .vimrc: Customize settings and mappings in Vim configuration file.

Resources for Further Learning

  • Vimtutor: Run vimtutor in the terminal for built-in Vim tutorial.
  • Online Guides and Tutorials: Explore various online resources for comprehensive Vim guides.

Conclusion

Vim, though initially challenging, offers unparalleled efficiency once mastered. Practice regularly and explore its features to unleash its full potential. Happy editing!

Last updated 01 Sep 2024, 10:22 CEST . history