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