oblitum
oblitum

Reputation: 12016

Is it possible to use <C-R>= with a VIM command?

I have the following:

map  <F6> :SCCompile<cr>
map! <F6> <c-r>=SingleCompile#Compile()<cr>

I'd like to use :SCCompile in the second mapping too, is that possible?

Currently I have another command which I really don't want to wrap in a function call. I use <c-r>= in insert mode because it doesn't create undo points and it aways works good except for this limitation.

I've tried execute but it's not working.

Upvotes: 0

Views: 299

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172768

You can built on my answer from your recent similar question. It's exactly the same issue: Like :call, a custom Vim command doesn't return anything, but <C-R> requires an expression that returns something:

function! SingleCompileWrapper()
    SCCompile
    return ''
endfunction

map! <F6> <C-R>=SingleCompileWrapper()<CR>

Upvotes: 0

xaizek
xaizek

Reputation: 5262

You can do something like this:

map  <F6> :SCCompile<cr>
map! <F6> <c-r>=feedkeys("<c-o>:SCCompile\<lt>cr>")?'':''<cr>

The command isn't the simplest:

  • here we ask Vim to execute some keys after leaving <c-r>=
  • use <lt> to allow expanding of <cr> in command-line mode instead of in <c-r>=
  • use ?: operator to ignore value returned by feedkeys() function

See :help feedkeys().

Upvotes: 1

Related Questions