Vim : Fight Power With Control

This is a meta-post. It is filled with vim commands to help you use the editor while playing with the code in the other posts and in the life.

Command Mode

  1. Saving in files:
    :w Saves the current file.
    :w! – Overwrites the current file.
    :w or :w! <file_Path> – Saves/Overwrites to/the <file_path>.
    :wq – A classic – save and exit.
    :h writing – Many other options for these commands, like  :wa (write to all buffers) for example.
  2. Executing shell commands:
    :!<command> – Executes the shell <command> (for example :!ruby %, which executes ruby on the current buffer).
    :!! – Repeats the last executed command.
    :sh – Starts the shell, you can type commands, compile files, etc, after typing exit you will return to Vim.
    :h shell – Detailed help the above commands.
  3. Enter in the Insert Mode (for typing text).
    :i – Enter Insert Mode, insert before the cursor.
    :I – Enter Insert Mode, insert in the beginning of the current line.
    :gi – Enter Insert Mode, from the position the last Insert Mode was exited.
    :o/:O – Insert new line bellow/above the line of the cursor and enter Insert Mode in the beginning of it.
    :a – Enter Insert Mode, insert after the cursor.
    :A Enter Insert Mode, insert at the end of the current line.
    :h insert – Help for the above commands.
    :i comes from insert, :a comes from append.

Normal Mode

  1. Saving files:
    ZZ – Save the current file and exit.
  2. Basic navigation
    h == left
    l == right
    j == down
    k == up
    G == End of the buffer/file
    gg == Beginning of the buffer/file
    0 == The beginning of the current line.
    $ == The end of the current line
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s