New answers tagged

4

:h :command will put you on the right track. It can be as simple as command! RunMyCommand call RunMyCommand() Or much more complex if you want to support arguments, range...


1

When I need to do that, I do it within the function: I assume that I'm not writing a re-entrant function. I prefer the mapping to be as simple as possible. Also, I use: script local variables (s:) to store global data -- i.e. independently of the current buffer. buffer local variables (b:), or a script local dictionary (s:) indexed by buffer numbers when ...


2

This is what happens: i - enter insert mode a - call func -> var = 1, but you left insert mode! a - executed in normal mode -> append -> you are back in insert mode a - call func -> var = 2, but you left insert mode! a - executed in normal mode -> append -> you are back in insert mode ... You might want to try inoremap a <c-o>:let b:var = Foo(b:var)...


1

To get a single character to use as an "argument" in a mapping, you can use the getchar() function, which waits for one. You should then use nr2char() to convert it to a string. If you want to use the character more than once (as it's your case here), you should store it in a variable. It's easier if you use a function to do so. Then use an <expr> ...


Top 50 recent answers are included