Last active
June 20, 2021 21:47
-
-
Save awkale/e9be49111319b0b28b206b5aa217f7fb to your computer and use it in GitHub Desktop.
#vim #cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:q[uit] | |
# Quit Vim. This fails when changes have been made. | |
:q[uit]! | |
# Quit without writing. | |
:cq[uit] | |
# Quit always, without writing. | |
:wq | |
# Write the current file and exit. | |
:wq! | |
#Write the current file and exit always. | |
:wq {file} | |
# Write to {file}. Exit if not editing the last | |
:wq! {file} | |
# Write to {file} and exit always. | |
:[range]wq[!] | |
# [file] Same as above, but only write the lines in [range]. | |
ZZ | |
# Write current file, if modified, and exit. | |
ZQ | |
# Quit current file and exit (same as ":q!"). | |
# EDITING A FILE | |
:e[dit] | |
# Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim. | |
:e[dit]! | |
# Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again. | |
:e[dit] {file} | |
# Edit {file}. | |
:e[dit]! {file} | |
# Edit {file} always. Discard any changes to the current buffer. | |
gf | |
#Edit the file whose name is under or after the cursor. Mnemonic: "goto file". | |
# INSERTING TEXT | |
a | |
# Append text after the cursor [count] times. | |
A | |
# Append text at the end of the line [count] times. | |
i | |
# Insert text before the cursor [count] times. | |
I | |
# Insert text before the first non-blank in the line [count] times. | |
gI | |
# Insert text in column 1 [count] times. | |
o | |
# Begin a new line below the cursor and insert text, repeat [count] times. | |
O | |
# Begin a new line above the cursor and insert text, repeat [count] times. | |
# INSERTING A FILE | |
:r[ead] [name] | |
# Insert the file [name] below the cursor. | |
:r[ead] !{cmd} | |
# Execute {cmd} and insert its standard output below the cursor. | |
# DELETING TEXT | |
x | |
# Delete [count] characters under and after the cursor | |
X | |
# Delete [count] characters before the cursor | |
d{motion} | |
# Delete text that {motion} moves over | |
dd | |
# Delete [count] lines | |
D | |
# Delete the characters under the cursor until the end of the line | |
{Visual}x | |
{Visual}d | |
# Delete the highlighted text. | |
{Visual}CTRL-H | |
{Visual} | |
# When in Select mode: Delete the highlighted text | |
{Visual}X | |
{Visual}D | |
# Delete the highlighted lines | |
:[range]d[elete] | |
# Delete [range] lines (default: current line) | |
:[range]d[elete] {count} | |
# Delete {count} lines, starting with [range] | |
# CHANGING OR REPLACING TEXT | |
r{char} | |
# replace the character under the cursor with {char}. | |
R | |
# Enter Insert mode, replacing characters rather than inserting | |
~ | |
# Switch case of the character under the cursor and move the cursor to the right. If a [count] is given, do that many characters. | |
~{motion} | |
# switch case of {motion} text. | |
{Visual}~ | |
# Switch case of highlighted text | |
# COPYING AND MOVIN | |
"{a-zA-Z0-9.%#:-"} | |
# Use register {a-zA-Z0-9.%#:-"} for next delete, yank or put (use uppercase character to append with delete and yank) ({.%#:} only work with put). | |
:reg[isters] | |
# Display the contents of all numbered and named registers. | |
:reg[isters] {arg} | |
# Display the contents of the numbered and named registers that are mentioned in {arg}. | |
:di[splay] [arg] | |
# Same as :registers. | |
["x]y{motion} | |
# Yank {motion} text [into register x]. | |
["x]yy | |
# Yank [count] lines [into register x] | |
["x]Y | |
# yank [count] lines [into register x] (synonym for yy). | |
{Visual}["x]y | |
# Yank the highlighted text [into register x]. | |
{Visual}["x]Y | |
# Yank the highlighted lines [into register x] | |
:[range]y[ank] [x] | |
# Yank [range] lines [into register x]. | |
:[range]y[ank] [x] {count} | |
# Yank {count} lines, starting with last line number in [range] (default: current line), [into register x]. | |
["x]p | |
# Put the text [from register x] after the cursor [count] times. | |
["x]P | |
# Put the text [from register x] before the cursor [count] times. | |
["x]gp | |
# Just like "p", but leave the cursor just after the new text. | |
["x]gP | |
# Just like "P", but leave the cursor just after the new text. | |
:[line]pu[t] [x] | |
# Put the text [from register x] after [line] (default current line). | |
:[line]pu[t]! [x] | |
# Put the text [from register x] before [line] (default current line).G TEXT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment