My guess is that I'll add more hints & tips to this posting, so be sure to bookmark it and revisit every now and then.
-- David 10Oct2010
Task: You want to enter command mode to try all of the commands in the rest of this page:
# press Esc key
<ESC>
Task: You want to find whole words spelled "the", excluding words like "them".
<ESC>
/\<the\>
Task: You have a text file of numbers representing some of your customer account ID numbers. You're creating an SQL query statement and you want to corral those numbers into an IN clause like "... where clientId in (333, 444, 555...). But the 10 numbers are listed, one by one, on ten lines. How do you get them collected into your IN claus?
First thing, you want to append commas after each number, with the exception of the 10th number.
# replace the endline of each line with a comma.
# to avoid putting a comma after the 10th number, specify the line range as 1 through 9.
:1,9s/$/,/g
Now it's time to bring everything onto a single line. Do this using "J" for join.
# Join the 10 lines onto a single line
<ESC>
:10J
You should see all 10 numbers on the same line now. Fill out the rest of your SQL query.
Task: You have a bunch of concatenated strings that each should occupy a single line. Each string is separated by the damn ^M characters that do nothing to create a visual line break.
<ESC>
:1,$s/<cntr-v>M/\\r/g
Task: You want to insert "</span>" between "Task" and ":", like I did when I decided to wrap a span tag around each Task word in this blog posting.
<ESC>
:1,$s/Task:/Task<\/span>:/g
Task: You want to jump to the 13th line in your text file.
<ESC>
:13
Task: Come back on occassion to see additional vi editor tasks here.
# At your browser's URL:
http://discretepassions.blogspot.com/2010/10/little-things-in-vi-that-may-folks.html