I have been using nvim terminal mode to learn python and I want to have Ctrl-C break the python script from the terminal window even when I am not in insert mode. However, I also want Ctrl-C in my python script to result in entering an escape command directly to the terminal.
if exists(':tnoremap') nnoremap <C-c> <C-w>wi<C-c><C-\><C-n><C-w>w " Ctrl-c from py sends key interupt to python terminal end
in my .vimrc file which gives me the functionality for sending Ctrl-C to the terminal when I am in the python script buffer.
I have tried
:tnoremap <C-c> i<C-c>
which does not work, I think because I am trying to issue the command from normal mode. This is a documented 'feature' of tmap.
I have found that
nnoremap <buffer> <C-c> i<C-c>
works but because the buffer has a name like :term\##:python where ## is the process id, and therefore varies, I cannot figure out how to incorporate the above into my rc file such that the terminal buffer automatically inherits this (local) functionality.
I have tried (from this answer)
augroup MyTermMappings autocmd! autocmd TermOpen * nnoremap <buffer> <C-c> i<C-c> augroup END
but this makes my whole rc file crap out with the error
no such group or event TermOpen * nnoremap <buffer>...
I have also tried changing my launch of the terminal command (which is currently
nnoremap <leader>r :split \| terminal python<CR> <C-w>w)
to send the local remap to the command line on launch but all I have been able to accomplish is crashing the python terminal.
I know I can just run the
nnoremap <buffer> <C-c> i<C-c> after launching terminal but I would like to have any buffer that is launched with :terminal have this command.
Alternatively, I tried having the default behavior be that in normal mode Ctrl-C mapped to enter insert mode and type Ctrl-c e.g.
nnoremap <C-c> i<C-c> and then further in the .vimrc file
autocmd FileType python nnoremap <buffer> <C-w>wi<C-c><C-\><C-n><C-w>w but that also did not work.
I think this can be solved using autocmd options in Vim or if the nmap cmd can take a pattern but I am fairly unfamiliar with these and have not had any luck looking at other responses.