Passing current line number to shell command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing current line number to shell command

Honggyu Kim
Hi all,

I would like to ask a question regarding getting the current line number.
I can get it as follows:

  :echo line(',')

It works fine but my question is in command execution with '!' in the front.

  :!echo line('.')

But "line" is not interpreted before going to shell and makes an error.

Can anyone give me some guide how I can pass the current line number to shell?

Thanks,
Honggyu

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

Frank Shute
On 19 March 2017 at 10:51, Honggyu Kim <[hidden email]> wrote:

>
> Hi all,
>
> I would like to ask a question regarding getting the current line number.
> I can get it as follows:
>
>   :echo line(',')
>
> It works fine but my question is in command execution with '!' in the front.
>
>   :!echo line('.')
>
> But "line" is not interpreted before going to shell and makes an error.

That's because as soon as you do ":!echo" your shell's builtin "echo"
will be invoked rather
than vim's echo and your shell's echo hasn't got any idea what kind of
an argument: "line('.')"
is and freaks out.

>
> Can anyone give me some guide how I can pass the current line number to shell?
>
> Thanks,
> Honggyu

Honggyu, my guess is that you are probably trying to do something that
you probably shouldn't
be trying to do and maybe advised to have a rethink.

IIRC, in vim there is:

:h 10_commandments

From the top of my head, one of them being:

"Thou shalt not pass an internal vim variable to your shell. It's
considerably worse than incest
or folk dancing."

HTH.


Regards,

--

Frank

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

Frank Shute
Crikey. The formatting on Google Groups is making my eyes bleed.

Anybody got any idea of how to integrate vim with gmail other than
cutting and pasting?

I'm using Firefox(esr) on FreeBSD and have "It's all text" add-on
installed but can't find any info on how to configure it.

TIA.


Regards,


On 19 March 2017 at 16:31, Frank Shute <[hidden email]> wrote:

> On 19 March 2017 at 10:51, Honggyu Kim <[hidden email]> wrote:
>>
>> Hi all,
>>
>> I would like to ask a question regarding getting the current line number.
>> I can get it as follows:
>>
>>   :echo line(',')
>>
>> It works fine but my question is in command execution with '!' in the front.
>>
>>   :!echo line('.')
>>
>> But "line" is not interpreted before going to shell and makes an error.
>
> That's because as soon as you do ":!echo" your shell's builtin "echo"
> will be invoked rather
> than vim's echo and your shell's echo hasn't got any idea what kind of
> an argument: "line('.')"
> is and freaks out.
>
>>
>> Can anyone give me some guide how I can pass the current line number to shell?
>>
>> Thanks,
>> Honggyu
>
> Honggyu, my guess is that you are probably trying to do something that
> you probably shouldn't
> be trying to do and maybe advised to have a rethink.
>
> IIRC, in vim there is:
>
> :h 10_commandments
>
> From the top of my head, one of them being:
>
> "Thou shalt not pass an internal vim variable to your shell. It's
> considerably worse than incest
> or folk dancing."
>
> HTH.
>
>
> Regards,
>
> --
>
> Frank



--

Frank

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

h_east
In reply to this post by Honggyu Kim
Hi Honggyu,

2017-3-19(Sun) 20:16:57 UTC+9 Honggyu Kim:

> Hi all,
>
> I would like to ask a question regarding getting the current line number.
> I can get it as follows:
>
>   :echo line(',')
>
> It works fine but my question is in command execution with '!' in the front.
>
>   :!echo line('.')
>
> But "line" is not interpreted before going to shell and makes an error.
>
> Can anyone give me some guide how I can pass the current line number to shell?
There is a way to pass it via environment variables.
See document.
:help :let-$


Sample:

:let $xxx=line('.')
:echo $xxx
12
:!echo $xxx
12

Press ENTER or type command to continue

--
Best regards,
Hirohito Higashi (a.k.a. h_east)

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

arocker

>> Can anyone give me some guide how I can pass the current line number to
>> shell?

Depending on what you want to do, and why, you might be better off passing
the file through sed or awk. Could you explain your ultimate purpose?

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

Charles E Campbell Jr
In reply to this post by Honggyu Kim
Honggyu Kim wrote:

> Hi all,
>
> I would like to ask a question regarding getting the current line number.
> I can get it as follows:
>
>    :echo line(',')
>
> It works fine but my question is in command execution with '!' in the front.
>
>    :!echo line('.')
>
> But "line" is not interpreted before going to shell and makes an error.
>
> Can anyone give me some guide how I can pass the current line number to shell?
>
Hello:

Try :exe "!echo ".line('.')

Regards,
Chip Campbell

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

Tim Chase
In reply to this post by Honggyu Kim
On 2017-03-19 03:51, Honggyu Kim wrote:

> I would like to ask a question regarding getting the current line
> number. I can get it as follows:
>
>   :echo line(',')
>
> It works fine but my question is in command execution with '!' in
> the front.
>
>   :!echo line('.')
>
> But "line" is not interpreted before going to shell and makes an
> error.
>
> Can anyone give me some guide how I can pass the current line
> number to shell?

You can either pass it as an environment variable as h_east suggests,
or you can hard code it into the command you're running via a vim
"exec" command:

  :exec '!echo '.line('.')

Depending on your use case (and how much you need to reuse it) in
your command, one might be easier than the other.

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Passing current line number to shell command

Honggyu Kim
In reply to this post by Honggyu Kim
I appreciate all your help. I was just trying to automatically set a breakpoint at the current line in the source code, then run cgdb to hit the current line.

  map <F6> :exe "!cgdb a.out -ex='b %:p:'" .line('.') " -ex='r'"<Cr>

I've just made the above mapping and found it useful now.
Thank you very much for all your help!

Regards,
Honggyu

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.