Unleash your inner root

Vim: Bust a Move!

Software      : VIM
Version       : 7.4.629
Compatibility : Any Modern Copy of VIM

I could go on an epic rant about why vim is the best editor ever (In fact, the first attempt at this article turned into exactly that, and will likely re-surface at a later date in the “Admins Log”)

Today though I’d like to share some of the movement techniques that make vim truly powerful. Some of them are common knowledge among vim users everywhere, others are a bit lesser known. As I say often in my sed guides: Practice these things, force them to become rote. Once you master them, your world will be changed forever.

Lets start with the basics, These many of you likely know:

k  # Moves up one character
h  # Moves back one character
l  # Moves forward one character
j  # Moves down one character

As I mentioned, these are the ones everyone that has spent a day with vim knows well. They are your bread and butter for movement commands, but they are only the beginning.

Lets talk about beginnings and ends!

gg  # jumps to the beginning of the file.
0   # Jumps to the beginning of the line.
b   # Jumps to the beginning of the previous "word", or of the current "word" if your cursor is already past the beginning.
w   # Jumps to the beginning of the next "word".
ge  # Jumps to the end of the Previous "word"
e   # Jumps to the end of the current "word", or of the next "word" if your cursor is already at the end of the current word.
$   # Jumps to the end of the line.

You may have noticed that I put the word “word” in quotes. That is because there are two versions of each of those next/previous word commands, the standard, and the capitals.

# lowercase versions jump to the next/previous "word"
# Uppercase versions jump to the next/previous "WORD"

So, whats the difference between a “word” and a “WORD”? Symbols!
Take this example:


Hashtag, Word, Semi-colon. That example is three “words” but only one “WORD”. So when moving forward by a word, assuming your cursor is on the “#”, you would then move to “Example”, and then to “;”. where as moving forward by a WORD you would move from “#” past the “;” and to the next word in a line.

And lastly (at least for this tutorial, there are quite a few other tricks out there that may get covered later) lets talk about two other simple sets of key’s

( # Move back one sentence. In this case a Sentence is defined as line of text ending with some form of punctuation: IE: . or !
) # Move forward by one sentence. See above.

{ # Move back one paragraph, this moves between blocks of text separated by an empty line.
} # Move forward one paragraph. See above.

This concludes some advanced-basic Movement techniques. There are more out there in the wide world of vim, but these are the ones that are most beneficial in most situations. More on the supreme glory of vim will be written in the near future. Tune in next time meta wizards!

file manipulationvim

Brandon.Graves • December 28, 2015

Previous Post

Next Post

Leave a Reply

Your email address will not be published / Required fields are marked *

%d bloggers like this: