Loading ...
Sorry, an error occurred while loading the content.

Re: Insert stdout of shell command on current line

Expand Messages
  • Tim Chase
    ... It s uncommon enough (especially the minus the leading # bit) that it s certainly not built-in. However, it s easy enough to map. I d personally use
    Message 1 of 3 , Jun 1, 2010
    • 0 Attachment
      On 06/01/2010 06:55 AM, Andre Majorel wrote:
      > Execute the current line (minus the leading "#") as a shell
      > command and insert its output at +1, keeping the current line in
      > place.
      >
      > Yp:.!sed 's/^\#//' | sh
      >
      > Is there a simpler way to do that ? Like a built-in command ?

      It's uncommon enough (especially the "minus the leading #" bit)
      that it's certainly not built-in. However, it's easy enough to
      map. I'd personally use ":t." instead of "Yp" just so I don't
      tromp the contents of my scratch-register. I'd also just use vim
      to strip the "#". You could try

      :nnoremap <f4> :t.<bar>s/^#//e<bar>.! sh<cr>

      which should have the same behavior. I might also tweak the
      regexp to

      s/^\s*#\+//e

      just to catch a few odd edge cases that occur to me.

      -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
    • Shawn H Corey
      ... Yes, they re called filters, see `:help filter` Place the cursor on the line and type: Ypx!!sh^M -- Just my 0.00000002 million dollars worth, Shawn
      Message 2 of 3 , Jun 1, 2010
      • 0 Attachment
        On 10-06-01 07:55 AM, Andre Majorel wrote:
        > Execute the current line (minus the leading "#") as a shell
        > command and insert its output at +1, keeping the current line in
        > place.
        >
        > Yp:.!sed 's/^\#//' | sh
        >
        > Is there a simpler way to do that ? Like a built-in command ?
        >

        Yes, they're called filters, see `:help filter`

        Place the cursor on the line and type:

        Ypx!!sh^M


        --
        Just my 0.00000002 million dollars worth,
        Shawn

        Programming is as much about organization and communication
        as it is about coding.

        The secret to great software: Fail early & often.

        Eliminate software piracy: use only FLOSS.

        --
        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
      Your message has been successfully submitted and would be delivered to recipients shortly.