vim
Table of Contents
Syntax Highlighting
:syntax on
This can also be added to .vimrc
Yank or delete between parentheses
Motion select
These work for matching parenthesis (), square brackets [], curly brackets {}, angle brackets <>, etc…
y% - yank d% - delete
For visual mode
v%y - highlight between parenthesis and yank v%d - highlight between parenthesis and delete
Object select
With the cursor within a block
yab - yank the block including the enclosing parenthesis dab - delete the block including the enclosing parenthesis yib - yank the block excluding the enclosing parenthesis dib - delete the block excluding the enclosing parenthesis
For visual mode
v2a) - visual select, 2 nesting levels, including the enclosing parenthesis v1i) - visual select, 1 nesting level, excluding the enclosing parenthesis
Comment/Uncomment multiple lines
Comment
- Enter visual mode:
v - Select the lines to comment.
- Add the line comment characters to the beginning of each line:
:s/^/# - shell scripts :s/^/\/\/ - C, C++, C#, Java, JavaScript :s/^/-- - SQL
Uncomment
- Enter visual mode:
v - Select the lines to comment.
- Remove the line comment characters to the beginning of each line:
:s/^#/ - shell scripts :s/^\/\// - C, C++, C#, Java, JavaScript :s/^--/ - SQL
Auto Indentation
:set autoindent :set cindent
Add/Remove indentation
- Enter visual mode:
v - Select the lines to indent.
>to increase indent one tab<to decrease indent one tab.n>to increase indentntabs.n<to decrease indentntabs.
Replace word with copied text
- Yank (or delete) the text into a buffer:
yw- to yank a word. - Move to the beginning of the word to replace.
vwp-vfor visual select,wfor the word,pto paste.
Reload the current file from disk
- Reload the current file:
:edit(without specifying a file name) - Reload the current file after it's been modified:
:edit!
Change Case
- Change word to lowercase:
guw - Change word to uppercase:
gUw - Toggle word case (aBBa → AbbA):
g~w
vim.txt · Last modified: 2023/08/18 18:15 by 127.0.0.1