Friday, February 18, 2011

Re: How do I click select a command from a list in buffer (a), and execute the chosen command in buffer (b) ?

On 02/17/2011 10:44 PM, Rostyslaw Lewyckyj wrote:
> I have a reasonably extensive repertory of edit commands from
> which, I'd like to pick and chose individual commands and
> execute them against my current buffer. I'd like to open the
> file to be edited in buffer (a), and the repertory of
> commands in buffer (b). And then I'd like to pick commands
> from (b), and execute them on (a).

Depending on how you have the commands defined in buffer (b), if
they're literal (control-characters and all, which can do odd
things when reloading the doc), you can yank the line into a
register and then execute it as a macro. Depending on whether
they're normal-mode or ex/command/search-mode arguments (the
commands for which you'll want to prefix with the appropriate ":"
or "/"), you'll either want to include or exclude the trailing
newline:

0y$
Y

The first one goes to the beginning of the line and yanks to the
end (excluding the <CR>); the second one yanks the entire line
(including the <CR>) and executes it. You can then switch back
to buffer (a) and execute it with

@"

If you have several that you plan to use repeatedly, you can yank
them into various registers:

"aY
<move around in B>
"bY
<move around in B>
"cY

You now have 3 lines yanked into registers "a", "b" and "c" which
you can execute any time you want with

@a
@b
@c

I run out of the ability to remember what I've put in each
register before I run out of the 26 registers :)

If you want to automate this, you can create some mappings like

:nnoremap <f4> 0y$<c-w>p@"
:nnoremap <f5> Y<c-w>p@"
:vnoremap <f4> y<c-w>p@"

which will give you 3 mappings you can use in window "b", one for
normal-mode commands, one for ex/search-mode commands, and one
where you visually select the command you want to run (in case it
happens that you want to execute a command that spans multiple
newlines).

-tim


--
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: