<C-\><C-n>
is working as (I'd) exepected, but not from a Vimscript.
I am trying to make a script that will:
- open Neovim's
:terminal
- run a python script
- exit from the terminal input mode
- manipulate the terminal buffer just as text
I already do that manually everyday. That's why the script would help. (:
But I can't find a way to give the <C-\><C-n>
to the terminal buffer.
Here is the most 'consistent piece' achieved so far:
function! AFunction(...)
let firstArg=a:0
let secondArg=a:1
let thirdArg=a:2
let fourthArg=a:3
let fifthArg=a:4
command! -nargs=* AFunctionCommand call Fetching(<f-args>)
execute ":terminal python a-python-script.py" a:1 a:2 a:3 a:4
endfunction
It does work, but I can't find a way to pass the exit key.
The first idea was to concatenate the strings, as mentioned here. Perhaps something that would allow to stablish where is the <cr>
(after the arguments):
execute ":terminal python a-python-script.py" a:1 a:2 a:3 a:4 "\<cr>" . '<C-\><C-n>'
If try to do something like:
execute ":terminal python a-python-script.py" a:1 a:2 a:3 a:4
<C-\><C-n>
It doesn't work since terminal has 'nomodifiable' by the default. The same if trying to call a function with the escape keys.
Yes, it is a horrible Vimscript art, and any comment on the code would be really appreciated, but since this is not Code Review, I would be happy with just the reason why doesn't work, or where is my logic not working. (:
:exe "norm! \<C-\>\<C-N>"
and yes, you need to make sure to use double quotation marks:exe ":term..." a:*..
it looks like the 'terminal' process was never done, and nothing below that will be parsed... I commented out theexecute
line and tested with these two in instead:execute ":terminal "
andexe "norm! \<C-\>\<C-N>"
. Thanks again, it's getting close. (:'makeprg'
?:normal
cannot be used while in terminal-mode (AKA "insert-mode in a terminal buffer"). Usefeedkeys("\<C-\><C-N>")
instead (and no the 2nd "\" is not escaped... yay vimscript)