From 6a3f415f263ed9a3a5667c02c8798562e95e812c Mon Sep 17 00:00:00 2001 From: m4ttm Date: Wed, 12 Oct 2022 06:05:44 +0100 Subject: [PATCH 1/6] Insert single word --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ autoload/copilot.vim | 10 ++++++++++ 2 files changed, 53 insertions(+) diff --git a/README.md b/README.md index cfac4e5e..cad119ef 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,46 @@ +# Copilot-One-Word.vim +This is a fork of the Neovim plugin for GitHub Copilot with the added feature of being able to add a single word at a time by pressing the shift and tab keys together. + +## Getting started + +1. Install [Neovim][] or the latest patch of [Vim][] (9.0.0185 or newer). + +2. Install [Node.js][] version 16. (Other versions should work too, except + Node 18 which isn't supported yet.) + +3. Install `github/copilot.vim` using vim-plug, packer.nvim, or any other + plugin manager. Or to install manually, run one of the following + commands: + + * Vim, Linux/macOS: + + git clone https://github.com/m4ttm/copilot.vim.git \ + ~/.vim/pack/github/start/copilot.vim + + * Neovim, Linux/macOS: + + git clone https://github.com/m4ttm/copilot.vim.git \ + ~/.config/nvim/pack/github/start/copilot.vim + + * Vim, Windows (PowerShell command): + + git clone https://github.com/m4ttm/copilot.vim.git ` + $HOME/vimfiles/pack/github/start/copilot.vim + + * Neovim, Windows (PowerShell command): + + git clone https://github.com/m4ttm/copilot.vim.git ` + $HOME/AppData/Local/nvim/pack/github/start/copilot.vim + +4. Start Neovim and invoke `:Copilot setup`. + +[Node.js]: https://nodejs.org/en/download/ +[Neovim]: https://github.com/neovim/neovim/releases/latest +[Vim]: https://github.com/vim/vim + +Suggestions are displayed inline and can be accepted by pressing the tab key. +See `:help copilot` for more information. + # Copilot.vim GitHub Copilot uses OpenAI Codex to suggest code and entire functions in diff --git a/autoload/copilot.vim b/autoload/copilot.vim index 3d61311b..e88e6d05 100644 --- a/autoload/copilot.vim +++ b/autoload/copilot.vim @@ -457,6 +457,8 @@ function! copilot#TextQueuedForInsertion() abort endtry endfunction + + function! copilot#Accept(...) abort let s = copilot#GetDisplayedSuggestion() if !empty(s.text) @@ -791,3 +793,11 @@ function! copilot#Command(line1, line2, range, bang, mods, arg) abort return 'echoerr ' . string(v:exception) endtry endfunction + +function! AcceptSingleWord() + let suggestion = copilot#Accept("") + let bar = copilot#TextQueuedForInsertion() + return split(bar, '[ .]\zs')[0] +endfunction + +imap