diff --git a/README.md b/README.md index 9f15e9a9..52681102 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,51 @@ +# m4ttm/copilot.vim + +This is a fork of the Neovim plugin for GitHub Copilot with the added feature of being able to add a single word or letter at a time. Map to your desired shortcuts with the copilot#AcceptWord and copilot#AcceptCharacter functions in your init.vim + +## 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 -real-time right from your editor. Trained on billions of lines of public +real-time right from your editor. Trained on billions of lines of public code, GitHub Copilot turns natural language prompts including comments and method names into coding suggestions across dozens of languages. @@ -12,7 +56,7 @@ To learn more, visit ## Subscription -GitHub Copilot requires a subscription. It is free for verified students and +GitHub Copilot requires a subscription. It is free for verified students and maintainers of popular open source projects on GitHub. GitHub Copilot is subject to the [GitHub Additional Product @@ -25,40 +69,40 @@ Terms](https://docs.github.com/en/site-policy/github-terms/github-terms-for-addi 2. Install [Node.js][]. 3. Install `github/copilot.vim` using vim-plug, packer.nvim, or any other - plugin manager. Or to install manually, run one of the following + plugin manager. Or to install manually, run one of the following commands: - * Vim, Linux/macOS: + - Vim, Linux/macOS: git clone https://github.com/github/copilot.vim.git \ ~/.vim/pack/github/start/copilot.vim - * Neovim, Linux/macOS: + - Neovim, Linux/macOS: git clone https://github.com/github/copilot.vim.git \ ~/.config/nvim/pack/github/start/copilot.vim - * Vim, Windows (PowerShell command): + - Vim, Windows (PowerShell command): git clone https://github.com/github/copilot.vim.git ` $HOME/vimfiles/pack/github/start/copilot.vim - * Neovim, Windows (PowerShell command): + - Neovim, Windows (PowerShell command): git clone https://github.com/github/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 +[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. ## Troubleshooting -We’d love to get your help in making GitHub Copilot better! If you have +We’d love to get your help in making GitHub Copilot better! If you have feedback or encounter any problems, please reach out on our [Feedback forum](https://github.com/orgs/community/discussions/categories/copilot). diff --git a/autoload/copilot.vim b/autoload/copilot.vim index 69a68133..4a7650b1 100644 --- a/autoload/copilot.vim +++ b/autoload/copilot.vim @@ -450,6 +450,8 @@ function! copilot#TextQueuedForInsertion() abort endtry endfunction + + function! copilot#Accept(...) abort let s = copilot#GetDisplayedSuggestion() if !empty(s.text) @@ -808,3 +810,19 @@ function! copilot#Command(line1, line2, range, bang, mods, arg) abort return 'echoerr ' . string(v:exception) endtry endfunction + +function! copilot#AcceptWord() + let suggestion = copilot#Accept("") + let bar = copilot#TextQueuedForInsertion() + return split(bar, '[ .]\zs')[0] +endfunction + +function! copilot#AcceptCharacter() + let suggestion = copilot#Accept("") + let bar = copilot#TextQueuedForInsertion() + return split(bar, '[ .]\zs')[0][0] +endfunction + +let g:copilot_filetypes = { + \ 'markdown': v:true, + \ } diff --git a/plugin/copilot.vim b/plugin/copilot.vim index 7ec0255c..15394788 100644 --- a/plugin/copilot.vim +++ b/plugin/copilot.vim @@ -40,6 +40,7 @@ function! s:MapTab() abort exe 'imap copilot#Accept(' . tab_fallback . ')' endif endif + imap