Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support selecting the first completion option / Remove 'noselect' from completeopts #3573

Closed

Conversation

rouge8
Copy link

@rouge8 rouge8 commented Feb 3, 2021

This patch removes noselect from the default completeopts. This should no longer be necessary thanks to 25b572b, because the <C-p> added to the map will deselect the first entry.

Combined with something like this in your ~/.vimrc:

function! RemapAleCompletion()
  iunmap <Plug>(ale_show_completion_menu)
  inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
endfunction

augroup remap_ale_completion
  autocmd!
  autocmd VimEnter * call RemapAleCompletion()
augroup END

This can address #3433.

@rouge8 rouge8 changed the title Remove 'noselect' from completeopts Support selecting the first completion option / Remove 'noselect' from completeopts Feb 4, 2021
@MeTheFlea
Copy link

MeTheFlea commented Feb 5, 2021

function! RemapAleCompletion()
  iunmap <Plug>(ale_show_completion_menu)
  inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
endfunction

augroup remap_ale_completion
  autocmd!
  autocmd VimEnter * call RemapAleCompletion()
augroup END

I'm a bit of a vimscript novice but this snippet doesn't seem to work, since <Plug>(ale_show_completion_menu) doesn't seem to be set by the time VimEnter * call RemapAleCompletion() is executed. It seems like <Plug>(ale_show_completion_menu) is only set after the first time ALEComplete is called, and I'm not sure if there's an autocmd moment where I can automatically override it once it gets set. However, calling RemapAleCompletion() manually after doing :ALEComplete once does seem to provide the behaviour I originally wanted in #3433 for the rest of the vim session.

@rouge8
Copy link
Author

rouge8 commented Feb 6, 2021

I'm a bit of a vimscript novice but this snippet doesn't seem to work, since <Plug>(ale_show_completion_menu) doesn't seem to be set by the time VimEnter * call RemapAleCompletion() is executed. It seems like <Plug>(ale_show_completion_menu) is only set after the first time ALEComplete is called, and I'm not sure if there's an autocmd moment where I can automatically override it once it gets set. However, calling RemapAleCompletion() manually after doing :ALEComplete once does seem to provide the behaviour I originally wanted in #3433 for the rest of the vim session.

I think I can reproduce what you're seeing when I don't use let g:ale_completion_enabled = 1. In that case, I believe this PR plus this function fixes #3433:

function! RemapAleCompletion()
  " Load autoload/ale/completion.vim and the <Plug>(ale_show_completion_menu) mapping
  ALEComplete
  " or:
  " call ale#completion#GetCompletions('ale-manual')

  iunmap <Plug>(ale_show_completion_menu)
  inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
endfunction

augroup remap_ale_completion
  autocmd!
  autocmd VimEnter * call RemapAleCompletion()
augroup END

@rouge8 rouge8 force-pushed the completeopt-remove-noselect branch from 49b3f16 to 9fffebf Compare February 6, 2021 00:25
rouge8 added a commit to rouge8/dotfiles that referenced this pull request Feb 6, 2021
Now I can accept the first completion with `<Tab>` or `<Right>` instead
of `<Down><Tab>` or `<Down><Right>`. Requires my patch to ALE:
dense-analysis/ale#3573
Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of this change, we need a separate Plug mapping for manual completion (ale-manual) so we don't send C-p to back out of selecting the first item. This can be done by adding an argument to s:OpenCompletionMenu to change which Plug key it sends. We can't select the first item from automatic completion as it will interrupt typing, but we can when you open the completion menu through a keybind.

@w0rp w0rp self-assigned this Feb 7, 2021
@rouge8
Copy link
Author

rouge8 commented Feb 7, 2021

I think instead of this change, we need a separate Plug mapping for manual completion (ale-manual) so we don't send C-p to back out of selecting the first item. This can be done by adding an argument to s:OpenCompletionMenu to change which Plug key it sends. We can't select the first item from automatic completion as it will interrupt typing, but we can when you open the completion menu through a keybind.

I actually use this with automatic completion. The noinsert ensures it doesn't insert the selected item unless I request it with C-y.

@rouge8 rouge8 requested a review from w0rp February 7, 2021 18:08
This patch removes `noselect` from the default `completeopts`. This
should no longer be necessary thanks to
25b572b, because the `<C-p>` added to
the map will deselect the first entry.

Combined with something like this in your `~/.vimrc`:

```
function! RemapAleCompletion()
  iunmap <Plug>(ale_show_completion_menu)
  inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
endfunction

augroup remap_ale_completion
  autocmd!
  autocmd VimEnter * call RemapAleCompletion()
augroup END
```

This can address dense-analysis#3433.
@rouge8 rouge8 force-pushed the completeopt-remove-noselect branch from 1977215 to 674ff78 Compare March 6, 2021 20:23
@w0rp
Copy link
Member

w0rp commented Jun 19, 2021

I'm gonna replace this with an alternate patch which respects the value of completeopt, so you'll get noselect if you have your options configured that way, otherwise you won't.

@w0rp w0rp closed this Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants