highlight VimgdbCurrentLine ctermbg=130 guibg=#FFE568 let s:vimgdb_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h') let s:next_session_id = 0 let s:sessions = {} function! Tapi_vimgdb_goto(bufnum, arglist) if len(a:arglist) != 3 return endif let session_id = a:arglist[0] let filename = a:arglist[1] let line = a:arglist[2] let session = s:sessions[session_id] " Go to source window noautocmd call win_gotoid(session['source_winid']) " Open file if needed if filename != expand('%:p') execute 'edit' fnameescape(filename) endif " Update highlighted line if session['current_line_matchid'] != -1 call matchdelete(session['current_line_matchid']) endif let session['current_line_matchid'] = matchaddpos('VimgdbCurrentLine', [line]) " Jump to current line if its not visible let first_visible = line('w0') let last_visible = line('w$') if last_visible > first_visible && (line < first_visible || line > last_visible) execute 'keepjumps normal!' line . 'G' endif " Switch back to debugger window noautocmd call win_gotoid(bufwinid(a:bufnum)) endfunction function! s:close_session(session_id) if !has_key(s:sessions, a:session_id) return endif let session = s:sessions[a:session_id] if session['current_line_matchid'] != -1 noautocmd call win_gotoid(session['source_winid']) call matchdelete(session['current_line_matchid']) endif endfunction function! s:vimgdb(mods, gdb_args) let session_id = s:next_session_id let s:next_session_id = s:next_session_id + 1 let s:sessions[session_id] = {'source_winid': win_getid(), 'current_line_matchid': -1} execute a:mods 'terminal' '++close' s:vimgdb_dir . '/gdb/gdb-wrapper' session_id a:gdb_args execute 'autocmd BufDelete <buffer> call s:close_session(' . session_id . ')' endfunction command! -nargs=+ -complete=shellcmd Vimgdb call s:vimgdb('<mods>', "<args>")