Monday, March 7, 2011

Re: How does one mix ex commands and normal commands such as ma (to set a mark) in a script?

On 8/03/11 4:21 PM, Rostyslaw Lewyckyj wrote:
> I'd like to write me a script which for example does the following:
> - set a mark at the current line ma
> - find a line with a pattern x /^$/
> - set a mark there mb
> - find a line with pattern y /^From - /
> - set a mark there mc
> - write the lines a-b to file1 :'a,'b w file1
> - write the lines b-c to file2 :'b,'c w file2
> ------------------------------------------------------------------------
> or:
> - find a line with pattern x /?x?x?x/
> - ma
> - find a line with pattern y /?y?y?y/
> - mb
> - move all lines with pattern z in a-b to 'a-1
> ----------------------------------------------------------------------
> Also note that I need to be able to handle errors.
> i.e. failed finds etc.

Use the :normal ex-command.

Mind you, there are ex commands for most of what you want, too, e.g.
:mark, :global, :move, so you may not need :normal much.

You can handle errors using :try and friends.

You may also need to specify ranges for your ex commands appropriately.
:help :range

Note that /pattern/ can be used as a range with an empty ex command to
go to a line containing a pattern too, i.e.
:/whatever/

Hope this helps,

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: