Added a few more commands into the reference, and tidied up a little

master
Nathan Steel 6 years ago
parent bdde36c80e
commit 10913c2cda

100
vim.md

@ -1,6 +1,14 @@
# Vim Reference
This is intended as a brief reference for beginners.
Vim does have a built in reference for each key, that can be accessed via
:h <key>
# Basics # Basics
Inserting text, saving and closing the buffer ## Inserting Text
`i` - Insert Text at the cursor `i` - Insert Text at the cursor
@ -10,6 +18,12 @@ Inserting text, saving and closing the buffer
`A` - Insert text at the end of the line `A` - Insert text at the end of the line
`o` - Insert a new line below the current line
`O` - Inserts a new line above the current line
## Saving and Quitting
`esc` - Pressing escape will put you in normal mode, then pressing `:` `esc` - Pressing escape will put you in normal mode, then pressing `:`
will put you into command mode will put you into command mode
@ -19,11 +33,13 @@ will put you into command mode
`Ctrl + ZZ` - Write and quit (`:wq`) `Ctrl + ZZ` - Write and quit (`:wq`)
`Ctrl + ZQ` - Force quit (`:q!`) `Ctrl + ZQ` - Force quit (`:q!`)
# Movement # Motions for Movement
These can also be used with other commands, such as dw to delete to next word Motions can also be used with other commands, such as dw to delete to next word
or while selecting a visual block. or while selecting a visual block.
Vim reference `:h motion.txt`
`h,l` - Left, Right `h,l` - Left, Right
`j,k` - Down, Up `j,k` - Down, Up
@ -47,8 +63,30 @@ or while selecting a visual block.
`5w` - Move forwards 5 words, this also works with most commands `5w` - Move forwards 5 words, this also works with most commands
`f<character>` - Moves to the next occurance of that character, good for quotes
`%` - Jump to matching parenthesis, either forwards or back
# Visual Selection
Visually highlight the selection being made
`v` - Select characters
`V` - Select entire lines
`Ctrl + v` - Visual block selection
Visual mode, can also be used with motions
`vi(` - Visually select the inside of some parenthesis
`va{` - Visual select the the {} and their contents
# Deleting and Clipboard # Deleting and Clipboard
Deleting, yanking, and pasting. Like other commands, can use motions too!
`x` - Delete/cut character under cursor `x` - Delete/cut character under cursor
`d` - Delete/cut selection `d` - Delete/cut selection
@ -81,15 +119,47 @@ or while selecting a visual block.
`N` - Previous search result `N` - Previous search result
# Replace/Change # Replace/Change/Substitute
c Change ## Replace
cw
ci( - Change inside ( { " `r<character>` - Replaces the whatever is at the cursor with the character
:s/x/y Replace x for y on the selected line
:%s/x/y Replace x for y on each line `R` - Replace mode. This enters an insert mode that writes over everything.
## Change
The more powerful alternative of replace
`c` - Change. This will delete the selection, and put you into insert mode
Yet again, this command can make use of, and gets its power from motions!
`cw` - Change word
`c$` - Change contents to the end of the line
`ci(` - Change inside ( { "
## Substitute
This is the "change and replace" of vim. It makes use of regex.
`:s/x/y` - Replace the first instance of x to y on the selected line
`:s/x/y/g` - Replace globally all instances of x to y on the current line.
`:%s/x/y/g` - Replace all instances of x to y on each line
`:s/x/y/gc` - Replace all instances on the line, but prompt for each change
# Cool stuff
`.` - Repeats the last command. Eg. ci( will occur again
# Buffers Splits Multitasking # Buffers Splits Multitasking
Vim can open numerous files/buffers at the same time.
These can be in tab like buffers, or in a splitscreen view.
:r :r
:e filename :e filename
:bn :bn
@ -101,9 +171,13 @@ ci( - Change inside ( { "
Ctrl + ww Ctrl + ww
Ctrl + wr Switch the splits around Ctrl + wr Switch the splits around
# Visual Selection # Setting variables in Vim
Vim has extra features disabled by default, that can be very useful!
`:set lines` - This adds line numbers
`v` - Select lines `:syntax on` - Turns syntax highlighting on
`V` - Select the current line
`Ctrl + v` - Visual selection in characters
These variables can be added into a file called ~/.vimrc to automatically run
every time vim opens.

Loading…
Cancel
Save