Update post: Integrated debugging in Vim

Author Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-11 04:04:12 +0100
Committer Mitja Felicijan <mitja.felicijan@gmail.com> 2026-01-11 04:04:12 +0100
Commit ef81d6388dfc3e5cc93b39874f69b7903c15b0e1 (patch)
-rw-r--r-- content/posts/2026-01-09-vim.md 28
1 files changed, 13 insertions, 15 deletions
diff --git a/content/posts/2026-01-09-vim.md b/content/posts/2026-01-09-vim.md
...
126
  
126
  
127
nnoremap <leader>x :call LocalRun()<CR>
127
nnoremap <leader>x :call LocalRun()<CR>
128
nnoremap <leader>c :call LocalMake()<CR>
128
nnoremap <leader>c :call LocalMake()<CR>
129
nnoremap <leader>v :call LocalDebugMain()<CR>
129
nnoremap <leader>m :call LocalDebugMain()<CR>
130
nnoremap <leader>b :call LocalDebugLine()<CR>
130
nnoremap <leader>l :call LocalDebugLine()<CR>
131
  
131
  
132
function! LocalRun() abort
132
function! LocalRun() abort
133
	let envs = join( map(items(g:_envs), { _, kv -> kv[0] . '=' . kv[1] }), ' ')
133
	let envs = join( map(items(g:_envs), { _, kv -> kv[0] . '=' . kv[1] }), ' ')
...
159
endfunction
159
endfunction
160
  
160
  
161
function! LocalMake() abort
161
function! LocalMake() abort
162
	let envs = join( map(items(g:_envs), { _, kv -> kv[0] . '=' . kv[1] }), ' ')
162
	for [k, v] in items(g:_envs)
163
	execute printf('silent !env %s %s', g:_make, envs)
163
		execute printf("let $%s = %s", k, string(v))
  
164
	endfor
  
165
  
  
166
	silent make
164
  
167
  
165
	" Filter non valid errors out of quicklist.
168
	" Filter non valid errors out of quicklist.
166
	let qfl = getqflist()
169
	let qfl = getqflist()
...
168
	call setqflist(filtered, 'r')
171
	call setqflist(filtered, 'r')
169
  
172
  
170
	redraw!
173
	redraw!
171
  
174
	execute len(filtered) > 0 ? 'copen' : 'cclose'
172
	if len(filtered) > 0
  
173
		execute exists(':CtrlPQuickfix') ? 'CtrlPQuickfix' : 'copen'
  
174
	else
  
175
		cclose
  
176
	endif
  
177
endfunction
175
endfunction
178
```
176
```
179
  
177
  
180
I am using the CtrlP plugin, so I also use it for displaying the Quickfix List.
178
> **Note**: If any errors are found during the compilation mode the Quickfix
181
But if the plugin is not found; it will default to native quicklist with
179
> list will be populated and opened. You could CtrlP Quickfix for this as well,
182
`:copen`.
180
> I just want to stick to what Vim supports natively.
183
  
181
  
184
Lets check these keybindings.
182
Lets check these keybindings.
185
  
183
  
186
- `Leader+x` - runs the binary in the terminal above and providing environment variables and argument
184
- `Leader+x` - runs the binary in the terminal above and providing environment variables and argument
187
- `Leader+c` - runs make and puts error in Quickfix List then opens with `:copen`
185
- `Leader+c` - runs make and puts error in Quickfix List then opens with `:copen`
188
- `Leader+v` - launches DebugTerm/DBG debugger with all variables and breaks on main
186
- `Leader+m` - launches DebugTerm/DBG debugger with all variables and breaks on main
189
- `Leader+b` - launches DebugTerm/DBG debugger with all variables and breaks on current line
187
- `Leader+l` - launches DebugTerm/DBG debugger with all variables and breaks on current line
190
  
188
  
191
This setup can get even more elaborate. Depending on your needs. This example
189
This setup can get even more elaborate. Depending on your needs. This example
192
works really well for projects using C, but anything goes here.
190
works really well for projects using C, but anything goes here.
...