DEV Community

Cover image for TIPS & TRICKS IN USING VIM
Frank
Frank

Posted on

TIPS & TRICKS IN USING VIM

Here are some tips and tricks to help you become more efficient with Vim:

Navigation

  1. Move by Word or Paragraph:

    • w / b: Move to the beginning of the next/previous word.
    • e / ge: Move to the end of the next/previous word.
    • { / }: Move to the beginning/end of the previous/next paragraph.
  2. Jump to Specific Lines:

    • :number (e.g., :25): Go to line 25.
    • G: Go to the last line.
    • gg: Go to the first line.
  3. Find Text:

    • /pattern: Search forward for the pattern.
    • ?pattern: Search backward for the pattern.
    • n: Go to the next occurrence of the search pattern.
    • N: Go to the previous occurrence of the search pattern.

Editing

  1. Replace Text:

    • r + char: Replace the character under the cursor with char.
    • R: Enter Replace Mode, allowing you to replace multiple characters until you press Esc.
  2. Change Text:

    • cw: Change (delete and switch to Insert Mode) the current word.
    • c$: Change from the cursor to the end of the line.
  3. Undo and Redo:

    • u: Undo the last change.
    • Ctrl-r: Redo the last undone change.
  4. Repeat Last Command:

    • .: Repeat the last change.

Visual Mode

  1. Select and Operate:
    • v: Select text character by character.
    • V: Select whole lines.
    • Ctrl-v: Select a block of text.
    • After selecting text, you can use d (delete), y (yank), c (change), etc.

Efficiency

  1. Use Macros:

    • Start recording a macro with q + register (e.g., q a to record into register a).
    • Perform the actions you want to record.
    • Stop recording with q.
    • Replay the macro with @register (e.g., @a to replay the macro stored in register a).
  2. Use Buffers and Tabs:

    • :e filename: Open a new file in a buffer.
    • :bnext / :bprev: Switch between buffers.
    • :tabnew: Open a new tab.
    • :tabnext / :tabprev: Switch between tabs.

Customization

  1. Edit .vimrc:

    • Add custom settings to ~/.vimrc to personalize Vim (e.g., set number to show line numbers).
  2. Install Plugins:

    • Use plugin managers like vim-plug, Vundle, or Pathogen to extend Vim's functionality (e.g., for syntax highlighting, code completion).

Helpful Commands

  1. Show Line Numbers:

    • :set number or :set nu: Show line numbers.
  2. Show Whitespace Characters:

    • :set list: Show whitespace characters (e.g., tabs, spaces).
  3. Get Help:

    • :help: Access Vim’s help documentation.
    • :help command: Get help for a specific command (e.g., :help :w).

These tips and tricks can help you navigate, edit, and customize Vim more effectively, making your workflow smoother and more efficient.

Top comments (2)

Collapse
 
dev_frank profile image
Frank

💡 Tips & Tricks in Using Vim: Unlock the full potential of Vim with our curated tips and tricks! Whether you're a beginner or a seasoned user, these insights will help you work smarter and faster. Dive in and take your Vim skills to the next level! 🚀 #VimTips #CodingEfficiency #VimMastery

Collapse
 
ivan_okafor_6160194c9d649 profile image
Ivan Okafor

Nice content 👍