Essential VIM Commands for Beginners

Essential VIM Commands for Beginners & Experts (New Update)
Essential VIM Commands – VIM Tutorials for Beginners (Updated)

VIM Cheatsheet : https://drive.google.com/file/d/15cd4RfcEU50Xk54bXoKMnbDjKAjMNXhX/view?usp=sharing

Essential VIM Commands for Beginners

VIM, a highly configurable text editor, is renowned for its efficiency, speed, and versatility. Loved by developers, sysadmins, and power users, VIM offers a vast array of commands to navigate, edit, and manipulate text with unparalleled precision. In this article, we will delve into the world of VIM commands and equip you with the knowledge needed to harness the full potential of this exceptional editor. Get ready to take your text editing skills to new heights and boost your productivity with VIM.

  1. Modes in VIM:

Before we explore the various VIM commands, it's crucial to understand the different modes:

  • Normal Mode: The default mode when you launch VIM. In this mode, you can navigate, delete, copy, and perform other operations on text.
  • Insert Mode: Used for inserting and editing text. Press “i” to enter Insert mode.
  • Visual Mode: Enables you to select and manipulate blocks of text. Press “v” to enter Visual mode.
  • Command-line Mode: Allows you to enter VIM commands. Press “:” to enter Command-line mode.
  1. Basic Navigation:

Efficient navigation is at the core of VIM. Here are some essential commands to help you move through your text seamlessly:

  • Moving the Cursor:
    • Use the arrow keys to navigate character by character.
    • Press “h” to move left, “j” to move down, “k” to move up, and “l” to move right.
    • Alternatively, you can use the following commands:
      • “w” to move to the beginning of the next word.
      • “b” to move to the beginning of the previous word.
      • “0” (zero) to move to the beginning of the current line.
      • “$” to move to the end of the current line.
      • “gg” to move to the beginning of the file.
      • “G” to move to the end of the file.
  1. Editing and Manipulation:

VIM provides a rich set of commands for editing and manipulating text efficiently:

  • Inserting Text:
    • In Normal mode, press “i” to enter Insert mode. Start typing to insert text at the cursor position.
  • Deleting Text:
    • In Normal mode, use the following commands to delete text:
      • “x” to delete the character under the cursor.
      • “dd” to delete the current line.
      • “dw” to delete from the cursor position to the beginning of the next word.
      • “d$” to delete from the cursor position to the end of the line.
  • Copying and Pasting:
    • In Normal mode, use the following commands to copy and paste text:
      • “yy” to yank (copy) the current line.
      • “yw” to yank from the cursor position to the beginning of the next word.
      • “p” to paste the copied or deleted text below the cursor.
      • “P” to paste the copied or deleted text above the cursor.
  1. Searching and Replacing:

VIM offers powerful search and replace commands to quickly find and modify text:

  • Searching:
    • In Normal mode, use the “/” command followed by the search term to find occurrences.
    • Press “n” to move to the next occurrence and “N” to move to the previous occurrence.
  • Replacing:
    • In Normal mode, use the following commands to replace text:
      • “:s/old/new” to replace the first occurrence of “old” with “new” in the current line.
      • “:s/old/new/g” to replace all occurrences of “old” with “new” in the current line.
      • “:%s/old/new/g” to replace all occurrences of “old” with “new” in the entire file.
  1. Advanced Features:

VIM offers a wealth of advanced features and commands to enhance your editing experience. Here are a few notable examples:

  • Macros: Record and replay a sequence of commands.
  • Buffers: Manage multiple files simultaneously.
  • Split Windows: Divide the editor window into multiple panes.

Conclusion:

By mastering VIM commands, you unlock a world of unparalleled editing capabilities. With efficient navigation, powerful manipulation, and advanced features, VIM empowers you to edit text with precision and speed. Practice and explore the vast command set VIM offers, and soon you'll be wielding this text editor like a seasoned pro.

Embrace the power of VIM and elevate your text editing skills to new heights. Start incorporating these commands into your workflow and experience the productivity gains that come with mastering this exceptional editor.

VIM Commands

MODE
i – Enter insert mode
: – Enter command mode
esc – Return to normal mode from insert or replace mode
esc+esc- Return to normal mode from command or visual mode

EDITING
o – Insert a line below the current line, then enter insert mode
O – Insert a line above the current line, then enter insert mode
R – Enter replace mode
dd – Delete Line
v – Enter visual mode (highlighting)
V – Enter visual line mode (highlighting lines)
y – Yank
p – Paste
x – Delete Character
/search – Search
n – Next word on search
U – Undo
Ctrl+R – Redo

————
NAVIGATION
h j k l – Moving or arrow keys
10j – Move down 10 lines
H – Top line on screen
M – Middle line on screen
L – Bottom line on screen
gg – First line of the file
G – Last line of the file
w – Beginning of next word
e – The end of the current word
b – Beginning of current word
:20 – Line 20 of the file
0 – Beginning of current line
$ – End of current line

————
MANIPULATING FILES
:w – Save the current file
:wq – Save the current file and close it; exits vim if no open files remain
:q – Quit a file (Must Save)
:q! – Close a file without saving
😡 – Write any changes to the file and close the file

#vim #ubuntu #vimcommands

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button