0

By default, termdebug has K mapped to :Evaluate.

I want to extend the mappings in the following way:

CC mapped to :Continue
B mapped to :Break
C mapped to :Clear

Such mappings shall apply only during a termdebug session. Once the termdebug session ends, I want to restore the original mappings for C, B and D (if any).

How to achieve that?

2
  • 1
    There are two questions, here. The part about breakpoints should be split.
    – romainl
    Commented May 6 at 14:52
  • Right. Edited and opened a new question.
    – Barzi2001
    Commented May 6 at 15:01

1 Answer 1

1

$VIMRUNTIME/pack/dist/opt/termdebug/plugin/termdebug.vim doesn't seem to set a global variable or something that could be used in a conditional to decide if we are in a debugging session or not.

But the plugin triggers some User autocommands at various points of its lifecycle, which can be used to set up and tear down your own TermDebug-specific stuff:

function! SetUpTermDebugOverrides()
    nnoremap CC <Cmd>Continue<CR>
    nnoremap B <Cmd>Break<CR>
    nnoremap C <Cmd>Clear<CR>
endfunction

function! TearDownTermDebugOverrides()
    nunmap CC
    nunmap B
    nunmap C
endfunction

augroup MyTermDebugOverrides
    autocmd!
    autocmd User TermdebugStartPost call SetUpTermDebugOverrides()
    autocmd User TermdebugStopPost  call TearDownTermDebugOverrides()
augroup END

See :help termdebug-events.

The above assumes that there is no prior mapping to CC, B, and C, or that you don't care about restoring them. If you need to back up and restore existing mappings, then you will have to do that in the two functions: backup in SetUpTermDebugOverrides() and restore in TearDownTermDebugOverrides().

See :help maparg().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.