cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
996 stars 46 forks source link

Commenting auto-added } on Escape #36

Open thirtythreeforty opened 8 years ago

thirtythreeforty commented 8 years ago

Hi! Fantastic plugin you've written. Far better, consistency-wise, than delimitMate, at least in my experience.

I've noticed behavior which is almost certainly wrong, but I'm not sure if it's lexima.vim's fault. When I type the following (| is the cursor):

void foo() {|

then it correctly expands to the following:

void foo() {
    |
}

But a common thing for me to do is to type out a bunch of empty functions and just put a comment in them, getting the skeleton ready for actual implementation later. From the above expansion, still in Insert mode, I type:

void foo() {
    // Frobnicate the bar.|
}

When I hit Escape, this happens:

void foo() {
    // Frobnicate the bar.|
    // }

Obviously this is not what I meant to happen; I'd rather the closing brace stay uncommented. Pressing u at this point corrects the issue, for whatever reason:

void foo() {
    // Frobnicate the bar.|
}

This only happens in files where a source code filetype is set (such as c, cpp, or rust). That is, in an empty buffer, the closing brace stays put.

Do you have any idea what could be causing this behavior, and how to make it stop?

cohama commented 8 years ago

Sorry for slow response. It is caused by r flag of formatoption option set by default filetype plugins. As a workaround, remove r flag from formatoption like below

autocmd BufWinEnter c,cpp,rust setlocal formatoption-=r

Ideally, however, lexima should work despite formatoption. I will try to fix this problem but need more time.

thirtythreeforty commented 8 years ago

I see. formatoption=r had been irritating me for some time now (although I didn't know what it was called), so thanks for the workaround suggestion.

beavailable commented 5 months ago

I have the same problem and there is another similar problem which I think may be the same as yours, to reproduce, say if I have (in a shell script):

foo(){
    |
}

Then I continue typing:

foo(){
    if [ 1 = 1| ]
}

After I press escape it becomes:

foo(){
    if [ 1 = 1 ]
    }

I tried to remove r from formatoptions but it didn't work, the problem still exists.