Professional Documents
Culture Documents
VIM Basics
VIM Basics
VIM Basics
the
hang of it. Here is a basic guide to help you start editing files with Vim:
Basic Usage
1. Opening a File:
• To open a file with Vim, use the command: vim filename.
2. Modes in Vim
• Normal Mode: This is the default mode where you can navigate the file and perform
commands. You enter this mode by pressing Esc.
• Insert Mode: This mode allows you to insert text. You enter this mode by pressing i
in Normal mode.
• Visual Mode: This mode is used to select text. You enter this mode by pressing v in
Normal mode.
• Command-Line Mode: This mode allows you to run commands. You enter this
mode by pressing : in Normal mode.
Basic Commands
Inserting Text
• Press i to enter Insert mode. You can now start typing text.
• Press Esc to return to Normal mode.
Navigation
• Arrow keys: Move the cursor up, down, left, and right.
• h, j, k, l: Move the cursor left, down, up, and right (in Normal mode).
• gg: Move to the beginning of the file.
• G: Move to the end of the file.
• w: Move to the start of the next word.
• b: Move to the start of the previous word.
• 0: Move to the beginning of the line.
• $: Move to the end of the line.
Editing
• x: Delete the character under the cursor.
• dd: Delete the current line.
• yy: Yank (copy) the current line.
• p: Paste the yanked or deleted text after the cursor.
• u: Undo the last change.
• Ctrl + r: Redo the last undone change.
• r: Replace the character under the cursor with the next character you type.
• cw: Change the word from the cursor onwards (deletes the word and enters Insert mode).
Visual Mode
• v: Enter Visual mode to select text.
• y: Yank (copy) the selected text.
• d: Delete the selected text.
• p: Paste the yanked or deleted text after the cursor.
Advanced Tips
• :set number: Show line numbers.
• :syntax on: Enable syntax highlighting.
• /search_term: Search for search_term in the file. Press n to go to the next occurrence and N
to go to the previous occurrence.
• :%s/old/new/g: Replace all occurrences of old with new in the file.
Customizing Vim
You can customize Vim by editing the ~/.vimrc file. Here are some common settings: