kassio / neoterm

Wrapper of some vim/neovim's :terminal functions.
Other
1.32k stars 117 forks source link

Send special characters to terminal #164

Closed amsibamsi closed 6 years ago

amsibamsi commented 7 years ago

How can I define a mapping to send control sequences to the terminal, e.g. to repeat the last command?

kassio commented 7 years ago

If you mean something like !!, you could do:

  nnoremap <silent> <leader>tR :call neoterm#exec(['!!', '', ''])<cr>
rperryng commented 7 years ago

I think this is related to the original question, is there a way to send keyboard events to the neoterm terminal? E.g. sometimes I want to send the <C-d> (end of input) or <C-c> to kill the process ruinning in the neoterm terminal. This functionality can be done with regular vim bindings (e.g. tnoremap <leader>td a<C-c><C-\><C-n>)

rperryng commented 7 years ago

d'oh. From the README...RTFM...

" kills the current job (send a <c-c>)
nnoremap <silent> ,tc :call neoterm#kill()<cr>

Looking through the source now I can see that it's simply a matter of escaping the command like

nnoremap <leader>td :call neoterm#exec("\<C-d>")

Sorry for all the noise on this issue - Thank you so much for writing this plugin! It's made my workflow dreamlike!

amsibamsi commented 7 years ago

I tried your suggestions. I also discovered the kill() function after some time ;-)

exec() does not seem to work for me. It sends the string as is to my shell, not interpreting the control sequences.

I'm using fish shell, maybe that makes things different from bash/zsh. To clarify, I wanted to send control sequences like (previous command from history, and enter) to the terminal window while in normal mode focusing another editor window with text.

kassio commented 7 years ago

exec() does not seem to work for me. It sends the string as is to my shell, not interpreting the control sequences. I'm using fish shell, maybe that makes things different from bash/zsh

This plugin wasn't tested in fish shell, maybe the way we need to send the commands to it is different, but I don't have any knowledge about that. 😞

To clarify, I wanted to send control sequences like (previous command from history, and enter) to the terminal window while in normal mode focusing another editor window with text.

The enter usually is just an empty value after the desired command, for control sequences I use \<c-ANYTHING IN HERE> and usually it works in zsh and bash, but again, this can be different in fish.

@justinmk you know anything if send commands to fish shell is different from bash/zsh? (asking because neoterm just uses neovim's api to do it)

bit101 commented 2 years ago

In case anyone else comes here years later, like me, I'll add that there is now Tkill which is perfect.