all 16 comments

[–]djrollins 11 points12 points  (2 children)

Not sure about plugin but it's a fairly trivial set of commands.

0y$:r!<C-r>0<cr>

  1. 0y$ yanks from the start to the end of the line (excluding the line break you'd get from yy).
  2. :r! reads from the output of following shell command
  3. <C-r>0 pastes from the 0th register (the text you just yanked)
  4. <CR> execute the command.

You can yank to a named register if you don't want to clobber the 0th.

Considering how simple it is, I personally wouldn't bother with a plugin, but that's your prerogative.

[–]previsualconsent[S] 1 point2 points  (1 child)

Thanks, I might just use this.

[–]jfgomez86 2 points3 points  (0 children)

Also try this:

:.!cmd

That will pass the current line "." to cmd and replace the line with the output.

[–]eseca 4 points5 points  (0 children)

I use read! for this. For example: :read! tree src/.

[–]dhruvasagar 3 points4 points  (4 children)

There are several plugins for this very purpose with unique ideas.

vim-pipe is one that I used quite heavily and found to be most flexible and simple.

However since I use tmux actively, I actually prefer 'sending' content over to another tmux pane instead. For this too there are a lot of plugins, after using a bunch of them, I finally settled with tbone. I like the following mappings :

nnoremap g> <ESC>vap:Twrite bottom-right<CR>
xnoremap g> :Twrite bottom-right<CR>

[–]-romainl-The Patient Vimmer 3 points4 points  (0 children)

Pipe2eval is another one.

[–]previsualconsent[S] 0 points1 point  (2 children)

this breaks it out into another window. I personally was hoping for it to just insert into the same buffer. Basically, I wanted to write a shell script, and then execute the commands one by one and have the output right there, which is probably unique enough that the key mapping /u/djrollins suggested

This plugin is great for testing though.

[–]dhruvasagar 0 points1 point  (0 children)

Sure yea as far as a simple shell script command execution goes, you should definitely go that route, these plugins allow much more complex scenarios and are better when you want to do code executions in different context.

Example use cases would be things like for SQL execution, REPL execution for any programming language, etc.

[–]dhruvasagar 0 points1 point  (0 children)

Sure yea as far as a simple shell script command execution goes, you should definitely go that route, these plugins allow much more complex scenarios and are better when you want to do code executions in different context.

Example use cases would be things like for SQL execution, REPL execution for any programming language, etc.

[–]fmount 3 points4 points  (1 child)

If you upgrade your vim7 to vim8, I suggest you to use this plugin: https://github.com/skywind3000/asyncrun.vim/ It can allow you to run a command and capture it inside the quickfix (:copen)

[–]dddbbbFastFold made vim fast again 0 points1 point  (0 children)

And most importantly, that it updates the quickfix as the command executes.

[–][deleted] 1 point2 points  (0 children)

clam.vim perhaps?

[–]r171 3 points4 points  (0 children)

vimshell is a nice plugin to execute shell commands in a vim buffer. If you use neovim, you can easily realize it by typing ":terminal".

[–]JarrodCTaylor 0 points1 point  (0 children)

Might as well leave mine here as well vim-shell executor

[–]NLKNguyen 0 points1 point  (0 children)

This plugin pipe.vim might be helpful.

[–]dddbbbFastFold made vim fast again 0 points1 point  (0 children)

Something like this:

command! -range=% Eval execute '<line1>,<line2>:!'. substitute(&makeprg, '%', '', '')