Initial window split in termdebug vim

This layout—with the editor on the right, and both GDB windows split horizontally on the left—can be set by configuring g:termdebug_wide in your .vimrc.

let g:termdebug_wide=1

See :help termdebug_wide for details.

I wrote a blog post on termdebug last year (May 2019), and recently (April 2020) addressed this same issue in a comment: https://www.dannyadam.com/blog/2019/05/debugging-in-vim/#comment-251004


Finally, I found how to do this by modifying vimrc. I mapped the whole sequence of keys to F6 for convenience.

autocmd filetype cpp nnoremap <F6> :Termdebug %:r<CR><c-w>2j<c-w>L

I added the above line in vimrc. Now, when i press F6 automatically opens windows with source code window on right like in the question above with no strange behavior.

Explanation:

  • :Termdebug %:r<CR> This will open Termdebug with all 3 windows horizontally.
  • <c-w>2j This will move focus to the source code window.
  • <c-w>L This will move source code window to the right.

Note: If you want focus back on the gdb window, you can add <c-w>h at the end of the above line.