Giter Club home page Giter Club logo

vim-help's Introduction

Vim Help

Basics

Case matters

When I write upper or lower case for a command, that exact case is meant.

Exiting vim

First press/spam Escape to go to normal mode!

  • :q to quit without changes
  • :q! to quit, discarding any changes
  • :wq to write any changes and quit
  • :x practically the same as wq, however this only actually writes when changes have been made (and it's shorter ;))

Modes

  • Insert, where you write!
  • Normal, where you can exit, thank Bob
  • Visual, to select, copy/paste, delete

Insert

The most used method to go into insert mode is by simply pressing i, for insert.

This will insert the cursor at the position of the cursor.

However, what you will most likely want 9/10 times is append with a, which will insert the cursor after the current position.

You can also insert at the beginning of the line with I, or at the end of the line with A.

Makes sense right?

Insert mode also has some shortcuts. You will probably use Ctrl+w to delete the previous word most often.

PS: Did you know Ctrl+w has the same effect in most terminals?

Replace

With r you can replace the character under the cursor. Example rG

With R you will enter replace mode (insert but overwriting existing text)

Normal

Esape to normal mode, never get stuck again in vim.

This is where you navigate, search, make small changes/deletions.

Visual

Visual mode has several sub-modes, which you can all enter from normal mode (Escape!)

  • v - Regular visual mode, to work similarly to how you would work in edit mode
  • V - Visual line mode, to work with entire lines
  • Ctrl+v - Visual block mode, to work with, well, blocks of text

Navigation

H J K L!

  • H = Left
  • J = Down
  • K = Up
  • L = Right

Arrow keys work too and function the same...

Use 0 to go the start of a line, and $ to go the end.

Use w to jump to the next word. W to jump a word-with-punctuation.and_stuff

Adversely, b and B to go back.

Two commands I personally find really useful are gg to go to the top of the document, and G to go to the bottom!

Repeat

You can repeat actions by prepending with a number!

Examples:

  • 5j will go down 5 lines
  • 3W to jump three words-with-punctuation to the right

Searching

In normal mode, press / to search.

Some symbols have to be escaped...

n to go to the next result

N to go to the previous!

Find & Replace

Find and replace all instances:

:%s/potato/tomato/g

Explanation:

  • s stands for substitute
  • % is a shortcut for using the entire document
  • g means global; this is required to change all occurrences in a line

Remember :%s and don't forget the g!

Selection

In any of the visual modes, just browse around!

Remember you can repeat commands!

V, 3k to select the current line and the 3 lines above it

You can also select from the cursor to a search result:

v, /my-word

And then execute commands on it:

  • :s/foo/bar/g will replace all occurrences of foo with bar in the selection
  • > to indent
  • ~ to switch case

Copy & Paste

With a selection, press y to yank (aka copy), or d to delete!

Then you can paste:

  • after the cursor with p
  • before the cursor with P

Remember you can combine this with navigation!

Indentation

Depends on your tabstop settings!

In normal mode:

Indentation, press >> or << to indent the current line.

Example: >5j to indent the current line and the 5 lines below it.

Configuration

You can configure vim with a .vimrc file in your $HOME (cd ~ should work on every system, including Windows with PowerShell)

Recommended:

" This is a comment
syntax on

set encoding=UTF-8

set tabstop=8       " This will _display_ actual tabs as 8-wide (default on most systems)
set softtabstop=4
set shiftwidth=4    " This will insert 4 spaces when you press tab.
set expandtab       " This will automatically convert tabs to spaces!

Other options:

  • set number to see line numbers
  • set nonumber to disable
  • set relativenumber to show how far away from other lines your cursor is, super convenient for navigation!
  • set norelativenumber to disable as well

Note that you can tab-complete these options. :)

Tutorials

Plugins

Vim Awesome is an awesome site with a list of plug-ins.

vim-help's People

Contributors

alveel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.