Executing commands over a fold

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing commands over a fold

Ven Tadipatri
I'm really excited about the possibility about running a command over
a set of folds. What this would mean is that I could store a command,
then rather than trying to run it 10 times, see that I have a few more
lines to execute, run it again, hoping that I don't go too far,
instead I could fold the lines I want to execute the command over,
then only execute the command over what's folded. In fact I was so
excited, I started to add this to one of the wikia pages on folding.
But then I was slightly disappointed to see that the "command" that
folddoc expected didn't like my escape sequences.
   Could you help me determine what's wrong?
Store the keysequence into a buffer:
qa^i    ^[ (escape key)
Set the mark with ma, and go to the line I want to start the fold.
Make the fold to the mark that I've set
zf'a
Now, the part that doesn't work:
:folddoc <ctrl+r>a

Any help would greatly be appreciated.

Thanks,
Ven

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Benjamin Fritz


On Oct 7, 2:51 pm, Ven Tadipatri <[hidden email]> wrote:

> I'm really excited about the possibility about running a command over
> a set of folds. What this would mean is that I could store a command,
> then rather than trying to run it 10 times, see that I have a few more
> lines to execute, run it again, hoping that I don't go too far,
> instead I could fold the lines I want to execute the command over,
> then only execute the command over what's folded. In fact I was so
> excited, I started to add this to one of the wikia pages on folding.
> But then I was slightly disappointed to see that the "command" that
> folddoc expected didn't like my escape sequences.
>    Could you help me determine what's wrong?
> Store the keysequence into a buffer:
> qa^i    ^[ (escape key)
> Set the mark with ma, and go to the line I want to start the fold.
> Make the fold to the mark that I've set
> zf'a
> Now, the part that doesn't work:
> :folddoc <ctrl+r>a
>
> Any help would greatly be appreciated.
>

You're trying to execute a normal-mode command where an :ex command is
expected. What you are trying to do is:

:folddoc normal! '<C-R>a'

However, may I instead suggest:

1. Visually select the lines you wish to execute the command on (or
use marks as you are doing)
2. :'<,'>normal! '<C-R>a'

Note that if you press : in visual mode, the '<,'> automatically gets
inserted on the line. This means, "do the command :normal! on every
line in the visual selection".

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Nikolay Aleksandrovich Pavlov
Ответ на сообщение «Re: Executing commands over a fold»,
присланное в 18:50:20 08 октября 2010, Пятница.
Отправитель: Ben Fritz:

> You're trying to execute a normal-mode command where an :ex command is
>
> expected. What you are trying to do is:
> :folddoc normal! '<C-R>a'
>
> However, may I instead suggest:
>
> 1. Visually select the lines you wish to execute the command on (or
> use marks as you are doing)
> 2. :'<,'>normal! '<C-R>a'
«normal! '<C-r>a'» is a wrong syntax for expressing
    execute "normal! \<C-r>a"
What you have written is the same as
    execute "normal! '<"."C"."-R>a'"
or ``go to the start of selection ('<) and replace the text to the end-of-line
(C) with «-R>a'»''. Please test your answer before you post it.


Текст сообщения:

> On Oct 7, 2:51 pm, Ven Tadipatri <[hidden email]> wrote:
> > I'm really excited about the possibility about running a command over
> > a set of folds. What this would mean is that I could store a command,
> > then rather than trying to run it 10 times, see that I have a few more
> > lines to execute, run it again, hoping that I don't go too far,
> > instead I could fold the lines I want to execute the command over,
> > then only execute the command over what's folded. In fact I was so
> > excited, I started to add this to one of the wikia pages on folding.
> > But then I was slightly disappointed to see that the "command" that
> > folddoc expected didn't like my escape sequences.
> >    Could you help me determine what's wrong?
> > Store the keysequence into a buffer:
> > qa^i    ^[ (escape key)
> > Set the mark with ma, and go to the line I want to start the fold.
> > Make the fold to the mark that I've set
> > zf'a
> >
> > Now, the part that doesn't work:
> > :folddoc <ctrl+r>a
> >
> > Any help would greatly be appreciated.
>
> You're trying to execute a normal-mode command where an :ex command is
>
> expected. What you are trying to do is:
> :folddoc normal! '<C-R>a'
>
> However, may I instead suggest:
>
> 1. Visually select the lines you wish to execute the command on (or
> use marks as you are doing)
> 2. :'<,'>normal! '<C-R>a'
>
> Note that if you press : in visual mode, the '<,'> automatically gets
> inserted on the line. This means, "do the command :normal! on every
> line in the visual selection".

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Benjamin Fritz


On Oct 8, 10:20 am, ZyX <[hidden email]> wrote:

>
> > You're trying to execute a normal-mode command where an :ex command is
>
> > expected. What you are trying to do is:
> > :folddoc normal! '<C-R>a'
>
> > However, may I instead suggest:
>
> > 1. Visually select the lines you wish to execute the command on (or
> > use marks as you are doing)
> > 2. :'<,'>normal! '<C-R>a'
>
> «normal! '<C-r>a'» is a wrong syntax for expressing
>     execute "normal! \<C-r>a"
> What you have written is the same as
>     execute "normal! '<"."C"."-R>a'"
> or ``go to the start of selection ('<) and replace the text to the end-of-line
> (C) with «-R>a'»''. Please test your answer before you post it.
>

I am aware of that. I was not suggesting pressing 5 keystrokes to get
<C-R>, I was suggesting physically typing CTRL+R. I interpreted this
to be what the OP was doing.

I understood the attempted solution to be:

:folddoc (insert contents of 'a' register)

I was suggesting this instead:

:foddoc normal! '(insert contents of "a" register)'

I am sorry for the confusion.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Benjamin Fritz
In reply to this post by Benjamin Fritz


On Oct 8, 9:50 am, Ben Fritz <[hidden email]> wrote:

> > Store the keysequence into a buffer:
> > qa^i    ^[ (escape key)
> > Set the mark with ma, and go to the line I want to start the fold.
> > Make the fold to the mark that I've set
> > zf'a
> > Now, the part that doesn't work:
> > :folddoc<ctrl+r>a
>
> > Any help would greatly be appreciated.
>
> You're trying to execute a normal-mode command where an :ex command is
> expected. What you are trying to do is:
>
> :folddocnormal! '<C-R>a'
>

(where <C-R> means "type CTRL and R keys together")

> However, may I instead suggest:
>
> 1. Visually select the lines you wish to execute the command on (or
> use marks as you are doing)
> 2. :'<,'>normal! '<C-R>a'
>

(again, where <C-R> means "type CTRL and R keys together", and I do
have a typo, you should omit the quotes around the whole ending)

> Note that if you press : in visual mode, the '<,'> automatically gets
> inserted on the line. This means, "do the command :normal! on every
> line in the visual selection".

Actually, it occurred to me, the BEST way is probably to dispense with
the <C-R> altogether:

:'<,'>normal! @a

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Ven Tadipatri
On Mon, Oct 11, 2010 at 9:33 PM, Ben Fritz <[hidden email]> wrote:

>
>
> On Oct 8, 9:50 am, Ben Fritz <[hidden email]> wrote:
>> > Store the keysequence into a buffer:
>> > qa^i    ^[ (escape key)
>> > Set the mark with ma, and go to the line I want to start the fold.
>> > Make the fold to the mark that I've set
>> > zf'a
>> > Now, the part that doesn't work:
>> > :folddoc<ctrl+r>a
>> You're trying to execute a normal-mode command where an :ex command is
>> expected. What you are trying to do is:
>>
>> :folddocnormal! '<C-R>a'
>>

I tried this, and it says "mark unknown".  I'm assuming there's a
space between folddoc and normal?

>
> (where <C-R> means "type CTRL and R keys together")
>
>> However, may I instead suggest:
>>
>> 1. Visually select the lines you wish to execute the command on (or
>> use marks as you are doing)
>> 2. :'<,'>normal! '<C-R>a'
>>

I realize it's possible in visual mode. Perhaps I can try that. What's
neat about folds (assuming I can get folddoc working) is that you can
execute a command in different parts of the file, whereas in visual
mode, it's a continuous selection.

> Actually, it occurred to me, the BEST way is probably to dispense with
> the <C-R> altogether:
>
> :'<,'>normal! @a
>

I tried the folddoc with the @a, and it just wiped out the text in my
fold altogether, replacing it with what i wanted to insert. Here's
what I tried
:folddoc normal! @a

Or perhaps I'm just not understanding the point of folddoc - I thought
you could use it to execute commands in normal mode as well, but maybe
visual mode is intended for that?  The code you showed did work in
visual mode.

Thanks,
Ven

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Executing commands over a fold

Benjamin Fritz


On Oct 12, 10:33 am, Ven Tadipatri <[hidden email]> wrote:
>
> >> :folddocnormal! '<C-R>a'
>
> I tried this, and it says "mark unknown".  I'm assuming there's a
> space between folddoc and normal?
>
>

Sorry, as I mention, there is a typo. Omit the '' characters.
Additionally I meant "type CTRL+R" (two keys) not "type < C - R >" (5
characters).

> >> However, may I instead suggest:
>
> >> 1. Visually select the lines you wish to execute the command on (or
> >> use marks as you are doing)
> >> 2. :'<,'>normal! '<C-R>a'
>
> I realize it's possible in visual mode. Perhaps I can try that. What's
> neat about folds (assuming I can get folddoc working) is that you can
> execute a command in different parts of the file, whereas in visual
> mode, it's a continuous selection.
>

I hadn't thought of that. Sounds like a neat use case. Another trick
to pull out when needed!

> > Actually, it occurred to me, the BEST way is probably to dispense with
> > the <C-R> altogether:
>
> > :'<,'>normal! @a
>
> I tried the folddoc with the @a, and it just wiped out the text in my
> fold altogether, replacing it with what i wanted to insert. Here's
> what I tried
> :folddoc normal! @a
>

That is strange. For me, this does not occur in a simple test.

I tried:
qaI* :folddoclosed normal! @a<CR>

on a buffer with some folded text, and as expected, each line in the
closed folds got "* " inserted.

What is the command you are trying to run? Some commands don't work as
nicely inside folded lines.

> Or perhaps I'm just not understanding the point of folddoc - I thought
> you could use it to execute commands in normal mode as well, but maybe
> visual mode is intended for that?  The code you showed did work in
> visual mode.
>

:folddoclosed is a way to specify which lines to execute an :ex
command on. Only :ex commands will work, but you can run normal-mode
commands with the ":normal" ex command. The '!' at the end of :normal!
is to ignore mapped keys, etc. while running the normal-mode command.
Visual mode also cannot execute normal-mode commands, but you can use
visual-mode to easily specify a range of lines to act on with an :ex
command.

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