cohama / lexima.vim

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

Lexima inserts piece of its own source-code into buffer on <CR> in neovim #67

Open kballenegger opened 7 years ago

kballenegger commented 7 years ago

After setting up Lexima, I've noticed a bizarre bug… when typing <CR> in insert mode, a lexima rule will automatically enter its own source code into the buffer. This happens on any filetypes repeatably.

The code in question is:

pumvisible() ? "\u" : lexima#expand('
', 'i')

I believe the culpable code is this: https://github.com/cohama/lexima.vim/blob/0aa05cbe10d3dc4de239754eb167ca82025415b0/autoload/lexima/insmode.vim#L84-L89

    if has('nvim') && a:rule.char == '<CR>'
      execute printf("inoremap <expr><silent> %s pumvisible() ? \"\\<C-y>\" : lexima#expand(%s, 'i')",
                    \ a:rule.char,
                    \ string(lexima#string#to_mappable(a:rule.char))
                    \ )
    else

My guess is that the rule.char is interpreted as a newline in the command, breaking the command, instead of the characters <CR> indicating the carriage return.

kballenegger commented 7 years ago

Okay… so, after a bit more digging I've narrowed down the cause of the issue to any of 3 custom rules I've added:

call lexima#add_rule({'char': '<', 'input_after': '>'})
call lexima#add_rule({'char': '>', 'at': '\%#>', 'leave': 1})
call lexima#add_rule({'char': '<BS>', 'at': '\<\%#\>', 'delete': 1})

Any of these rules seems to cause this behavior. The rules themselves work at adding the <> pair, but they do cause these issues as a result.

No amount of escaping the < and > characters seems to fix this.

cohama commented 7 years ago

Thanks for reporing but I can not replicate it. Please tell me your neovim version. and minimal nvim/init.vim file.

kballenegger commented 7 years ago

nvim --version

NVIM 0.1.7
Build type: RelWithDebInfo
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim-20170116-138-1h33iaz/neovim-0.1.7/build/config -I/tmp/neovim-20170116-138-1h33iaz/neovim-0.1.7/src -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/usr/include -I/tmp/neovim-20170116-138-1h33iaz/neovim-0.1.7/build/src/nvim/auto -I/tmp/neovim-20170116-138-1h33iaz/neovim-0.1.7/build/include
Compiled by kenneth@kenneth.local

Optional features included (+) or not (-): +acl   +iconv    +jemalloc +tui      
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.1.7/share/nvim"

My .vimrc and entire vim configuration can be seen here: https://github.com/kballenegger/dotfiles

cohama commented 7 years ago

Sorry I could not replicate this issue. I found out you are using many plugins. https://github.com/kballenegger/dotfiles/tree/dotfiles/.vim/bundle One of them might conflicts with lexima. (vim-endwise looks suspicious)