cohama / lexima.vim

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

<Esc> doesn't quit immidietly insert mode when b:lexima_disabled = 1 #88

Open doronbehar opened 4 years ago

doronbehar commented 4 years ago

Hey,

I'm really enjoying lexima and I almost never complain. It's also a much better alternative to @tpope's "endwise" which doesn't seem as configurable as this one. However, I'm having a rather annoying small inconvenience with it which I've successfully tracked down to this plugin. I'll explain:

When I first started using Vim, I noticed there is a delay between when I press <Esc> and when I actually see the mode indicator changing at the bottom. Thankfully, many people have encountered this weird default setting and have wrote about this.

Through out the years, after I changed some mappings in my init.vim, Sometimes I suddenly started noticing that my <Esc> doesn't make me leave insert mode immediately as I'm used to yet I could always track this down to clashing mappings I defined by myself e.g:

tnoremap <c-\> <c-\><c-n>
nnoremap <c-\> :SomeCommand

The issue I'm having with lexima, is that with some filetypes, where I let b:lexima_disabled = 1 and only inside these buffers, I experience that annoying lag after pressing <Esc>.

Anyway I was hoping you could help me out figure this out.

cohama commented 4 years ago

Thank you for your feedback. I am sorry I cannot reproduce this problem.

Please tell me some information

doronbehar commented 4 years ago

You are right. Here's some basic information:

NVIM v0.3.7
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: 
Compiled by nixbld

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/nix/store/ir2fjws49ak1v12yh64cjbcifly7lm14-neovim-unwrapped-0.3.7/share/nvim"

Run :checkhealth for more info

Minimal setup I've tested to reproduce the issue:

mkdir -p test-config/nvim/{pack/test/start,ftplugin}
cd test-config
git clone https://github.com/cohama/lexima.vim nvim/pack/test/start/lexima
echo 'let b:lexima_disabled = 1' > nvim/ftplugin/text.vim
env XDG_CONFIG_HOME=$PWD nvim test.txt

Please test this and see I'm right. I think the issue is that I use ftplugin/text.vim and not an autocmd straight in init.vim. Also, in that case, imap <Esc> reports:

i  <Esc><Esc>  * <Esc>

While (I assume you'd expect) in a buffer where b:lexima_disabled is undefined, the result of imap <Esc> is:

i  <Esc>       *@<C-R>=lexima#insmode#escape()<CR><Esc>
i  <Esc><Esc>  * <Esc>

And that esc timeout issue doesn't occur.

I'll add to that, that if I use instead of let b:lexima_disabled = 1 in ftplugin/text.vim the following in init.vim:

autocmd FileType text let b:lexima_disabled = 1

As you propose in the help file, the issue persists.

doronbehar commented 4 years ago

Hey,

While trying to workaround this, I discovered that running iunmap <Esc> in a buffer where b:lexima_disabled is 1 fixes the issue. The following patch fixes this:

diff --git i/plugin/lexima.vim w/plugin/lexima.vim
index f7b377d..4f83d7a 100644
--- i/plugin/lexima.vim
+++ w/plugin/lexima.vim
@@ -20,6 +20,7 @@ endif

 function! s:setup_insmode()
   if get(b:, 'lexima_disabled', 0)
+    silent! iunmap <esc>
     return
   endif

I'd have opened a PR but I have no idea why exactly this is needed and I don't understand the overall design of the whole insert mode autocmds etc.

doronbehar commented 3 years ago

What say you @cohama ?

cohama commented 3 years ago

I'm sorry for slow response. It is caused by your imap <Esc><Esc> <Esc> mapping, not by lexima.vim. Please remove this mapping and try again.

doronbehar commented 3 years ago

@cohama did you manage to reproduce the issue with the steps I gave you in my comment? I updated lexima now, and checked these steps once more and they still prove the issue.