yesthattom: (Default)
[personal profile] yesthattom
For years I've taken advantage of the fact that one can use the "+" option in "vi" to have the editor open up at a particular position:

Example: Open the file file.txt for editing and position cursor at the 5th line:
vi +5 file.txt

Today I saw a shell script that opened to line "$" which positions the cursor at the last line. It's obvious that it would work ("$" means "last line" in the vi command line) but I had never thought of it:
vi +$ file.txt

Date: 2007-10-26 08:05 pm (UTC)
qnetter: (Default)
From: [personal profile] qnetter
Then I guess you're even less likely to be aware of:
   vi +/foo/ file.txt

Date: 2007-10-26 09:14 pm (UTC)
From: [identity profile] yesthattom.livejournal.com
Oddly enough, I've known and used that idiom for a while.

Date: 2007-10-26 08:33 pm (UTC)
From: [identity profile] dossy.livejournal.com
The humor here is that "$" means "end of line" not end of buffer, and that what you discovered is that "vi +" positions you at the end of the edit buffer, and that your shell is eating "$" silently as a shell metachar.

LOL. :-)

Date: 2007-10-26 09:18 pm (UTC)
From: [identity profile] yesthattom.livejournal.com
My shell doesn't eat the "$" since it is followed by a space.

However, if you do "vi +\$ file.txt" vi takes me to the end of the buffer, not end of the line.

In vi "$" means "last line" when in a line-number context. For example:

%s/search/replace/g
is the same as
1,$s/search/replace/g

% (all lines) is just an alias for "1,$" (from the first to the last).

This behavior was copied by awk.

Date: 2007-10-26 09:23 pm (UTC)
From: [identity profile] dossy.livejournal.com
Ah, yes, you're right, in a line context, "$" does mean "end of buffer" ... but in this case, vim at least treats "vi +" and "vi +$" both as "end of buffer."

Date: 2007-10-27 12:15 am (UTC)
geekosaur: LOPSA logo (lopsa)
From: [personal profile] geekosaur
Yep, vi + file has meant "open at end" ever since the original vi. And you can use any ex-level command after the +... which is why POSIX renamed it -c (since options not starting with - are verboten...).

December 2015

S M T W T F S
  12345
6789 101112
13141516171819
202122 23242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 3rd, 2026 04:03 pm
Powered by Dreamwidth Studios