From 562ccea4af152220edeb4d297c0d031cdc1141d2 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Sat, 8 Jul 2023 12:05:22 -0700 Subject: [PATCH] Update autocomplete and autocomplete bindings --- README.md | 3 +++ lua/conf/keybinds.lua | 22 +++++++++++++++++++++- lua/conf/ui.lua | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c1adae2..0ffbc49 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,9 @@ To move seamlessly between splits. Autocompletion is provided by [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim). Additionally LSP-based autocompletion is installed. +Automatic popups are disabled. In order to see suggestions begin typing and then hit `` in insert mode. +Once in the popup you can use `` and `` to go up and down the suggestions. + ### Default Leader The default leader is the space key. diff --git a/lua/conf/keybinds.lua b/lua/conf/keybinds.lua index f9552d7..08da7a6 100644 --- a/lua/conf/keybinds.lua +++ b/lua/conf/keybinds.lua @@ -22,6 +22,27 @@ vim.api.nvim_set_keymap('n', 'r', 'lua NumberToggle()', keymap_ -- the next search. vim.api.nvim_set_keymap('n', '', ':noh', keymap_opts) +-- Autocomplete bindings +vim.keymap.set('i', '', function() + if vim.fn.pumvisible() == 1 then return '' end + return '' +end, {expr = true}) + +vim.keymap.set('i', '', function() + if vim.fn.pumvisible() == 1 then return '' end + return '' +end, {expr = true}) + +vim.keymap.set('i', '', function() + if vim.fn.pumvisible() == 1 then + vim.cmd [[ asyncomplete#close_popup() . "\" ]] + else + return '' + end +end, {expr = true}) + +vim.keymap.set('i', '', '(asyncomplete_force_refresh)', keymap_opts) + -- This one maps F5 to delete all trailing whitespace vim.api.nvim_set_keymap( 'n', @@ -29,4 +50,3 @@ vim.api.nvim_set_keymap( [[:let _s=@/:%s/\s\+$//e:let @/=_s:nohl]], keymap_opts) - diff --git a/lua/conf/ui.lua b/lua/conf/ui.lua index de68cb6..6a2ad81 100644 --- a/lua/conf/ui.lua +++ b/lua/conf/ui.lua @@ -8,5 +8,10 @@ vim.opt.termguicolors = true -- Always show hidden files in nerdtree vim.g.NERDTreeShowHidden = 1 +-- Disable auto-popup for autocomplete +-- This prevents autocomplete spamming when +-- you dont want it. +vim.g.asyncomplete_auto_popup = 0 +