hrsh7th / nvim-compe

Auto completion Lua plugin for nvim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tab selection no longer working

joshzcold opened this issue · comments

Checkhealth

Put result of :checkhealth compe.

<Plug>(compe-checkhealth-check)
health#compe#check
========================================================================
## compe:snippet
  - OK: snippet engine detected.

## compe:mapping

Describe the bug

Ive been using functions to tab complete suggestions for a couple weeks now, but just this morning they stopped working.
I have confirm that this works in coc.nvim so I am assuming that my terminal is not the cause

To Reproduce

Steps to reproduce the behavior with the minimal config:

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !isdirectory(s:plug_dir)
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-compe'
call plug#end()
PlugInstall | quit


lua << EOF
    require("compe").setup {
        source = {
            path = true
        }
    }
    -- Utility functions for compe and luasnip 
    local t = function(str)
        return vim.api.nvim_replace_termcodes(str, true, true, true)
    end

    local check_back_space = function()
        local col = vim.fn.col('.') - 1
        return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
    end

    -- vim.g.UltiSnipsExpandTrigger = "<nop>"
    -- Use (s-)tab to:
    --- move to prev/next item in completion menuone
    --- jump to prev/next snippet's placeholder

    _G.tab_complete = function()
      if vim.fn.pumvisible() == 1 then
        return t "<C-n>"
      elseif check_back_space() then
        return t "<Tab>"
      else
        return vim.fn['compe#complete']()
      end
    end
    _G.s_tab_complete = function()
      if vim.fn.pumvisible() == 1 then
        return t "<C-p>"
      else
        -- If <S-Tab> is not working in your terminal, change it to <C-h>
        return t "<S-Tab>"
      end
    end

    -- Map tab to the above tab complete functiones
    vim.api.nvim_set_keymap( "i", "<Tab>", "v:lua.tab_complete()", { expr = true })
    vim.api.nvim_set_keymap( "s", "<Tab>", "v:lua.tab_complete()", { expr = true })
    vim.api.nvim_set_keymap( "i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
    vim.api.nvim_set_keymap( "s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })

    -- Map compe confirm and complete functions
    vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm({ 'keys': '<CR>', 'select': v:true })", { expr = true })
EOF
  1. start typing ~/
  2. try to hit <TAB> to go to the first option

Actual behavior

character is inserted

Expected behavior

go to the first option in plumvisible

Screenshots (optional)

Peek 2021-07-28 08-44

Additional context (optional)

nvim compe version - 73529ce
neovim version - 0.5.0 (i did try nightly with same results)

reverting my config back to what it was when I first transitioned to lua made this start working, so im going to have to pin point what caused it to break.
No idea why the minimal config isn't working however.

the minimal config starts working if I do
source ~/.config/nvim/minimal.vim
after I start vim with
nvim -u ~/.config/nvim/minimal.vim

pretty confused on why that is needed

Either way, considering I was able to get it working by reverting my config im going to close this.

Either way, considering I was able to get it working by reverting my config im going to close this.

I'm also having this problem where tab autocompletion only works when im in the nvim project and after i do :source but it does not work for any other project.

Did you ever find out whats causing this?

Do you use ultisnippets? I think I had to map something from ultisnippets to <nop>

Check out :map before and after the :source I think I remember that giving me the clue.

I'm also having this issue.
<Tab> and <S-Tab> don't move the next/prev option but if I execute the compe config file with :luafile % then it works as expected.
I am using ultisnips but not sure on what could be interfering from there?

do you have this in your config?
vim.g.UltiSnipsExpandTrigger = "<nop>"

@joshzcold Thanks for the reply.
No I do not.
I tried adding it but I get an error saying it's not a valid option.

Oh! I had a typo in the option, yes! that does fix it for me. Thanks @joshzcold 🙏