diff --git a/clients/vim/.gitignore b/clients/vim/.gitignore new file mode 100644 index 0000000..0a56e3f --- /dev/null +++ b/clients/vim/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/clients/vim/README.md b/clients/vim/README.md index 4ce859a..9b8468b 100644 --- a/clients/vim/README.md +++ b/clients/vim/README.md @@ -12,12 +12,15 @@ " Make sure that the filetype plugin has been enabled. filetype plugin on +" Assume using vim-plug as plugin manager Plug 'TabbyML/tabby', {'rtp': 'clients/vim'} + +" Set URL of Tabby server let g:tabby_server_url = 'http://127.0.0.1:5000' ``` ## Usage 1. In insert mode, Tabby will show code suggestion when you stop typing. Press `` to accpet the current suggestion, `` to see the next suggestion, `` to see previous suggestion, or `` to dismiss. - 2. Use command `:Tabby enable` to enable, `:Tabby disable` to disable Tabby, and `:Tabby status` to check status. +3. Use command `:help Tabby` for more information. diff --git a/clients/vim/autoload/tabby.vim b/clients/vim/autoload/tabby.vim index 3c6691a..9b11236 100644 --- a/clients/vim/autoload/tabby.vim +++ b/clients/vim/autoload/tabby.vim @@ -7,27 +7,77 @@ let g:autoloaded_tabby = 1 let s:commands = {} +function! s:commands.status(...) + call tabby#Status() +endfunction + +function! s:commands.enable(...) + call tabby#Enable() + call tabby#Status() +endfunction + +function! s:commands.disable(...) + call tabby#Disable() + call tabby#Status() +endfunction + +function! s:commands.toggle(...) + call tabby#Toggle() +endfunction + +function! s:commands.help(...) + let args = get(a:, 1, []) + if len(args) < 1 + execute 'help Tabby' + return + endif + try + execute 'help Tabby-' . join(args, '-') + return + catch + endtry + try + execute 'help tabby_' . join(args, '_') + return + catch + endtry + execute 'help Tabby' +endfunction + +function! tabby#CompleteCommands(arglead, cmd, pos) + let words = split(a:cmd[0:a:pos].'#', ' ') + if len(words) > 3 + return [] + endif + if len(words) == 3 + if words[1] == 'help' + let candidates = ['compatibility', 'commands', 'options', 'keybindings'] + else + return [] + endif + else + let candidates = keys(s:commands) + endif + + let end_index = len(a:arglead) - 1 + if end_index < 0 + return candidates + else + return filter(candidates, { idx, val -> + \ val[0:end_index] ==# a:arglead + \}) + endif +endfunction + function! tabby#Command(args) let args = split(a:args, ' ') if len(args) < 1 call tabby#Status() + echo 'Use :help Tabby to see available commands.' return endif - if args[0] == 'enable' - call tabby#Enable() - call tabby#Status() - elseif args[0] == 'disable' - call tabby#Disable() - call tabby#Status() - elseif args[0] == 'server' - if len(args) < 2 - echo 'Usage: Tabby server ' - return - endif - call tabby#SetServerUrl(args[1]) - echo 'Tabby server URL set to ' . args[1] - elseif args[0] == 'status' - call tabby#Status() + if has_key(s:commands, args[0]) + call s:commands[args[0]](args[1:]) else echo 'Unknown command' endif @@ -39,6 +89,10 @@ if !exists('g:tabby_enabled') let g:tabby_enabled = v:true endif +if !exists('g:tabby_suggestion_delay') + let g:tabby_suggestion_delay = 150 +endif + if !exists('g:tabby_filetype_to_languages') " From: vim filetype https://github.com/vim/vim/blob/master/runtime/filetype.vim " To: vscode language identifier https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers @@ -51,6 +105,13 @@ if !exists('g:tabby_filetype_to_languages') \ } endif +function! tabby#SetServerUrl(url) + let g:tabby_server_url = a:url + call s:UpdateServerUrl() +endfunction + +" Node job control + function! tabby#Enable() let g:tabby_enabled = v:true if !tabby#Running() @@ -73,13 +134,6 @@ function! tabby#Toggle() endif endfunction -function! tabby#SetServerUrl(url) - let g:tabby_server_url = a:url - call s:UpdateServerUrl() -endfunction - -" Node job control - function! tabby#Start() if !g:tabby_enabled || tabby#Running() return @@ -233,8 +287,7 @@ function! tabby#Schedule() return endif call tabby#Clear() - let delay = 150 - let s:scheduled = timer_start(delay, function('tabby#Trigger')) + let s:scheduled = timer_start(g:tabby_suggestion_delay, function('tabby#Trigger')) endfunction function! tabby#Trigger(timer) diff --git a/clients/vim/doc/tabby.txt b/clients/vim/doc/tabby.txt new file mode 100644 index 0000000..82e4b80 --- /dev/null +++ b/clients/vim/doc/tabby.txt @@ -0,0 +1,102 @@ +tabby.txt Tabby + *Tabby* *tabby* *Tabby-doc* +Tabby is a self-hosted AI coding assistant that can suggest multi-line code or +full functions in real-time. For more information, please check out our +{Website}{1} and {Github}{2}. If you encounter any problem or have any +suggestion, please open an {issue}{3}. + {1} https://www.tabbyml.com/ + {2} https://github.com/TabbyML/tabby + {3} https://github.com/TabbyML/tabby/issues/new + + *Tabby-compatibility* *Tabby-neovim* +Compatibility~ +This plugin is compatible with VIM 9.0+ with `+job` and `+textprop` features +enabled, or NeoVIM 0.6.0+. + + *Tabby-commands* +Commands~ + *:Tabby* +:Tabby Same as |:Tabby-status|. + *:Tabby-enable* +:Tabby enable Start Tabby if not currently running in current VIM + process. + *:Tabby-disable* +:Tabby disable Stop Tabby in current VIM process. To disable Tabby + globally, set |g:tabby_enable| to v:false. + *:Tabby-toggle* +:Tabby toggle Toggle enable or disable Tabby, same as use command + |:Tabby-enable| or |:Tabby-disable|. + *:Tabby-status* +:Tabby status Check whether Tabby is enabled or not, and the + reachabilty to the Tabby server. Also report errors + if any compatibility problems exist. + *:Tabby-help* +:Tabby help [subject] Search for help information in this document using + VIM command `:help`. + + *Tabby-options* +Options~ + *g:tabby_enable* +g:tabby_enable Controls Tabby whether auto-starts along with VIM or + not. Modifying this value do not start or stop Tabby + at the same time. You can use |:Tabby-enable| or + |:Tabby-disable| to start or stop Tabby manually in + current VIM process. +> + let g:tabby_enable = v:true +< + *g:tabby_server_url* +g:tabby_server_url Specify the Tabby server URL. You always need this + setting in your vimrc file, unless you are using the + default value: "http://localhost:5000". +> + let g:tabby_server_url = 'http://localhost:5000' +< + *g:tabby_suggestion_delay* +g:tabby_suggestion_delay + Controls the delay after which the suggestion request + is sent to server. If you want suggestion to show up + more quickly or slowly, try to tune this value. + Default value is 150 milliseconds. +> + let g:tabby_suggestion_delay = 150 +< + *g:tabby_filetype_to_languages* +g:tabby_filetype_to_languages + This option is a dictionary that map from the VIM + `:filetype` to {VSCode-Language-Identifier}{1}. Not + listed filetype will be used as language identifier + directly. + A correct language identifier is required for the + Tabby server to generate suggestion. If your filetype + need converting to language identifier but not listed, + add it in this dictionary. + You can also map a filetype to "unknow" to prevent + Tabby giving suggestion for specified filetype. + {1} https://code.visualstudio.com/docs/languages/identifiers +> + let g:tabby_filetype_to_languages = { + \ "bash": "shellscript", + \ "cs": "csharp", + \ "objc": "objective-c", + \ "objcpp": "objective-cpp", + \ } +< + + *Tabby-keybindings* *Tabby-maps* +Keybindings~ + + Accept the current suggestion, fallback to normal + `` if no suggestion is shown. + + Dismiss the current suggestion. Fallback to normal + `` if no suggestion is shown. + + Show the next suggestion. There is a empty suggestion + after the last, before return to first one. + + Show the previous suggestion. There is a empty + suggestion before the first, before return to last + one. + + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/clients/vim/plugin/tabby.vim b/clients/vim/plugin/tabby.vim index a7293bf..f1ee0af 100644 --- a/clients/vim/plugin/tabby.vim +++ b/clients/vim/plugin/tabby.vim @@ -5,7 +5,7 @@ let g:loaded_tabby = 1 call tabby#Start() -command! -nargs=* Tabby exe tabby#Command() +command! -nargs=* -complete=customlist,tabby#CompleteCommands Tabby call tabby#Command() imap