Deler
Deler

Reputation: 51

vsvim call to function not supported

I wrote a function in my vimrc file:

function! InsertDebugBlock()
    call append(line('.'), [", "])
    call setline(line('.') + 1, '#if DEBUG')
    call setline(line('.') + 2, '#endif')
    normal j
    startinsert
endfunction

however, when I called it via vsvim in visual studio, it said:

call to function InsertDebugBlock not supported

call to function InsertDebugBlock not supported

but it works well with gvim

it works well with gvim

here are some configurations in vsvim

some configurations in vsvim

it says my vimrc file is "C:\Users\Deler\vimfiles\_vimrc", and that's what it is.

I can't find the problem. My vsvim version is 2.8.0.0, visual studio 2019

Upvotes: 0

Views: 148

Answers (1)

romainl
romainl

Reputation: 196516

VsVim is not Vim so there is no reason whatsoever to expect anything from Vim to work in VsVim and vice-versa.

Case in point: here is the very limited subset of features supported by VsVim and here is the (very reasonable) rationale for not supporting vimscript.

Preliminary conclusion: VsVim doesn't support vimscript so there is no way to make your snippet work.

Now… as-is, your function can't do what you claim it to do in Vim anyway. It actually produces this when called with the cursor on foo:

foo
|#if DEBUG    # cursor before #if
#endif

Besides, using setline() the way you do anywhere else than the end of the buffer will inevitably result in loss of data:

# before
foo
bar
baz
quux

# after
foo
#if DEBUG    # oops! where is bar?
#endif
baz
quux

Not good.

Here is a simpler implementation that is guaranteed to work in Vim and, judging by the linked resources, is very likely to also work in VsVim:

nnoremap <key> o#ifdef DEBUG<CR>#endif<Esc>O

Use whatever <key> you want.

Upvotes: 1

Related Questions