garbas/vim-snipmate

VISUAL strange behaviour and extra line

0x62ash opened this issue · 4 comments

I have MacVim 8.0.329 (127) on macOS 10.12.3 and vim-snipmates commit 2d70860 (Mon Nov 14 16:13:00 2016 -0500)

First, i want to say that snippet like this (from vim-snippets) doesn't work correctly from the box

snippet if
    if (${1:true}) {
        ${0:${VISUAL}}
    }

Example

1
2
3

Substitues to

if (true) {
    truetrue
    2
    3}true
    2
    3
}

Solution for this is to set parser version via .vimrc:

let g:snipMate = {}
let g:snipMate.snippet_version = 1

But even with this settings you will get one empty extra line:

if (true) {
    1
    2
    3
    
}

Is there any way to exclude this extra line?

ddaza commented

I am seeing the same behavior.
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 18 2017 22:56:36)
Included patches: 1-313, 315-339

Alright for version 0, there are a few problems. One is that in version 0, the correct visual placeholder is {VISUAL}, without the $. The others are a result of limitations of the legacy parser, limitations that I wrote the version 1 parser to get away from. Simply put I'm not going to fix those problems.

With version 1, the extra empty line is a result of using visual line mode instead of just visual mode. When using plain ol' visual mode, there is no extra line. Consider a snippet with text before and after a visual placeholder, such as

snippet foo
    foo $VISUAL bar

I think it's reasonable that someone might want to use visual character mode to keep all three pieces of text on one line sometimes, but other times want to use visual line mode to put a bunch of lines between the "foo" and "bar". For this reason I'm not inclined to change anything at this point. Unless you can persuade me otherwise.

Having said that, I will leave this open in case at some point in the future someone comes up with a reasonable way to specify that some placeholders are to be characterwise and others linewise (or even blockwise).

Thank you for response.

Maybe it's possible to check that if $VISUAL placed at line end then do not put extra new line?

That sounds reasonable to me. Fixed in the above commits. Thanks!