Advertisement
roachsinai

vimspector.vim

Apr 19th, 2022
3,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 4.63 KB | None | 0 0
  1. " vimspector
  2. let g:vimspector_enable_mappings = ''
  3. packadd! vimspector
  4. nmap <F5>         <Plug>VimspectorContinue
  5. nmap <F9>         <Plug>VimspectorToggleBreakpoint
  6. nmap <S-F9>       <Plug>VimspectorAddFunctionBreakpoint
  7. " all input should be surrounded by quotes
  8. nmap <leader><F9> :<c-u>call vimspector#ToggleBreakpoint(
  9.       \ { 'condition': input( 'Enter condition expression: ' ),
  10.       \   'hitCondition': input( 'Enter hit count expression: ' ) }
  11.       \ )<CR>
  12.  
  13. sign define vimspectorBP text==>         texthl=WarningMsg
  14. sign define vimspectorBPCond text=?>     texthl=WarningMsg
  15. sign define vimspectorBPDisabled text=x> texthl=LineNr
  16. sign define vimspectorPC text=->         texthl=MatchParen
  17. sign define vimspectorPCBP text==»        texthl=MatchParen
  18.  
  19. let g:vimspector_sign_priority = {
  20.   \    'vimspectorBP':         33,
  21.   \    'vimspectorBPCond':     32,
  22.   \    'vimspectorBPDisabled': 31,
  23.   \    'vimspectorPC':         999,
  24.   \    'vimspectorPCBP':       999,
  25.   \ }
  26.  
  27. let g:vimspector_sidebar_width = 75
  28.  
  29. let g:vimspector_mappings = {
  30.       \   'stack_trace': {},
  31.       \   'variables': {
  32.       \    'set_value': [ '<Tab>', '<C-CR>', '<leader><CR>', 'C' ],
  33.       \   }
  34.       \ }
  35.  
  36. let g:vimspector_runtime_mappings = {}
  37. function! SpectorOnJumpToFrame() abort
  38.   if has_key( g:vimspector_runtime_mappings, string( bufnr() ) )
  39.     return
  40.   endif
  41.  
  42.   " nmap <silent> <buffer> <leader>dn <Plug>VimspectorStepOver
  43.   " nmap <silent> <buffer> <leader>ds <Plug>VimspectorStepInto
  44.   " nmap <silent> <buffer> <leader>df <Plug>VimspectorStepOut
  45.   " nmap <silent> <buffer> <leader>dc <Plug>VimspectorContinue
  46.   nmap <silent> <buffer> <leader>di <Plug>VimspectorBalloonEval
  47.   xmap <silent> <buffer> <leader>di <Plug>VimspectorBalloonEval
  48.  
  49.   nmap <silent> <S-F5>       <Plug>VimspectorStop
  50.   nmap <silent> <C-S-F5>     <Plug>VimspectorRestart
  51.   nmap <silent> <F6>         <Plug>VimspectorPause
  52.   nmap <silent> <F10>        <Plug>VimspectorStepOver
  53.   " windows terminal F11 is mapped for full screen
  54.   " so you should disable it in windows terminal setting
  55.   nmap <silent> <F11>        <Plug>VimspectorStepInto
  56.   nmap <silent> <S-F11>      <Plug>VimspectorStepOut
  57.   nmap <silent> <F8>         :VimspectorReset<CR>
  58.  
  59.   let g:vimspector_runtime_mappings[ string( bufnr() ) ] = { 'modifiable': &modifiable }
  60.  
  61.   setlocal nomodifiable
  62.  
  63.   " if enable shoosewin overlay will cause bug when first time
  64.   " run :execute "normal \<Plug>(choosewin)"
  65.   " more details about <Plug> https://stackoverflow.com/a/18547013/6074780
  66.   let g:choosewin_overlay_enable = 0
  67. endfunction
  68.  
  69. function! SpectorOnDebugEnd() abort
  70.  
  71.   let original_buf = bufnr()
  72.   let hidden = &hidden
  73.  
  74.   try
  75.     set hidden
  76.     for bufnr in keys( g:vimspector_runtime_mappings )
  77.       try
  78.         execute 'noautocmd buffer' bufnr
  79.         " silent! nunmap <buffer> <leader>dn
  80.         " silent! nunmap <buffer> <leader>ds
  81.         " silent! nunmap <buffer> <leader>df
  82.         " silent! nunmap <buffer> <leader>dc
  83.         silent! nunmap <buffer> <leader>di
  84.         silent! xunmap <buffer> <leader>di
  85.  
  86.         silent! nunmap <S-F5>
  87.         silent! nunmap <C-S-F5>
  88.         silent! nunmap <F6>
  89.         silent! nunmap <F10>
  90.         silent! nunmap <F11>
  91.         silent! nunmap <S-F11>
  92.         silent! nunmap <F8>
  93.  
  94.         let &l:modifiable = g:vimspector_runtime_mappings[ bufnr ][ 'modifiable' ]
  95.  
  96.         let g:choosewin_overlay_enable = 1
  97.       endtry
  98.     endfor
  99.   finally
  100.     execute 'noautocmd buffer' original_buf
  101.     let &hidden = hidden
  102.   endtry
  103.  
  104.   let g:vimspector_runtime_mappings = {}
  105. endfunction
  106.  
  107. augroup TestCustomMappings
  108.   au!
  109.   autocmd User VimspectorJumpedToFrame call SpectorOnJumpToFrame()
  110.   autocmd User VimspectorDebugEnded call SpectorOnDebugEnd()
  111. augroup END
  112.  
  113. function! s:CustomiseWinBar()
  114.     call win_gotoid( g:vimspector_session_windows.code)
  115.     aunmenu WinBar
  116.     nnoremenu WinBar.▷\ ᶠ⁵ :call vimspector#Continue()<CR>
  117.     nnoremenu WinBar.↷\ ᶠ¹⁰ :call vimspector#StepOver()<CR>
  118.     nnoremenu WinBar.↓\ ᶠ¹¹ :call vimspector#StepInto()<CR>
  119.     nnoremenu WinBar.↑\ ˢᶠ¹¹ :call vimspector#StepOut()<CR>
  120.     nnoremenu WinBar.❘❘\ ᶠ⁶ :call vimspector#Pause()<CR>
  121.     nnoremenu WinBar.□\ ˢᶠ⁵ :call vimspector#Stop()<CR>
  122.     nnoremenu WinBar.⟲\ ᶜˢᶠ⁵ :call vimspector#Restart()<CR>
  123.     nnoremenu WinBar.✕\ ᶠ⁸ :call vimspector#Reset()<CR>
  124. endfunction
  125.  
  126. augroup MyVimspectorUICustomistaion
  127.     autocmd!
  128.     " autocmd User VimspectorUICreated call s:CustomiseUI()
  129.     " autocmd User VimspectorTerminalOpened call s:SetUpTerminal()
  130.     autocmd User VimspectorUICreated call s:CustomiseWinBar()
  131. augroup END
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement