cohama / lexima.vim

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

How to custom cr mapping? #104

Closed glepnir closed 3 years ago

glepnir commented 3 years ago

I found when i load lexima. It always redefine my cr map. this is my cr map work with completion-nvim. How can i bind cr work with completion-nvim and lexima.vim new line rules?

imap <expr> <cr>  pumvisible() ? complete_info()["selected"] != "-1" ?
                 \ "\<Plug>(completion_confirm_completion)"  : "\<c-e>\<CR>" :  "\<CR>"
cohama commented 3 years ago

Try to use lexima#expand('<CR>', 'i') instead of "\<CR>".

imap <expr> <cr>  pumvisible() ? complete_info()["selected"] != "-1" ?
                 \ "\<Plug>(completion_confirm_completion)"  : "\<c-e>" . lexima#expand('<CR>', 'i') :  lexima#expand('<CR>', 'i')
glepnir commented 3 years ago

But when load lexima , it always redefine <CR> map ...

cohama commented 3 years ago

Ok... Please write the following codes in your vimrc

" after plugin settings like Plug "cohama/lexima.vim"

let g:lexima_no_default_rules = 1
call lexima#set_default_rules()  " force load lexima.vim and define mappings

imap <expr> <CR> ....  " override <CR> mapping here
glepnir commented 3 years ago

works fine. Thanks a lot.

Glavnokoman commented 3 years ago

This was really helpful. Thanks! I think it is really worth adding this to the README.

nghialm269 commented 3 years ago

Try to use lexima#expand('<CR>', 'i') instead of "\<CR>".

imap <expr> <cr>  pumvisible() ? complete_info()["selected"] != "-1" ?
                 \ "\<Plug>(completion_confirm_completion)"  : "\<c-e>" . lexima#expand('<CR>', 'i') :  lexima#expand('<CR>', 'i')

After trying this, completion-nvim works, but new line rule no longer works for me.

Edit: Work file now after changing lexima#expand('<CR>', 'i') to lexima#expand('<LT>CR>', 'i')

sieuwerts commented 2 years ago

For future reference if anyone stumbles upon my (related) issue in the future (lua):

When using lexima together with nvim-cmp and pressing <cr> while the pum menu was open, it would not give me a new line. This solved that issue (change the <C-e><cr> mapping to what suits you):

use "cohama/lexima.vim"
...
vim.g["lexima_no_default_rules"] = 1
vim.fn["lexima#set_default_rules"]()
...
function _G.new_line_lexima()
  return vim.fn.pumvisible() == 1 and vim.api.nvim_replace_termcodes("<C-e><cr>", true, true, true) or vim.fn["lexima#expand"]("<cr>", "i")
end
...
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.new_line_lexima()", {expr = true, noremap = true})