Can you make interactive macros or records in vim?

I would like to define a vim macro that interrupts for user input at a specific time, is this possible?

EDIT: Turns off i (q) entries, not macros

You can use an input command in a record, but this is more of a problem than it costs.

First, I displayed the key input input tab

:map <F2> a<CR>=input('input: ')<CR> 

then I made this entry in the q register

 name: 

and paste it into a new tab

 iname: ^[ 

And after the final exit, I pressed <CV><F2> on the line:

 iname ^[^[OQ 

What I returned back to the q buffer, then I used a macro, allowing me to use the input function. It works, but awful.

+6
source share
3 answers

Yes. See the input({prompt}, [, {text} [, {completion}] ]) function input({prompt}, [, {text} [, {completion}] ]) . There is even inputdialog({prompt} [, {text} [, {cancelreturn}]]) for the popup.

+3
source

If you use the input() inside a matching or macro, the remaining characters are taken as input, you do not want. Vim offers the functions inputsave() and inputrestore() temporarily suspend reading from the stream of display characters.

Based on mogelbrod's answer, this does not work; itest read as input:

 oBEFORE ^R=input('prompt> ')^Mitest 

But it does:

 function! Input() call inputsave() let text = input('prompt> ') call inputrestore() return text endfunction oBEFORE ^R=Input()^Mitest 

Unfortunately, since <CR> accepts an expression, we cannot put commands in a string, but must define a separate input() function.

+2
source

Unfortunately, this is not possible. You can run input() inside the macro, but continuing after that is not possible, since any additional input is written to the input prompt.

Put the string in the named case ( "qY ) and run it ( @q ) to try it.
Note: replace ^R and ^M with Ctrl-V Ctrl-R / M (see :help i_CTRL-V ).

  • oBEFORE ^R=input('prompt> ') - works
  • oBEFORE ^R=input('prompt> ')^Mitest - works, but inserts itest into the prompt
  • oBEFORE ^R=input('prompt> ')<CR>test - does not work
+1
source

Source: https://habr.com/ru/post/920911/


All Articles