diff options
| 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) | |
| tree | 06245dd48a5faadb0c9babeca893ba3f696785e9 /content/posts/2026-01-09-vim.md | |
| parent | 136f5795c113d794ce1307c84190744d4137043b (diff) | |
| download | mitjafelicijan.com-ef81d6388dfc3e5cc93b39874f69b7903c15b0e1.tar.gz | |
Update post: Integrated debugging in Vim
Diffstat (limited to 'content/posts/2026-01-09-vim.md')
| -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 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 | |||
| 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,8 +159,11 @@ function! LocalDebugLine() abort | |||
| 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,25 +171,20 @@ function! LocalMake() abort | |||
| 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. |
