cohama / lexima.vim

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

singe quote lexima user custom rule doesnt override the internal one #117

Closed alexzanderr closed 2 years ago

alexzanderr commented 2 years ago

hey. i tried to play around with the lexima rules.

however, i've managed to edit the double quotes rule like this:

" auto complete for "
call lexima#add_rule({'char': '"', 'at': '\%#', 'input_after': '"'})
" when before word character then insert just one "
call lexima#add_rule({'char': '"', 'at': '\%#\w', 'leave': 1})
" when after word character then insert just one "
call lexima#add_rule({'char': '"', 'at': '\w\%#', 'leave': 1})
" when after a word and before " jump over
call lexima#add_rule({'char': '"', 'at': '\w\%#"', 'input': '<Right>'})
" when in the middle of "|" then delete both
call lexima#add_rule({'char': '<BS>', 'at': '"\%#"', 'input': "<Right><BS><BS>"})
" when backspacing empty "", delete both
call lexima#add_rule({'char': '<BS>', 'at': '""\%#', 'input': "<BS><BS>"})

these work like a charm. im very proud of them

but when im trying to edit single quotes like this:

" auto compelete for '
call lexima#add_rule({"char": "'", "input_after": "'"})
" when before word character then insert just one '
call lexima#add_rule({"char": "'", "at": "\%#\w", "input": "<BS>"})
" when after word character then insert just one '
call lexima#add_rule({"char": "'", "at": "\w\%#", "leave": 1})

it doesnt work.

INFO normally, the dict for custom rule has keys between single quotes, but when editing custom rules for single quotes you cant use single quotes for strings, thats why i used double quotes. maybe that is the problem.

im not an experienced vim user, but i ussed single quotes and double quotes as strings im vimrcs and i assume there is no difference. but here it doesnt work.

any ideas? thanks.

alexzanderr commented 2 years ago

yea. i've tested out. it doesnt work with double quotes.

here is the solution that fixed the problem:

call lexima#add_rule({'char': '''', 'at': '\%#', 'input_after': ''''})
call lexima#add_rule({'char': '''', 'at': '\%#\w', 'leave': 1})
call lexima#add_rule({'char': '''', 'at': '\w\%#', 'leave': 1})
call lexima#add_rule({'char': '<BS>', 'at': '''\%#''', 'input': "<Right><BS><BS>"}) " keyboard presses must be between double quotes
call lexima#add_rule({'char': '<BS>', 'at': '''''\%#', 'input': "<BS><BS>"}) " keyboard presses must be between double quotes

between single quotes the single quotes but be represented with '', then to integrate it would look like '''' (4 single quotes)