Commit bf2ee9c4 authored by bobloblaw's avatar bobloblaw
Browse files

Updates vim.md

Auto commit by GitBook Editor
parent e2295444
Loading
Loading
Loading
Loading
+49 −32
Original line number Diff line number Diff line
# Vim

http://www.viemu.com/a-why-vi-vim.html
And also this classic answer: https://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim


## Core concepts

In vim you have the concept of buffers.

```
```bash
# List buffers
:buffers

@@ -18,69 +20,82 @@ In vim you have the concept of buffers.
## Movement - Motion commands

**Left,up,down,right**
hjkl

`hjkl`

**start of line**
0 (zero)

`0` (zero)

**end of line**
$

`$`

**beginning of next word**
w

`w`

**beginning of next word, defined by white space**
W

`W`

**end of the next word**
e

`e`

**end of the next word, defined by white space**
E

`E`

**back to the beginning of previous word**
b

`b`

**back to the end of previous word**
B

`B`

**go to next character of your choice**

If you want to go to the next comma
f,

`f,`

**start of file**
gg

`gg`

**end of file**
G

`G`

## Operators

Operators are commands that do things. Like delete, change or copy. 

c - change
ce - change until end of the word.
c$ - change until end of line.
`c` - change
`ce` - change until end of the word.
`c$` - change until end of line.


## Combining Motions and Operators

Now that you know some motion commands and operator commands. You can start combining them.

dw - delete word
d$ - delete to the end of the line
`dw` - delete word
`d$` - delete to the end of the line

## Count - Numbers

You can add numbers before motion commands. To move faster.

4w - move cursor three words forward
0 - move curso to the start of the line
`4w` - move cursor three words forward
`0` - move curso to the start of the line

You can use numbers to perform operations.
d3w - delete three words
`d3w` - delete three words

3dd - delete three lines
`3dd` - delete three lines


## Replace
@@ -88,31 +103,33 @@ d3w - delete three words
If you need to replace a character, there is no need to enter insert-mode. You can just use replace


Go to a character and the press **r** followed by the character you want instead.
Go to a character and the press `r` followed by the character you want instead.

**rp** if you want to replace p.
`rp` if you want to replace p.

**R**
`R`

## Clipboard

In order to copy something FROM vim to the OS-clipboard you can do this:

The **"** means that we are not entering a registry. And the * means the OS-clipboard. So we are yanking something and putting it in the OS-clipboard registry.
The `"` means that we are not entering a registry. And the `*` means the OS-clipboard. So we are yanking something and putting it in the OS-clipboard registry.

```
"*y
```

## Substitute - Search and replace

:s/thee/the/g

## Entering insert-mode

i
o
O
a
A
`i` - current character
`o` - next line
`O` - line before
`a` - end of word
`A` - end of line

## .vimrc

@@ -128,4 +145,4 @@ https://github.com/VundleVim/Vundle.vim

Add plugin to your .vimrc-file and then open vim and write

**:PluginInstall**
 No newline at end of file
`:PluginInstall`
 No newline at end of file