Skip to content

Instantly share code, notes, and snippets.

@aldaris
Last active April 19, 2017 21:42
Show Gist options
  • Save aldaris/2b1d902c60c47986f6dc0e05624aebe1 to your computer and use it in GitHub Desktop.
Save aldaris/2b1d902c60c47986f6dc0e05624aebe1 to your computer and use it in GitHub Desktop.
vim tips
b - back a word
w - go to next word
e - go to the end of the current word
d - delete
y - copy
0 - go to the beginning of line
$ - go to the end of the line
o - insert new line and turn on editor mode
a - editor mode and move cursor one character (append)
i - editor mode and leave cursor at location (insert)
v - visual selection
gg - go to the top of the file
G - go to the bottom of the file
SHIFT + v - visual selection of lines
CTRL + v - visual selection of rows
:!<command> - executes <command> in shell without exiting vim, after pressing Enter you can get back to the editor
:%sort - sorts the lines in alphabetical order in the current file
:%s/hello/world/g - replaces all occurrences of hello with world in each line
:vsplit filename - vertical split of window, opening the file in a new pane
:set bg=dark - let's vim know that you are on dark background, which will result in using different syntax highlight palette
CTRL + W THEN arrows - switch between panes in the direction requested
:split filename - horizontal split of window, opening the file in a new pane
f<char> - finds <char> in current line
t<char> - finds <char> in current line and moves the cursor in front of the character
u - undo
CTRL + r - redo
r - replace one character (so r1 would replace the character at the current location with '1')
R - turn on REPLACE mode, every character hit will replace existing text
most fun bit:
q THEN character of your choice THEN stuff THEN q - turns on recording mode, everything you do, will be recorded as a macro under the character you have chosen, the final press of q will stop the recording
@<character of your choice> - execute your recorded macro once
10@<char> - execute macro associated with char 10 times
combine things:
dw - delete word from cursor
cw - change word from cursor (similar to dw, but unlike dw it will not remove whitespace, instead it will turn on editor mode and allow you to enter a new word)
y$ - copy until end of line
dd - delete line
d THEN down arrow - delete 2 lines
5dd - delete 5 lines
dt< - delete characters until '<' character (especially helpful when dealing with XMLs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment