with vim, if I use
:r!date
vim insert the date in the next line, similar with
:r!pwd
how I can insert the output command under cursor position and no in a new line ?
|
with vim, if I use
vim insert the date in the next line, similar with
how I can insert the output command under cursor position and no in a new line ? |
|||
|
|
|
With " You may insert the output of a command at the current cursor position when you are in insert mode by pressing ControlR then typing That can be fixed by adding a The ultimate solution is to create some sort of mapping, but that gets even more complex due to how Vim handles what it calls "type ahead"; while you can do something like:
Where the command is "hard wired" in the mapping, you cannot do something like:
Where you try to prompt the user for the command to run, because Vim will just get confused, beep, and enter insert mode. So you have to prompt for the command to run first, store it in a variable, and then insert the processed output. At this point a helper function is probably needed to keep the mapping itself from becoming unmanageably messy, so we end up with something like this:
Note that Incidentally, if you only wanted to insert the date or the current working directory, the initial answer I gave is feasible. Just enter insert mode and type ControlR |
|||
|
|
|
If you want it in the current line you try just, but have in mind the old content of the line will be erased:
If you want the exact cursor position you can:
Long story short: you need to substitute cause you want to get rid of ^@ (null characters) which you can also can replace with .s/\%x00//g. This is a shorter version with less pipes:
And you can also set tags if you want to replace in various points at the same line: Given this Line 1:
Execute:
After Replacement:
Tested on Vim 7.2 |
||||
|
|