Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initial window split in termdebug vim

I am new to vim and recently came to know that we can use Termdebug to debug code in vim with gdb. I liked this very much as i was searching for a good vim integration with gdb. When i launch Termdebug window is split horizontally in gdb window, program window & source code window. I like to vertically split source code window to right. For that, currently i move focus on source code window and press Ctrl+w & L.

Before splitting:

enter image description here

After splitting:

enter image description here

This i have to do every time i launch Termdebug. Is there a way to .vimrc so that when i launch Termdebug, source code window is automatically splitted to right. I have seen here which suggests to use:

let g:termdebug_wide = 163

This does automatic splitting but it has some problem in highlighting lines during debug as can be seen in picture below:

enter image description here

Please suggest how can i change .vimrc

like image 615
Sumit Kumar Avatar asked Oct 20 '19 07:10

Sumit Kumar


2 Answers

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

like image 58
dannyadam Avatar answered Nov 06 '22 01:11

dannyadam


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.

like image 31
Sumit Kumar Avatar answered Nov 06 '22 01:11

Sumit Kumar