1834149 Members
2179 Online
110064 Solutions
New Discussion

Needs vi editor tips

 
+++¦-°
New Member

Needs vi editor tips

Hi,
I'm suffering from vi command.
I know the '.' character redo the previous command in editing mode.
How can I apply this redo command for several lines in one command?
for example, I modify number 3 line and I want apply this from 20 to 50 line.
How can I do this?
Hope to get your help.
8 REPLIES 8
Stefan Farrelly
Honored Contributor

Re: Needs vi editor tips


Goto line 20 by doing :20
Then to repeat your command for the next 30 lines (from 20-50) you can supply a count to . eg. 30.
This should repeat your command for the next 30 lines. Tested it, works fine. you may need to go to line 20 first, do your command for the first line, then do 29.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Rick Garland
Honored Contributor

Re: Needs vi editor tips

Another option;

In the vi command mode, do the following:

:20,50 s/oldpattern/newpattern/

The above is saying on lines 20 - 50, do a substitute command from the oldpattern to the newpattern.

As always, if you are testing some new editor functions, make a backup copy of the file before you do the experiments.
Mike Stroyan
Honored Contributor

Re: Needs vi editor tips

You can use all of the range editing commands that are documented in "man ex". Those are useful for repeating a substitution over a range of lines.
You can also use the :map feature of ex to make a single key map to a long sequence of keys. For example,
:map #1 cwnew^V^[/old^V^M
would make the F1 key change a world to "new", then search for an occurance of "old". The escape and carriage return characters are quoted with a control-V character. You can map normal characters, function keys, or characters typed with control or alt combinations. Almost all of the normal characters are already used by some vi binding.
CHRIS_ANORUO
Honored Contributor

Re: Needs vi editor tips

Setup $HOME/.exrc and include
set nu
set showmode
Log out and login, then try the steps contributed by your peers.
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
RikTytgat
Honored Contributor

Re: Needs vi editor tips

Hi,

The command to redo the last 'ex' command is '&'.

For example, you type
:s/oldpat/newpat/

and want to re-apply the same change to line 20-50, type
:20,50&

This should do the trick.

Bye,
Rik.
Rick Beldin
HPE Pro

Re: Needs vi editor tips

If you really some more powerful editing features, but still like vi, trying getting a copy of vim. Has the ability to learn sequences of commands and then execute them on a keystroke. Available at the porting center.
Necessary questions: Why? What? How? When?
Carlos Fernandez Riera
Honored Contributor

Re: Needs vi editor tips


vi is capable to execute macros too.

See man vi and search for @buffer.
unsupported
CHRIS_ANORUO
Honored Contributor

Re: Needs vi editor tips

Award your points!
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.