From ef81d6388dfc3e5cc93b39874f69b7903c15b0e1 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 11 Jan 2026 04:04:12 +0100 Subject: Update post: Integrated debugging in Vim --- content/posts/2026-01-09-vim.md | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'content/posts') diff --git a/content/posts/2026-01-09-vim.md b/content/posts/2026-01-09-vim.md index cd3cea7..74e0b15 100644 --- a/content/posts/2026-01-09-vim.md +++ b/content/posts/2026-01-09-vim.md @@ -126,8 +126,8 @@ let g:termdebug_config['variables_window'] = v:true nnoremap x :call LocalRun() nnoremap c :call LocalMake() -nnoremap v :call LocalDebugMain() -nnoremap b :call LocalDebugLine() +nnoremap m :call LocalDebugMain() +nnoremap l :call LocalDebugLine() function! LocalRun() abort let envs = join( map(items(g:_envs), { _, kv -> kv[0] . '=' . kv[1] }), ' ') @@ -159,8 +159,11 @@ function! LocalDebugLine() abort endfunction function! LocalMake() abort - let envs = join( map(items(g:_envs), { _, kv -> kv[0] . '=' . kv[1] }), ' ') - execute printf('silent !env %s %s', g:_make, envs) + for [k, v] in items(g:_envs) + execute printf("let $%s = %s", k, string(v)) + endfor + + silent make " Filter non valid errors out of quicklist. let qfl = getqflist() @@ -168,25 +171,20 @@ function! LocalMake() abort call setqflist(filtered, 'r') redraw! - - if len(filtered) > 0 - execute exists(':CtrlPQuickfix') ? 'CtrlPQuickfix' : 'copen' - else - cclose - endif + execute len(filtered) > 0 ? 'copen' : 'cclose' endfunction ``` -I am using the CtrlP plugin, so I also use it for displaying the Quickfix List. -But if the plugin is not found; it will default to native quicklist with -`:copen`. +> **Note**: If any errors are found during the compilation mode the Quickfix +> list will be populated and opened. You could CtrlP Quickfix for this as well, +> I just want to stick to what Vim supports natively. Lets check these keybindings. - `Leader+x` - runs the binary in the terminal above and providing environment variables and argument - `Leader+c` - runs make and puts error in Quickfix List then opens with `:copen` -- `Leader+v` - launches DebugTerm/DBG debugger with all variables and breaks on main -- `Leader+b` - launches DebugTerm/DBG debugger with all variables and breaks on current line +- `Leader+m` - launches DebugTerm/DBG debugger with all variables and breaks on main +- `Leader+l` - launches DebugTerm/DBG debugger with all variables and breaks on current line This setup can get even more elaborate. Depending on your needs. This example works really well for projects using C, but anything goes here. -- cgit v1.2.3