Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Vi substitution question?



	 I just had a windows guy muck up a perl file and now each line ends with the dre
	aded "^M".
	 
	 My problem is I try to run :1,$s/^M//g but it doesn't seem to see the ^M's, is t
	here a key combo I should be using besides the carrot on top of my 6 key to put i
	n that "^" ?

Yeah; typing the two chars ^M doesn't  generally  work  (though  I've
seen a version of vi that will do it). The general solution is to use
CTRL-V, which "quotes" the next  char  and  suppresses  its  meaning.
Follow this by typing the CTRL-M char.  What you'll see on the screen
after you hit the CTRL-V is
   :1,$s/^
which is your notice that it expects some funny character next.  Then
after pressing the CTRL-M, you'll see
   :1,$s/^M
and so on.  This should take care of it.

Another example that I use a lot is inserting newlines.  Suppose  you
have a line like
   <dt>foo<dt>bar
and you'd like to put the tags on separate lines.  You can do this by
typing the command:
   :s'<dt>'^M^I&'

The ^M was entered as CTRL-V Return, and the ^I was a Tab.   I  could
have  typed  CTRL-V CTRL-M for the newline, but I knew that my Return
key gave the right value, so I used it instead.

(Now I expect an emacs guru to show an efficient way to do  the  same
thing with emacs.  ;-)

Another significant use for CTRL-V is in entering function keys, most
of  which  start with an ESC char.  You can map a function key to any
arbitrary string of input chars by typing
   :map ^
where the ^ appeared when you  typed  a  CTRL-V,  and  then  press  a
function key.  For F5 on this Sun keyboard, what appears next is:
   :map [15~
which  tells me that F5 sends an ESC plus [15~, and I can then type a
space and the definition that I want.  For a silly example:
   :map [15~ :wq

That final ^M was entered as CTRL-V followed by Return. This makes F5
generate  the  :wq command, including the final Return.  Actually, of
course, you probably want to put this command (minus the :) into your
.exrc  file,  so  the definitions will be loaded when vi starts.  For
some reason, it's hard to learn how to  define  functions  keys  from
most vi documentation.


-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org