Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:
vim --version.:YcmDebugInfo.:YcmToggleLogs command.install.py (or cmake/make/ninja) including its invocationThank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.
What did you do?
Open a new file, in this case tmp.py. :set tw=5, then in insert mode type asdf a asdf.
What did you expect to happen?
I expected to get a file that looks like this:
a
asdf
What actually happened?
I got a file that looks like this:
a
asasdf
What seems to happen is that when vim wraps a line partway through a word that YCM is trying to complete, I end up with the first few characters of the word duplicated. This only happens if the word is in the autocomplete options, thus typing a asdf alone doesn't trigger it, I have to have asdf somewhere else in the file.
Thanks very much in advance for your help (and for a great plugin)!
See gist. The three log files not included were empty.
I've tested this with a clean vimrc and only pathogen + YouCompleteMe (latest master) in my .vim. (I believe this was introduced somewhere in b358b5ba...31e5fa6d. I realize that's a pretty giant range so if I have time later I'll try a bisect.) It seems to happen for any non-null filetype. The tw=5 is only to simplify the reproduction; it happens with more reasonable text widths too.
Ubuntu 17.04, here's uname -a: Linux diffeomorphism 4.10.0-35-generic #39-Ubuntu SMP Wed Sep 13 07:46:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Thanks for the report. I am not getting exactly the same issue when following your steps using this vimrc:
set nocompatible
set runtimepath+=/path/to/YouCompleteMe
filetype plugin indent on
set textwidth=5
but it's not far off:

If I press <TAB> then I get the same result. Anyway, this should be fixed but I am not sure how.
Probably related to issue https://github.com/Valloric/YouCompleteMe/issues/771.
I've played with this and came to the conclusion that there doesn't need to be a valid candidate to trigger this bug.
@benjaminjkraft You need to update your Vim to at least 8.0.0127.
@micbou , I have exactly the behavior you described in your former message (Tab triggers the mess), but my Vim version is
:version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Oct 12 2018 19:49:42)
It results very annoying to me, since I tend to Tab-complete with considerable frequency.
@Aster89 Sorry, I can't reproduce with Vim 8.1.477.
Just to be sure I'm doing the same thing, I encounter the problem when I run
$ vi -u <(echo -e "set nocompatible\nset runtimepath+=.vim/plugged/YouCompleteMe/\nfiletype plugin indent on\nset textwidth=5") tmp.py
and then hit iasdfSpaceaSpaceasdfTab.
I didn't check this properly. The suggestion is not inserted anymore when Vim automatically wraps the text, which was the issue initially reported by the OP, but the completion menu still appears at the wrong position like in the GIF animation of my comment. Reopening.
So, when vim hardwraps the line and moves the word to the next line, we are keeping the previous start codepoint. What's interesting is that vim doesn't automatically wrap the second asdf until you exit insert mode if you start vim with --noplugins.
PR https://github.com/Valloric/YouCompleteMe/pull/3192 should fix the issue. @Aster89 Could you give it a try?
So, when vim hardwraps the line and moves the word to the next line, we are keeping the previous start codepoint. What's interesting is that vim doesn't automatically wrap the second asdf until you exit insert mode if you start vim with --noplugins.
Strange, I don't experience this.
I'd be glad to check and let you know if it works, but... How can I get your changes from command line?
Go to the YCM folder and run the commands
git fetch origin pull/3192/head:auto-wrap
git checkout auto-wrap
Once you are done, you can go back to the current version of YCM with
git checkout master
It works, as long as the example we've been trying so far is exhaustive.
@micbou , for my own reference and understanding, pull/3192 is the pull request, auto-wrap is the name of the branch you created to work. Where should have I understood that head: was needed and not anything else?
It works, as long as the example we've been trying so far is exhaustive.
You could try the changes for a few days and report back if you encounter any issue.
@micbou , for my own reference and understanding, pull/3192 is the pull request, auto-wrap is the name of the branch you created to work. Where should have I understood that head: was needed and not anything else?
head is actually part of the name of the branch that store the changes of PR #3192: pull/3192/head. When a PR is opened, GitHub creates a hidden branch on the repository named pull/{id}/head where {id} is the PR number. In Git terminology, head refers to the tip of the branch i.e. the latest version so pull/{id}/head can be understood as the latest version of PR #{id}.
Oh, indeed PRs can consist of more commits, right. Ok, I think I got it.
Btw, yes, I'll use it and I won't report as long as I don't encounter issues. (I think I should be notified by e-mail if this is merged in master, right?)
I think I should be notified by e-mail if this is merged in master, right?
Yes, you will be notified if you are watching the repository or if you are subscribed to this issue or the PR.
Most helpful comment
@benjaminjkraft You need to update your Vim to at least 8.0.0127.