Skip to content

Instantly share code, notes, and snippets.

@ahndmal
Last active July 1, 2023 15:11
Show Gist options
  • Save ahndmal/a015c466d8c4ae9999727d7d239f48bb to your computer and use it in GitHub Desktop.
Save ahndmal/a015c466d8c4ae9999727d7d239f48bb to your computer and use it in GitHub Desktop.
============= modes
v - visual
i, I, o, O, - insert
R - replace
c - change mode
C - change from position till end of line
Esc - quit mode
============= navigation
b, B - back 1 word
w - 1 word forth
'z + Enter' - center screen
=============
'u' - undo
'Ctrl + r' - redo
======
'yy' - copy line
'y2w' - copy 2 words
'P' - paste before
'p' - paste
'x' - delete char
'X' - backspace
'dd' - delete line
'd$' - delete till end of line
'd2w' - delete 2 words
=== upper / lowercase
U - make UPPERCASE
u - make lowercase
~ - change case
g~{motion} - change whole motion (g~w - change word to uppercase)
or
gUw - make word uppercase
gUU / g~$ - make line uppercase
===================== registers
:reg - registers
"" - contains last operated on text
"[0-...] - register number
"_dd - delete to BLACK HOLE register
=== named registers [a-z]
"[a-z]{cmd}
"ayy - add 'yy' to 'a' register
"Ayy - append to 'a' register
"ap - paste from 'a' register
====== Find / Replace
f[a-z] - go to next [a-z]
Shift + f + [a-z] - back
; - keep searching / go next item
, - go to previous item
t + [a-z] - go to char next to item
/ - find
n - next
N - back
:s - substiture
:s/from/to/[flags]
[range]s/from/to/[flags]
. - first line
$ - last line
% - all lines
:s/from/to/ - find and replace
:1,5s/from/to/g - find and replace for first 5 lines
:.,$s/from/to/g - replace from 1st to last lines
:%s/from/to/g - replace from 1st to last lines
patterns:
:s#/var/tmp#/usr/local#
======= :set
is / icsearch - incremental search
hls / hlsearch - highlight search
:set {cmd}? - check if s enabled
:set nu / nonu - numbering ON / OFF
============ text objects
{action}{inner-object}{motion}
i / a - inner / whole
diw - delete Inner word
daw - delete all word
das - delete all sentence
ci[ = ci] - change inside brackets
at / it - TAG object (e.g. HTML tag <p>)
ci{ - change all inside { }
============= macros
Note: better use 0 after start recording to be at the beginning of the line
q[reg] - start/stop recording (e.g. "qa")
@[reg] - to replay the macro use @ followed by register (e.g. "@a")
@@ - repeat last macro
:27,35normal @d - apply macro with reg 'd' to lines 27-35
// write macro to .vimrc
let @e = '0:s/"/'^M...'
let @t = 'ITODO: ^[j'
========= visual
v - char-wise mode
V - line-wise mode
Ctrl + v - block-wise mode
~ - switch case
c - change
d - delete
y - yank
r - replace
x - delete
I - insert
A - append
J - join
u - make lowercase
U - make Uppercase
> - shift right (indent right)
< - shift left (indent left)
gv - previous visual selection
:'<,'> - visual area selection
:'<,'>center - center selected area (ce)
============ settings
:set nu
:set nu?
:set history=500
ctrl + g - show file working on
:buffers / :files / :ls - list buffers (files)
:buffer file1 - open file 1 by name
:b 2 - open file 2 by id
:bn - next file
:bp(revious) - previous file
:bf / :bl - first/last file
Ctrl + ^ - switch file
:wall / :qall! - save/quit all buffers
:bd - delete buffer
===================== windows
Ctrl + w, s - add window
Ctrl + w, q - close window
:vs (ctrl + w, v) - view split
Ctrl + w, [h,j,k,l] - navigate through windows
Ctrl + w, + / - - change size
====================== Plugins
:set packpath
:packadd {addon-name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment