TermHelp takes a text prompt and turns it into a command. For example, :TermHelp find command to search three levels deep for Makefile
will insert this in the current terminal window:
$ find . -maxdepth 3 -name "Makefile"
This plugin assumes you have a terminal open inside of NeoVim, which you can do by default with :term
.
I suggest using vim-termhere so you can have an easy mapping for opening split terminals,
and so the suggested terminal-buffer-only mappings below work.
Aside from :TermHelp [instructions]
, you can also select a failed command and ask for help - with this visual selection active:
$ find . type f -iname Makefile
find: ‘type’: No such file or directory
find: ‘f’: No such file or directory
Doing :Chat terminal_correction
will output the fixed command. You can also specify addition instructions at the end of this,
e.g. :Chat terminal_correction search for the CMake defining file instead
gives:
find . -type f -iname CMakeLists.txt
Note the typo 'zstsd' - it knows we mean zstd:
You need CodeGPT.nvim, to be loaded after nvim-termhelp.
Add the following line to your init.vim or init.lua file within the plug call block:
Plug 'TamaMcGlinn/nvim-termhelp'
Plug 'dpayne/CodeGPT.nvim'
Then, run :PlugInstall in NeoVim to install the plugin.
In your init.lua, add the following snippet:
require("lazy").setup({
-- Load 'nvim-termhelp' first
{ "TamaMcGlinn/nvim-termhelp" },
-- Then load 'CodeGPT.nvim'
{
"dpayne/CodeGPT.nvim",
config = function()
-- Configuration for CodeGPT.nvim if needed
-- For example, you might want to set some default options or key mappings for CodeGPT
require('codegpt').setup({
-- your configuration here
})
end,
-- This ensures CodeGPT.nvim loads after nvim-termhelp has been loaded
after = "nvim-termhelp",
},
})
First, navigate to your Pathogen bundle directory, usually ~/.config/nvim/bundle. Then, clone the repository:
cd ~/.config/nvim/bundle
git clone /~https://github.com/TamaMcGlinn/nvim-termhelp.git 01-nvim-termhelp
git clone /~https://github.com/dpayne/CodeGPT.nvim.git 02-CodeGPT.nvim
Pathogen should load the plugin automatically the next time you start NeoVim.
Add the following to your init.vim or init.lua in the dein block:
call dein#add('TamaMcGlinn/nvim-termhelp')
call dein#add('dpayne/CodeGPT.nvim', {'depends': 'nvim-termhelp'})
In your init.lua, add:
use { 'TamaMcGlinn/nvim-termhelp', }
use {
'dpayne/CodeGPT.nvim',
after = 'nvim-termhelp', -- Ensure CodeGPT.nvim loads after nvim-termhelp
config = function()
-- Configuration for CodeGPT.nvim here
require('codegpt').setup({
-- your configuration here
})
end
}
If you are using a different plugin manager, please send me a PR adding the instructions for this plugin; refer to its documentation for instructions on adding plugins. The general approach involves adding the plugin's git repository URL (/~https://github.com/TamaMcGlinn/nvim-termhelp) to your plugin manager's configuration file or command.
I can recommend these mappings for your vimrc:
augroup termhelp
autocmd FileType terminal nnoremap <buffer> <Leader>n :TermHelp
autocmd FileType terminal vnoremap <buffer> <Leader>n :Chat terminal_correction
autocmd FileType terminal vnoremap <buffer> <Leader>nn :Chat terminal_correction<CR>
augroup END
or in lua:
vim.api.nvim_command([[
augroup termhelp
autocmd FileType terminal nnoremap <buffer> <Leader>n :TermHelp<CR>
autocmd FileType terminal vnoremap <buffer> <Leader>n :Chat terminal_correction
autocmd FileType terminal vnoremap <buffer> <Leader>nn :Chat terminal_correction<CR>
augroup END
]])
Note that the terminal filetype doesn't work by default without using vim-termhere, because Justin thinks the empty string is a more sensible default for terminal buffers. See neovim/neovim#4465.
You can just use regular nnoremap to define it in all buffers:
nnoremap <Leader>n :TermHelp
vnoremap <Leader>n :Chat terminal_correction
vnoremap <Leader>nn :Chat terminal_correction<CR>
You should absolutely not set g:termhelp_learn_to_stop_worrying = v:true
. This automatically runs the command generated,
so you don't have time to check if the resulting command bricks your machine.
Next, definitely don't run :TermHelp delete all files on the machine
.
Have fun good luck DON'T PANIC!