Domanda

I often invoke functions from my menu

Many have double entries:
- one for normal substitution
- one for subsitution with confirmation dialog (gc)

p.e.:

vnoreme 20.900 &Edit.Delete\ All\ but\ 1st\ Doubles\              :<C-U>call <SID>DeleteD("'<,'>","confirm-no")<CR>
vnoreme 20.901 &Edit.Delete\ All\ but\ 1st\ Doubles\ (gc)\        :<C-U>call <SID>DeleteD("'<,'>","confirm-yes")<CR>

Is there no better way then the one I use above to indicate a confirmation dialog? (and to avoid all these double entries)

P.e. when a function invokes an inputdialog box, I would like to have a checkbox added where I can indicate (checking it) to add a dialog confirmation after every substitution, but unfortunately they don't exist and there is no way (as in autohotkey) to create an inputdialog GUI myself.

È stato utile?

Soluzione

Well, you could change your Delete() function to ask you, whether you'd like to have each substitution being confirmed. Something like this:

fu! Delete(range)
let confirm = confirm("confirm each change?", "&yes\n&no", 1)
let cmd=printf("%ss/foobar/foobaz/g%s", a:range, confirm ? 'c' : '')
exe cmd
endfu

(this is just an example, you probably want to change at least the search and replace criteria)

Or, if you are using a simple substitution, learn to use the :ex command :promptrepl, e.g. :promptrepl foobar will open a search/replace dialog where the search field will be set to 'foobar' and you only need to enter the replacement part and hit the buttons you like.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top