diff options
| author | rebuilt <[email protected]> | 2021-07-27 17:02:20 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-27 11:02:20 -0400 | 
| commit | 2b877ee53e3432736ed2e41a987ab4d05d638876 (patch) | |
| tree | a020e58a1f1365cfe423158e6d3950e15067f407 /lua/core | |
| parent | a82fd81106f8d3266adb162f234b255e7f3b6a23 (diff) | |
Conditionally enable TAB to trigger completion based on filetype. Disable completion for simple text files (#1130)
* disable tab completion for markdown
* md is markdown
* Set local keybindings conditionally based on filetype.  Disable tab complete for text files
* Rename functions and expose excluded filetypes setting for compe
Co-authored-by: abzcoding <[email protected]>
Diffstat (limited to 'lua/core')
| -rw-r--r-- | lua/core/autocmds.lua | 3 | ||||
| -rw-r--r-- | lua/core/compe.lua | 25 | 
2 files changed, 23 insertions, 5 deletions
| diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index d337f71a..9280da9e 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -55,6 +55,9 @@ lvim.autocommands = {      { "FileType", "markdown", "setlocal wrap" },      { "FileType", "markdown", "setlocal spell" },    }, +  _tab_bindings = { +    { "FileType", "*", "lua require'core.compe'.set_tab_keybindings()" }, +  },    _buffer_bindings = {      { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },    }, diff --git a/lua/core/compe.lua b/lua/core/compe.lua index 73e93b05..801e2dd8 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -30,6 +30,8 @@ M.config = function()        emoji = { kind = " ﲃ  (Emoji)", filetypes = { "markdown", "text" } },        -- for emoji press : (idk if that in compe tho)      }, +    -- FileTypes in this list won't trigger auto-complete when TAB is pressed.  Hitting TAB will insert a tab character +    exclude_filetypes = { "md", "markdown", "mdown", "mkd", "mkdn", "mdwn", "text", "txt" },    }  end @@ -81,11 +83,6 @@ M.setup = function()      end    end -  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 }) -    vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true })    -- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true })    vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true }) @@ -93,4 +90,22 @@ M.setup = function()    vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true })  end +local is_excluded = function(file_type) +  for _, type in ipairs(lvim.builtin.compe.exclude_filetypes) do +    if type == file_type then +      return true +    end +  end +  return false +end + +M.set_tab_keybindings = function() +  local file_type = vim.fn.expand "%:e" +  if is_excluded(file_type) == false then +    vim.api.nvim_buf_set_keymap(0, "i", "<Tab>", "v:lua.tab_complete()", { expr = true }) +    vim.api.nvim_buf_set_keymap(0, "s", "<Tab>", "v:lua.tab_complete()", { expr = true }) +    vim.api.nvim_buf_set_keymap(0, "i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) +    vim.api.nvim_buf_set_keymap(0, "s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) +  end +end  return M | 
