0

help terminal-input said

To use `ALT+{h,j,k,l}` to navigate windows from any mode: >
    :tnoremap <A-h> <C-\><C-N><C-w>h
    :tnoremap <A-j> <C-\><C-N><C-w>j
    :tnoremap <A-k> <C-\><C-N><C-w>k
    :tnoremap <A-l> <C-\><C-N><C-w>l
    :inoremap <A-h> <C-\><C-N><C-w>h
    :inoremap <A-j> <C-\><C-N><C-w>j
    :inoremap <A-k> <C-\><C-N><C-w>k
    :inoremap <A-l> <C-\><C-N><C-w>l
    :nnoremap <A-h> <C-w>h
    :nnoremap <A-j> <C-w>j
    :nnoremap <A-k> <C-w>k
    :nnoremap <A-l> <C-w>l

. Thus I add these shortcut maps into my init file. And when a terminal is open, i type <A-j>, the cursor jumped from the terminal into the normal interface (The terminal interface does not close.). i want jump back to the terminal interface. However, all the shortcuts do not work. They only jump across windows.

romainl
  • 186,200
  • 21
  • 280
  • 313
xye
  • 11
  • 2
  • 1
    Not sure if it is the same terminal I used before, but when you jump back to a terminal you need to use insert mode (just press `A` for line-append, for example). Normal mode in a terminal would allow you to copy previous output. So you jump to the terminal window with normal `C-W j` for example and then you press `a` to append text to the terminal prompt. – Jorge Bellon Apr 06 '22 at 09:18
  • Yes. I typed into the terminal by using insert mode. Thank you! – xye Apr 07 '22 at 00:03

1 Answers1

0

:) i wanted the same thing i searched online to learn how to write a custom function around buffers, then came with this:

function SwitchToTerm()
  let term_bufs = getbufinfo({'buflisted':1})
  let curr_buf = bufnr('%')
  call filter(term_bufs, 'v:val.name =~ "^term"')
  call filter(term_bufs, 'v:val.bufnr != ' . curr_buf)
  call map(term_bufs, { _, e -> ({"nr": e.bufnr, "lu": e.lastused}) })
  if bufname('%') =~ "^term"
    call sort(term_bufs, { b1, b2 -> b1.lu - b2.lu })
  else
    call sort(term_bufs, { b1, b2 -> b2.lu - b1.lu })
  endif
  exec "b " . term_bufs[0].nr
endfunction

nnoremap <silent> <Leader>t :call SwitchToTerm()<cr>

in my ~/.vimrc and using Neovim but not sure if that matters. It is supposed to go to the most recently used buffer, then continuously cycle through terminal buffers if already on at a terminal. I switch to BufExplorer a lot to visit another file, and the last terminal becomes iffy there... but switching buffers directly from the command line works fine.

nymo
  • 532
  • 1
  • 5
  • 14