-
Notifications
You must be signed in to change notification settings - Fork 397
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
Question: Completion in nvim's terminal window #1219
Comments
I know it is useful. |
Thanks for the quick response. What exactly is not supported? Is it popup menu's in the terminal buffer? Or what else is missing? |
well, I had to implement the feature in pum.vim. |
The popup menu can be displayed in terminal mode. |
I'm not an expert in automating (n)vim and at the same time I can command
when I'm in the terminal to enter insert mode and command |
I will test it later... |
I have tested it and I found the critical problem. In terminal mode, it does not have |
I have created the PR for it. |
@Shougo For zsh, I'm not sure if this can be done with zle + $NVIM(unix socket) + user autocmd |
Well, it may be work. But this is just hack. I don't want to hack it. |
Yes, it would be best if it could be implemented in neovim, it looks like you are familiar with both neovim and nvim-cmp projects, I am a newbie, mind sharing how you read open source projects quickly? |
Hm... It is hard problem. |
Excellent! |
The patch is already merged! |
Great, so I just installed the latest nightly build for nvim. How can I get nvim-cmp to trigger and show any snippets? Thank you very much @Shougo |
I don't think nvim-cmp supports it yet, so you should manually add the trigger event TextChangedT to trigger the completion of nvim-cmp, #519 (comment) |
You may also need to install a source, such as zsh: |
Yes. It needs |
Hi! I tried it out and could not get a snippet popup to appear in the terminal. So when I configure What I tried: I added the zsh source and I also put the snippet from #519 (comment) into my init.vim. At the start of the lua function I added a print of the current time incl. seconds and always see an update of the time when I type something in the terminal. autocmd TextChangedT * call s:on_complete_check()
function! s:on_complete_check() abort
lua <<EOF
print(os.date("%X"))
local line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(0)[2]
local current = string.sub(line, cursor, cursor + 1)
if current == "." or current == "," or current == " " then
require('cmp').close()
end
local before_line = string.sub(line, 1, cursor + 1)
local after_line = string.sub(line, cursor + 1, -1)
if not string.match(before_line, '^%s+$') then
if after_line == "" or string.match(before_line, " $") or string.match(before_line, "%.$") then
require('cmp').complete()
end
end
EOF
endfunction I get no snippet list to appear. In fact I can put some wrapping code around the IPython command and do the switch in the background. Hence, if I can get any zsh snippet to be shown, that would already be a big win. |
Sorry, I don't know what the problem is, maybe we should wait for @Shougo's pr to solve the problem |
If you need the feature, |
@jamilraichouni I have tested your snippet. |
diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua
index 6ec11a0..2cde661 100644
--- a/lua/cmp/core.lua
+++ b/lua/cmp/core.lua
@@ -371,7 +371,7 @@ core.confirm = function(self, e, option, callback)
feedkeys.call('', 'n', function()
-- Restore the line at the time of request.
local ctx = context.new()
- if api.is_cmdline_mode() then
+ if api.is_cmdline_mode() or api.is_terminal_mode() then
local keys = {}
table.insert(keys, keymap.backspace(ctx.cursor_before_line:sub(e:get_offset())))
table.insert(keys, string.sub(e.context.cursor_before_line, e:get_offset()))
diff --git a/lua/cmp/utils/api.lua b/lua/cmp/utils/api.lua
index 8153c9e..89f3075 100644
--- a/lua/cmp/utils/api.lua
+++ b/lua/cmp/utils/api.lua
@@ -13,6 +13,8 @@ api.get_mode = function()
return 's' -- select
elseif mode == 'c' and vim.fn.getcmdtype() ~= '=' then
return 'c' -- cmdline
+ elseif mode == 't' then
+ return 't' -- terminal
end
end
@@ -32,9 +34,13 @@ api.is_visual_mode = function()
return api.get_mode() == 'x'
end
+api.is_terminal_mode = function()
+ return api.get_mode() == 't'
+end
+
api.is_suitable_mode = function()
local mode = api.get_mode()
- return mode == 'i' or mode == 'c'
+ return mode == 'i' or mode == 'c' or mode == 't'
end
api.get_current_line = function()
Here is the minimal patch to support terminal mode. |
@hrsh7th Can we merge this patch? |
Thank you very much @Shougo ! I got it to run and will try that out within the next weeks. |
Well, the patch is just works and more changes are needed. You can test it before. |
Hi!
First: Thank you very much for the different completion/ source plugins @hrsh7th! The stuff is really helpful!
My question:
Is there any chance/ trick how I could achieve that
nvim-cmp
triggers in the internal terminal window?Use cases:
cmp-buffer
That would be really awesome!
Many thanks and all best,
Jamil
The text was updated successfully, but these errors were encountered: