zzmove the current line to the middle of the screen
wgo to the next word
bgo to the previous word
ego to the end of the word
W/B/Esame as above, but only treats whitespace as a separator
Hgo to the first line of current screen.
Mgo to the middle line of current screen.
Lgo to the last line of current screen.
CTRL-fjump forward one full screen.
CTRL-bjump backwards one full screen
CTRL-djump forward (down) a half screen
CTRL-ujump back (up) one half screen
Convert tabs to spaces
expandtab is on
Strip trailing whitespace
Close all open buffers
:sp (horizontal split) :vsp (vertical split)
Jumping around them
CTRL-<hjkl> (movement keys) <LEADER>-<hjkl>
Open a split with a specific file
:sp filename :vsp filename
- courtesy of https://github.com/mtth/scratch.vim plugin
gsin normal mode opens the scratch window and enters insert mode. The scratch window closes when you leave insert mode. = can also use
Uppercase a word
Highlight the lines you want to sort, and then execute
Vim lets you run any command line tool on a buffer/ selection of text via the following format, where
range is the selection of text, and
filter is the command to run. The output of the command, when fed the filter, replaces the selection:
Requires that the
jq command is installed.
% references the current buffer.
Execute command on range
:key puts you into command line mode
- You can then specify a range, such as
%, which represents the entire file (alternatively, use visual mode to select the range you want and then enter command mode)
normaltell the command line to run the rest of the sequence in normal mode
- A command such as
$x(or any other normal mode incantation) can be used, and will execute over the entire selection
So, for example, to delete the last character of every line in the buffer, run:
Execute command on multiple lines
g command is the "global" command to execute other commands. In this case, you can use it with the
norm command to perform a change on lines that match a specific pattern (or all lines).
For example, if you want to add a semicolon to the end of all lines that start with a number, you could do that as follows:
In this case, instead of substituting the line for something else, you are telling Vim to execute the "normal mode" command of moving to the end of the line and entering insert mode (with
A), and then adding a semicolon.
This is pretty powerful because you have the ability to perform a motion on all the lines matching a specific pattern.
Visual select and insert
Once you have selected the block you want, you can edit all of the selected lines at once with:
SHIFT-i (insert whatever you want) <ESC>