Skip to content

Instantly share code, notes, and snippets.

@saadlu
Last active May 10, 2024 09:48
Show Gist options
  • Save saadlu/c1280b6279765d33692409245bdfb4e0 to your computer and use it in GitHub Desktop.
Save saadlu/c1280b6279765d33692409245bdfb4e0 to your computer and use it in GitHub Desktop.

Find out

There are commands that start it's action as soon as you issue it, and there are some that requires additional arguments.

For example, ^ moves cursor to the first character on the line right away, but y requires additional argument to start executing.

Inserting, Changing, Replacing and Joining

key stroke Description
shift+j join lines
g shift+j do not add space when joining lines
~ change character under caret to uppercase
g ~ {motion} change the sequence covered by motion to uppercase

Searching, Finding and Replacing

key stroke Description
f {char} find the char on the line
F {char} find the char on the line, backwards
f {char}, ; repeat repeats the search
f {char}, , repeat repeats the search in opposite direction
t {char} Position cursor one position before the given char
T {char} Position cursor one position before the given char, backwards

Consider the following string

Delete THIS<<-- word.

To delete the THIS<<-- we can do

  1. Position cursor under T with f T
  2. d t w or d f [space] or d [Shift]+w or
key stroke Description
/ {word} search word
subsequently
n repeat
N repeat opposite direction
? {word} search for word backwards.
n repeats
N repeats in opposite direction
* find the next occurence of the word under or nearest to the word under the cursor
# find the next occurence of the word under or nearest to the word under the cursor, backwards

Combine commands::

  1. If we do d /This, vi will delete everything from current cursor to where it found This.
  2. If we are at the start of a line, and do "a y /z, vi will yank characters from the currect cursor to the first occurence of character z to register a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment