I started debugging a c program inside vim with:
:packadd termdebug :Termdebug
with vim 8 and and gdb > 8.3 installed.
In order to set a breakpoint, I would like to send the following string while the cursor is in file main.c (by typing
so that the gdb terminal receives:
if the file name is
main.c and the current line for this example is 100 and represented with
let lineNumber = line('.')
Here is what I've come up with until now:
nnoremap <leader>b : call SetBreakPoint()<CR> function! SetBreakPoint() abort let lineNumber = line('.') let fileName = %f exe "normal! ma" exe "normal! \<C-w>w\<C-w>w" | call term_sendkeys('', "break fileName\:lineNumber\<CR>") exe "normal! \<C-w>w`a" endfunction
exe "normal! \<C-w>w\<C-w>w | call term_sendkeys()..." takes into account that the cursor is in a file named main.c and has to traverse Nerdtree to arrive to the Terminal window opened by vim with gdb.
I have in total 3 vim windows (main.c, Nerdtree and Terminal (gdb)).
The problem here is that I cannot make
term_sendkeys() load the values of fileName and lineNumber.
However, changing the longest line of code to
exe "normal! \<C-w>w\<C-w>w" | call term_sendkeys('', "break main.c:100\<CR>")
works but defeats the whole purpose of defining break points inside the vim main.c window without having to manually change window and type in the break command for gdb.