Home A short intro to VIM
Post
Cancel

A short intro to VIM

Vim

About Vim

  • Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient
  • an improved version of the vi editor distributed with most UNIX systems
  • Vim is a modal editor: it has different modes for inserting text vs manipulating text
  • Vim is programmable (with Vimscript and also other languages like Python)
  • Vim avoids the use of the mouse, because it’s too slow
  • Vim even avoids using the arrow keys because it requires too much movement

Vim has multiple operating modes

  • Normal: for moving around a file and making edits
  • Insert: for inserting text
  • Replace: for replacing text
  • Visual (plain, line, or block): for selecting blocks of text
  • Command-line: for running a command

changing modes

for default case followings keys are used

  • Normal Mode
  • i Insert mode
  • v visual mode
  • R replace mode
  • V visual line mode
  • : command line mode

Buffer tabs and windows

  • buffer is set of open files
  • Unlike other programs you are familiar with, like web browsers, there is not a 1-to-1 correspondence between buffers and windows
  • A given buffer may be open in multiple windows, even within the same tab which can be handy to view two different parts of file at same time

Command mode

This mode has many functionalities, including opening, saving, and closing files, and quitting Vim.

  • :q quit (close window)
  • :w save (“write”)
  • :wq save and quit
  • :e {name of file} open file for editing
  • :ls show open buffers
  • :help {topic} open help
    • :help :w opens help for the :w command
    • :help w opens help for the w movement

Movement

  • Basic movement: hjkl (left, down, up, right)
  • Words: w (next word), b (beginning of word), e (end of word)
  • Lines: 0 (beginning of line), ^ (first non-blank character), $ (end of line)
  • Screen: H (top of screen), M (middle of screen), L (bottom of screen)
  • Scroll: Ctrl-u (up), Ctrl-d (down)
  • File: gg (beginning of file), G (end of file)
  • Line numbers: :{number} or {number}G (line {number})
  • Misc: % (corresponding item)
  • Find: f{character}, t{character}, F{character}, T{character}
    • find/to forward/backward {character} on the current line
    • , / ; for navigating matches
  • Search: /{regex}, n / N for navigating matches

Edits

  • o / O insert line below / above
  • d{motion} delete {motion}
    • dw is delete word
    • d$ is delete to end of line
    • d0 is delete to beginning of line
  • c{motion} change {motion}
    • cw is change word
  • x delete character (equal do dl)
  • s substitute character (equal to xi)
  • Visual mode + manipulation
    • select text, d to delete it or c to change it
  • u to undo, to redo
  • y to copy / “yank” (some other commands like d also copy)
  • p to paste

Counts

  • 3w move 3 words forward
  • 5j move 5 lines down
  • 7dw delete 7 words

Modifiers

  • to change meaning of nouns
  • i which means “inner”
  • a which means “around”
  • ci( change the contents inside the current pair of parentheses
  • ci[ change the contents inside the current pair of square brackets
  • da’ delete a single-quoted string, including the surrounding single quotes

Customization

  • Vim is customized through a plain-text configuration file in ~/.vimrc

Extending Vim

There are tons of plugins for extending vim. Some popular ones are

  • ctrlp.vim: fuzzy file finder
  • ack.vim: code search
  • nerdtree: file explorer
  • vim-easymotion: magic motions

All above plugins are available here

This post is licensed under CC BY 4.0 by the author.
Recently Updated
Trending Tags
Contents
Trending Tags