Quantcast
Channel: How to execute selected lines in bash and print the output in the next line? - Vi and Vim Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Ralf for How to execute selected lines in bash and print the output in the next line?

$
0
0

I would propose the following:

nnoremap _X  :put =system(getline('.'))<cr>vnoremap _X  :<C-U>'>put =system(join(getline('''<','''>'),\"\n\").\"\n\")<cr>

The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")), executes it (system(...)) and puts the returned result below the current line.

The visual mode mapping works similar, but

  • `getline('''<', '''>') fetches the list of selected lines
  • join(..., "\n")."\n" joins the list into one string
  • finally put puts the result below the last selected line, due to the leading `'>'

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>