cohama / lexima.vim

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

How can I add rules for {} and [] #145

Closed ahnafalnafis closed 1 year ago

ahnafalnafis commented 1 year ago

Hi, there! Recently, I've discovered that putting \ (backslash) after { (starting curly brace) is not required in Vim9. Same goes for [ (starting square bracket). So, I decided to add a lexima rule for this. But seems like I'm unable to do that.

Current behaviour:

var blah = {
  \ |
  \ }

Expected behaviour:

var blah = {
  |
}

NOTE: Here, | is meant to be the cursor.

Here's my work:

lexima#add_rule({
  char: '<CR>',
  at: '{%#}',
  input_after: '<CR>',
  filetype: 'vim'
})

But, it turns out that I couldn't make it work. So, I'm seeking for the help from you. Thanks in advance!

4513ECHO commented 1 year ago

From vim help:

When some of rules are conflicted, what rule to be applied is decided as the following priority order.

  1. has "filetype"
  2. has "syntax" (only on Insert mode)
  3. "priority" value is higher
  4. the length of "at" is longer

However, lexima does not have the rule about backslash for vim by default. Please provide your configuration.

ahnafalnafis commented 1 year ago

Not sure what configuration are you talking about. Here's my configuration for lexima.vim

vim9script noclear

# To prevent having conflict with coc.nvim
g:lexima_no_default_rules = true
lexima#set_default_rules()
lexima#insmode#map_hook('before', '<CR>', '')

If you need further details, here's my vimrc. This is all I got for you. https://github.com/ahnafalnafis/dotfiles/blob/master/home/.vim/vimrc

ahnafalnafis commented 1 year ago

Finally, I figured out what was wrong. It was coc#on_enter() which was doing this. Now, I turned it off. Pardon me guys for the mess 😓. Thank you @4513ECHO