1

I'm creating a mapping which is supposed to navigate to a specific window (call TEST_WIN), focus in on the terminal and then delete a single character.

The mapping looks like this:

noremap '; :let curWin = win_getid()<CR>:call win_gotoid(TEST_WIN)<CR>A<C-c><C-l><up><BS>

I have substituted <BS> in with <C-w> and both of these delete the entire line instead of a single charater/word.

How can I get it to just delete a single word or character?

I should add that when I am controlling the terminal without the command, <C-w> and the backspace key on my Mac both work as expected. The problem only arises during the command.

  • You have <C-c there with noremap, this means that control+c will have no effect if you have some mapping to it. Please explain what are you trying to do because this mapping looks confusing. – Moshe Nov 15 '20 at 11:37
  • @Moshe <C-c> works perfectly fine. It's the <BS> that doesn't work. – libby Nov 16 '20 at 6:30
  • Note there's also a Vi and Vim Stack Exchange for questions on Vim, you might want to take a look there as well. – filbranden Nov 19 '20 at 8:07
0

UPDATE: Answered here.

Terminal windows are special, you can't just have a mapping use a command to switch to insert mode and then include characters to type in the terminal directly.

Instead, you should call function term_sendkeys() to interact with the terminal.

Something like the following should work:

function! TermHistory()
  call win_gotoid(TEST_WIN)
  call term_sendkeys('', "\<C-c>\<C-l>\<Up>\<BS>")
endfunction
nnoremap <silent> '; :call TermHistory()<CR>
  • @fibranden, this is great, but do you know how it could be done for neovim? the term_sendkeys function isn't available for neovim – libby Nov 19 '20 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.