Unix tip of the day
Oct. 26th, 2007 03:57 pmFor 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:
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:
Example: Open the file file.txt for editing and position cursor at the 5th line:
vi +5 file.txtToday 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
no subject
Date: 2007-10-26 08:05 pm (UTC)no subject
Date: 2007-10-26 08:33 pm (UTC)LOL. :-)
no subject
Date: 2007-10-26 09:14 pm (UTC)no subject
Date: 2007-10-26 09:18 pm (UTC)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.
no subject
Date: 2007-10-26 09:23 pm (UTC)no subject
Date: 2007-10-27 12:15 am (UTC)