0

Problem

I am trying to map the F10 key with theterminal bash % command so I can execute the current open file with bash in a split pane setup (this functions works). The problem is when I try to add the key combo CTRL-W R to swap the vim pane positions in the mapping, the positions do not swap. When I type CTRL-W R manually, it works.

This is the line that I have in my .vimrc

nnoremap <F10> :terminal bash % <cr> <C-w> <C-r>

I have also tried adding a pipe and changing noremap to map but that did not solve anything.

map <F10> :terminal bash % <cr> | <C-w> r

Question

Is is there a way to combine Vim commands (eg :terminal bash %) with CTRL-W R in a single nnoremap line?

6
  • You should keep the <C-w>... commands for normal mode operations since it's a normal mode command. In the command like you should try to use :h :wincmd instead (this is why this command exists). Otherwise the right approach to execute normal mode commands in the command line is to use :h :normal
    – statox
    Feb 23, 2023 at 15:58
  • If you don't include the spaces (:nnoremap <f10> :terminal bash %<enter><C-w>r) does it work?
    – D. Ben Knoble
    Feb 23, 2023 at 18:39
  • Hi @Luna we are trying to answer your question fully :-) Are you still searching a solution at your problem? Could precise what is not already answered? Feb 26, 2023 at 5:19
  • 1
    @statox - I just discovered :wincmd thanks!
    – Luna
    Feb 27, 2023 at 12:10
  • I have discovered the problem. My script took about 5 seconds to fully execute with :terminal bash %. tThat paned seemed to have been locked which prevented <C-w>r. It also prevented me from typing any command with : . I would have to CTRL-WW to go back to the original pane to swap positions.
    – Luna
    Feb 27, 2023 at 12:15

1 Answer 1

1

I would propose:

nnoremap <F10> :terminal bash % <cr>:wincmd r<cr>

As @Matt mention in his comment :wincmd r is the command that is equivalent to Ctrl wr.

1
  • Perhaps an explanation could accompany the proposal?
    – D. Ben Knoble
    Feb 23, 2023 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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