mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[vim/en] add additional fold commands and visual regex; reformat
accordingly
This commit is contained in:
parent
a52f5d2c26
commit
d259c3bc42
@ -19,70 +19,71 @@ specific points in the file, and for fast editing.
|
|||||||
## Basics of navigating Vim
|
## Basics of navigating Vim
|
||||||
|
|
||||||
```
|
```
|
||||||
vim <filename> # Open <filename> in vim
|
vim <filename> # Open <filename> in vim
|
||||||
:help <topic> # Open up built-in help docs about <topic> if any exists
|
:help <topic> # Open up built-in help docs about <topic> if any exists
|
||||||
:q # Quit vim
|
:q # Quit vim
|
||||||
:w # Save current file
|
:w # Save current file
|
||||||
:wq # Save file and quit vim
|
:wq # Save file and quit vim
|
||||||
ZZ # Save file and quit vim
|
ZZ # Save file and quit vim
|
||||||
:q! # Quit vim without saving file
|
:q! # Quit vim without saving file
|
||||||
# ! *forces* :q to execute, hence quiting vim without saving
|
# ! *forces* :q to execute, hence quiting vim without saving
|
||||||
ZQ # Quit vim without saving file
|
ZQ # Quit vim without saving file
|
||||||
:x # Save file and quit vim, shorter version of :wq
|
:x # Save file and quit vim, shorter version of :wq
|
||||||
|
|
||||||
u # Undo
|
u # Undo
|
||||||
CTRL+R # Redo
|
CTRL+R # Redo
|
||||||
|
|
||||||
h # Move left one character
|
h # Move left one character
|
||||||
j # Move down one line
|
j # Move down one line
|
||||||
k # Move up one line
|
k # Move up one line
|
||||||
l # Move right one character
|
l # Move right one character
|
||||||
|
|
||||||
Ctrl+B # Move back one full screen
|
Ctrl+B # Move back one full screen
|
||||||
Ctrl+F # Move forward one full screen
|
Ctrl+F # Move forward one full screen
|
||||||
Ctrl+D # Move forward 1/2 a screen
|
Ctrl+D # Move forward 1/2 a screen
|
||||||
Ctrl+U # Move back 1/2 a screen
|
Ctrl+U # Move back 1/2 a screen
|
||||||
|
|
||||||
# Moving within the line
|
# Moving within the line
|
||||||
|
|
||||||
0 # Move to beginning of line
|
0 # Move to beginning of line
|
||||||
$ # Move to end of line
|
$ # Move to end of line
|
||||||
^ # Move to first non-blank character in line
|
^ # Move to first non-blank character in line
|
||||||
|
|
||||||
# Searching in the text
|
# Searching in the text
|
||||||
|
|
||||||
/word # Highlights all occurrences of word after cursor
|
/word # Highlights all occurrences of word after cursor
|
||||||
?word # Highlights all occurrences of word before cursor
|
?word # Highlights all occurrences of word before cursor
|
||||||
n # Moves cursor to next occurrence of word after search
|
n # Moves cursor to next occurrence of word after search
|
||||||
N # Moves cursor to previous occurrence of word
|
N # Moves cursor to previous occurrence of word
|
||||||
|
|
||||||
:%s/foo/bar/g # Change 'foo' to 'bar' on every line in the file
|
:%s/foo/bar/g # Change 'foo' to 'bar' on every line in the file
|
||||||
:s/foo/bar/g # Change 'foo' to 'bar' on the current line
|
:s/foo/bar/g # Change 'foo' to 'bar' on the current line
|
||||||
:%s/\n/\r/g # Replace new line characters with new line characters
|
:%s/\n/\r/g # Replace new line characters with new line characters
|
||||||
|
:'<,'>s/foo/bar/g # Change 'foo' to 'bar on every line in the current visual selection
|
||||||
|
|
||||||
# Jumping to characters
|
# Jumping to characters
|
||||||
|
|
||||||
f<character> # Jump forward and land on <character>
|
f<character> # Jump forward and land on <character>
|
||||||
t<character> # Jump forward and land right before <character>
|
t<character> # Jump forward and land right before <character>
|
||||||
|
|
||||||
# For example,
|
# For example,
|
||||||
f< # Jump forward and land on <
|
f< # Jump forward and land on <
|
||||||
t< # Jump forward and land right before <
|
t< # Jump forward and land right before <
|
||||||
|
|
||||||
# Moving by word
|
# Moving by word
|
||||||
|
|
||||||
w # Move forward by one word
|
w # Move forward by one word
|
||||||
b # Move back by one word
|
b # Move back by one word
|
||||||
e # Move to end of current word
|
e # Move to end of current word
|
||||||
|
|
||||||
# Other characters for moving around
|
# Other characters for moving around
|
||||||
|
|
||||||
gg # Go to the top of the file
|
gg # Go to the top of the file
|
||||||
G # Go to the bottom of the file
|
G # Go to the bottom of the file
|
||||||
:NUM # Go to line number NUM (NUM is any number)
|
:NUM # Go to line number NUM (NUM is any number)
|
||||||
H # Move to the top of the screen
|
H # Move to the top of the screen
|
||||||
M # Move to the middle of the screen
|
M # Move to the middle of the screen
|
||||||
L # Move to the bottom of the screen
|
L # Move to the bottom of the screen
|
||||||
```
|
```
|
||||||
|
|
||||||
## Help docs:
|
## Help docs:
|
||||||
@ -104,28 +105,28 @@ Vim is based on the concept on **modes**.
|
|||||||
- Ex Mode - used to drop down to the bottom with the ':' prompt to enter commands
|
- Ex Mode - used to drop down to the bottom with the ':' prompt to enter commands
|
||||||
|
|
||||||
```
|
```
|
||||||
i # Puts vim into insert mode, before the cursor position
|
i # Puts vim into insert mode, before the cursor position
|
||||||
a # Puts vim into insert mode, after the cursor position
|
a # Puts vim into insert mode, after the cursor position
|
||||||
v # Puts vim into visual mode
|
v # Puts vim into visual mode
|
||||||
: # Puts vim into ex mode
|
: # Puts vim into ex mode
|
||||||
<esc> # 'Escapes' from whichever mode you're in, into Command mode
|
<esc> # 'Escapes' from whichever mode you're in, into Command mode
|
||||||
|
|
||||||
# Copying and pasting text
|
# Copying and pasting text
|
||||||
# Operations use the vim register by default
|
# Operations use the vim register by default
|
||||||
# Think of it as vim's private clipboard
|
# Think of it as vim's private clipboard
|
||||||
|
|
||||||
# Yank ~ copy text into vim register
|
# Yank ~ copy text into vim register
|
||||||
y # Yank whatever is selected
|
y # Yank whatever is selected
|
||||||
yy # Yank the current line
|
yy # Yank the current line
|
||||||
|
|
||||||
# Delete ~ yank text and delete from file
|
# Delete ~ yank text and delete from file
|
||||||
d # Delete whatever is selected
|
d # Delete whatever is selected
|
||||||
dd # Delete the current line
|
dd # Delete the current line
|
||||||
|
|
||||||
p # Paste text in vim register after the current cursor position
|
p # Paste text in vim register after the current cursor position
|
||||||
P # Paste text in vim register before the current cursor position
|
P # Paste text in vim register before the current cursor position
|
||||||
|
|
||||||
x # Delete character under current cursor position
|
x # Delete character under current cursor position
|
||||||
```
|
```
|
||||||
|
|
||||||
## The 'Grammar' of vim
|
## The 'Grammar' of vim
|
||||||
@ -142,64 +143,75 @@ A few important examples of 'Verbs', 'Modifiers', and 'Nouns':
|
|||||||
```
|
```
|
||||||
# 'Verbs'
|
# 'Verbs'
|
||||||
|
|
||||||
d # Delete
|
d # Delete
|
||||||
c # Change
|
c # Change
|
||||||
y # Yank (copy)
|
y # Yank (copy)
|
||||||
v # Visually select
|
v # Visually select
|
||||||
|
|
||||||
# 'Modifiers'
|
# 'Modifiers'
|
||||||
|
|
||||||
i # Inside
|
i # Inside
|
||||||
a # Around
|
a # Around
|
||||||
NUM # Number (NUM is any number)
|
NUM # Number (NUM is any number)
|
||||||
f # Searches for something and lands on it
|
f # Searches for something and lands on it
|
||||||
t # Searches for something and stops before it
|
t # Searches for something and stops before it
|
||||||
/ # Finds a string from cursor onwards
|
/ # Finds a string from cursor onwards
|
||||||
? # Finds a string before cursor
|
? # Finds a string before cursor
|
||||||
|
|
||||||
# 'Nouns'
|
# 'Nouns'
|
||||||
|
|
||||||
w # Word
|
w # Word
|
||||||
s # Sentence
|
s # Sentence
|
||||||
p # Paragraph
|
p # Paragraph
|
||||||
b # Block
|
b # Block
|
||||||
|
|
||||||
# Sample 'sentences' or commands
|
# Sample 'sentences' or commands
|
||||||
|
|
||||||
d2w # Delete 2 words
|
d2w # Delete 2 words
|
||||||
cis # Change inside sentence
|
cis # Change inside sentence
|
||||||
yip # Yank inside paragraph (copy the para you're in)
|
yip # Yank inside paragraph (copy the para you're in)
|
||||||
ct< # Change to open bracket
|
ct< # Change to open bracket
|
||||||
# Change the text from where you are to the next open bracket
|
# Change the text from where you are to the next open bracket
|
||||||
d$ # Delete till end of line
|
d$ # Delete till end of line
|
||||||
```
|
```
|
||||||
|
|
||||||
## Some shortcuts and tricks
|
## Some shortcuts and tricks
|
||||||
|
|
||||||
<!--TODO: Add more!-->
|
<!--TODO: Add more!-->
|
||||||
```
|
```
|
||||||
> # Indent selection by one block
|
> # Indent selection by one block
|
||||||
< # Dedent selection by one block
|
< # Dedent selection by one block
|
||||||
:earlier 15m # Reverts the document back to how it was 15 minutes ago
|
:earlier 15m # Reverts the document back to how it was 15 minutes ago
|
||||||
:later 15m # Reverse above command
|
:later 15m # Reverse above command
|
||||||
ddp # Swap position of consecutive lines, dd then p
|
ddp # Swap position of consecutive lines, dd then p
|
||||||
. # Repeat previous action
|
. # Repeat previous action
|
||||||
:w !sudo tee % # Save the current file as root
|
:w !sudo tee % # Save the current file as root
|
||||||
:set syntax=c # Set syntax highlighting to 'c'
|
:set syntax=c # Set syntax highlighting to 'c'
|
||||||
:sort # Sort all lines
|
:sort # Sort all lines
|
||||||
:sort! # Sort all lines in reverse
|
:sort! # Sort all lines in reverse
|
||||||
:sort u # Sort all lines and remove duplicates
|
:sort u # Sort all lines and remove duplicates
|
||||||
~ # Toggle letter case of selected text
|
~ # Toggle letter case of selected text
|
||||||
u # Selected text to lower case
|
u # Selected text to lower case
|
||||||
U # Selected text to upper case
|
U # Selected text to upper case
|
||||||
J # Join the current line with the next line
|
J # Join the current line with the next line
|
||||||
|
|
||||||
# Fold text
|
# Fold text
|
||||||
zf # Create fold from selected text
|
zf # Create fold from selected text
|
||||||
zo # Open current fold
|
zd # Delete fold on the current line
|
||||||
zc # Close current fold
|
zD # Recursively delete nested or visually selected folds
|
||||||
zR # Open all folds
|
zE # Eliminate all folds in the window
|
||||||
zM # Close all folds
|
zo # Open current fold
|
||||||
|
zO # Recursively open nested or visually selected folds
|
||||||
|
zc # Close current fold
|
||||||
|
zC # Recursively close nested or visually selected folds
|
||||||
|
zR # Open all folds
|
||||||
|
zM # Close all folds
|
||||||
|
za # Toggle open/close current fold
|
||||||
|
zA # Recursively toggle open/close nested fold
|
||||||
|
[z # Move to the start of the current fold
|
||||||
|
]z # Move to the end of the current fold
|
||||||
|
zj # Move to the start of the next fold
|
||||||
|
zk # Move to the end of the previous fold
|
||||||
```
|
```
|
||||||
|
|
||||||
## Macros
|
## Macros
|
||||||
@ -210,9 +222,9 @@ you use, until you stop recording. On invoking a macro, it applies the exact
|
|||||||
same sequence of actions and commands again on the text selection.
|
same sequence of actions and commands again on the text selection.
|
||||||
|
|
||||||
```
|
```
|
||||||
qa # Start recording a macro named 'a'
|
qa # Start recording a macro named 'a'
|
||||||
q # Stop recording
|
q # Stop recording
|
||||||
@a # Play back the macro
|
@a # Play back the macro
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuring ~/.vimrc
|
### Configuring ~/.vimrc
|
||||||
|
Loading…
Reference in New Issue
Block a user