f



[vim] execute a command from a line of text in a buffer

Hi everyone,

Sometimes in the :help files there are nice examples of code to execute, either
for mappings or other stuff. I'd like to be able to have a mapping set in order
to do that from the confort of my current buffer, without the need to type the
command manually.

Any idea on that?

Al

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
0
al
12/1/2016 11:30:18 PM
comp.editors 4871 articles. 0 followers. Post Follow

5 Replies
201 Views

Similar Articles

[PageSpeed] 30

alb wrote:

> Sometimes in the :help files there are nice examples of code to
> execute, either for mappings or other stuff. I'd like to be able to
> have a mapping set in order to do that from the confort of my current
> buffer, without the need to type the command manually.
>
> Any idea on that?

POSIX standard vi has the "@" command to execute a named buffer, so
this should work to yank the current line into buffer x and then
execute it:

    ^"xy$@x

I don't use vim, but this works for me in nvi and Solaris vi.

If the command makes changes to the current line, you'll probably want
to do the yank (^"xy$), then move to a different line to operate on, and
then type @x.

-- 
Geoff Clare <netnews@gclare.org.uk>
0
Geoff
12/2/2016 1:32:08 PM
In comp.editors, alb <al.basili@gmail.com> wrote:
> Sometimes in the :help files there are nice examples of code to execute, either
> for mappings or other stuff. I'd like to be able to have a mapping set in order
> to do that from the confort of my current buffer, without the need to type the
> command manually.

My most used macro is for just that sort of thing.

    " yank current line into buffer y and execute;
    " mnemonic * is executable in ls -F output
    map * "yyy@y

I like it so much, I sometimes embed comments in files with often used
commands. Like sort the rest of the file (fold case, unique out dupes):

: +,$ ! sort -fu

(With a space, sh style shells ignore that line; the ":" is the no-op
command; but note that no-op is not the same as a comment: > still
works, etc.)

Elijah
------
has a four line core .exrc he can type from memory on new systems
0
Eli
12/2/2016 11:30:36 PM
Eli the Bearded <*@eli.users.panix.com> wrote:
> In comp.editors, alb <al.basili@gmail.com> wrote:
>> Sometimes in the :help files there are nice examples of code to execute, either
>> for mappings or other stuff. I'd like to be able to have a mapping set in order
>> to do that from the confort of my current buffer, without the need to type the
>> command manually.
>
> My most used macro is for just that sort of thing.
>
>     " yank current line into buffer y and execute;
>     " mnemonic * is executable in ls -F output
>     map * "yyy@y
>
> I like it so much, I sometimes embed comments in files with often used
> commands. Like sort the rest of the file (fold case, unique out dupes):
>
>: +,$ ! sort -fu
>
> (With a space, sh style shells ignore that line; the ":" is the no-op
> command; but note that no-op is not the same as a comment: > still
> works, etc.)
>
> Elijah
> ------
> has a four line core .exrc he can type from memory on new systems

I wrote my own editor about the same time Joy wrote vim, and I have
been tweaking it ever since. I added the execute a line of text
to my editor over 10 years ago. I too find it useful, so much
so that if the cursor is positioned on a line of text, hitting
CR executes the line.

I bring this up because I have added an additional feature: I
can construct up to 10 commands from the line of text. The
default is simply to execute the line. But I can parse the
line into fields and extract some parts from one or more
fields to construct the line to execute.

I will go into more detail if there is any interest expressed
in this post.
0
root
12/3/2016 7:20:42 PM
In article <o1v5ua$91m$1@news.albasani.net>, root  <NoEMail@home.org> wrote:
....
>I wrote my own editor about the same time Joy wrote vim, ...

Don't you mean Moolenaar?

-- 
"Women should not be enlightened or educated in any way. They should be
segregated because they are the cause of unholy erections in holy men.

    -- Saint Augustine (354-430) --
0
gazelle
12/3/2016 8:04:21 PM
Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <o1v5ua$91m$1@news.albasani.net>, root  <NoEMail@home.org> wrote:
> ...
>>I wrote my own editor about the same time Joy wrote vim, ...
>
> Don't you mean Moolenaar?
>

I'm sorry, I meant Joy wrote vi.
0
root
12/3/2016 11:12:26 PM
Reply: