How to effectively cancel autocomplete in vim

Now I play with autocomplete in vim, and I decided to use supertab to handle my terminations. Although it works very smoothly and (I think) exactly as it was designed, I would like to know how to change something.

Firstly, I am running 7.3.429 on Ubuntu 12.04LTS with

set completeopt=menuone,preview,longest 

so i have bash -type autocompletion with supertab and the default value is complete.

Suppose my file has the following:

 aaabbbcccddd aaabbccddeef aaabbcddeeff 

If I type aa and press Tab , then vim realized that aaabb is the longest common string among the matches, so it inserts aaabb and displays a menu containing three parameters. If I really need one of these options, then all is well. But maybe I really wanted aaaaazzzzz , but I didn’t understand that I hadn’t dialed it yet.

Is there a good way to say vim: "Oh, sorry, I was not going to write in the end! Please pretend that I did not."

Currently, the following options are obvious to me:

  • Hit Tab or Shift + Tab enough time to get back to my original one. But if there are many similar words, especially to different lengths, it is annoying.
  • Hit backspace as many times as you like, or another naive delete. But this, of course, extra keystrokes.
  • Press Esc + u to cancel, but it cancels my entire word (or more if I type quickly). This is completely unacceptable. And then I need to enter insert mode again and repeat. Gross
  • Press Ctrl + u to cancel without leaving paste mode. But it also tends to remove too much.
  • Press Ctrl + W to delete the last word. As long as I get this without leaving insert mode, I still have to retype. This is the best I've found so far.

If I did not have longest enabled, then I could use Ctrl + E , which leaves the menu without inserting anything. But since it is longer, it stops autocomplete, but leaves the longest overall match.

Of course, there must be a better way to do this.

+6
source share
2 answers

There are 2 own ways to do this in vim. If you correctly know that the item is not in the completion menu, you can use <cy> . <cy> accepts the current match, which if you didn’t move, although any completion will only return the text you inserted. (Second method) However, if you went through the completion menu, you can move until you return to the source text.

However, I think it’s not too difficult just to accept the longest match and edit the word. You can also use <cg>u to break the cancellation block by processing it in your <tab> map. Although this can break the story more than you want.

+2
source

It is difficult, but I had the same problem and something was implemented. The downside is that I had to overload any (built-in and customizable) completion trigger to first call a user-defined function that sets the sign to the beginning of the completion. Then I display <Esc> in insert mode (with a popup menu visible) to remove the text to this label.

 function! s:SetUndo() call setpos("'\"", getpos('.')) return '' endfunction inoremap <expr> <SID>(CompleteStart) <SID>SetUndo() function! s:UndoLongest() " After a completion, the line must be the same and the column must be " larger than before. if line("'\"") == line('.') && col("'\"") < col('.') return "\<C-\>\<Co>dg`\"" endif endif return '' endfunction imap <expr> <Esc> pumvisible() ? <SID>UndoLongest() : '<Esc>' inoremap <script> <Cx><Cn> <SID>(CompleteStart)<Cx><Cn> inoremap <script> <Cx><Cp> <SID>(CompleteStart)<Cx><Cp> ... 
+2
source

Source: https://habr.com/ru/post/950786/


All Articles