Skip to content

Instantly share code, notes, and snippets.

@mevanlc
Created September 14, 2025 22:54
Show Gist options
  • Save mevanlc/b8be0397e3897c6bc0ced9a1fe1d9e5a to your computer and use it in GitHub Desktop.
Save mevanlc/b8be0397e3897c6bc0ced9a1fe1d9e5a to your computer and use it in GitHub Desktop.
vim TextYankPost debug
function! s:LogTextYankPost() abort
let l:logfile = expand('$HOME/.vimlog')
let l:ts = strftime('%Y-%m-%d %H:%M:%S')
let l:lines = []
call add(l:lines, '==== TextYankPost { ====')
call add(l:lines, 'timestamp: ' . l:ts)
" safe gets with defaults
let l:inclusive = get(v:event, 'inclusive', 0)
call add(l:lines, 'inclusive: ' . (l:inclusive ? '1' : '0'))
call add(l:lines, 'operator: ' . string(get(v:event, 'operator', '')))
call add(l:lines, 'regname: ' . string(get(v:event, 'regname', '')))
call add(l:lines, 'regtype: ' . string(get(v:event, 'regtype', '')))
let l:visual = get(v:event, 'visual', 0)
call add(l:lines, 'visual: ' . (l:visual ? '1' : '0'))
" regcontents is a list of lines (or absent)
call add(l:lines, 'regcontents:')
let l:rc = get(v:event, 'regcontents', [])
if type(l:rc) != type([])
call add(l:lines, '> (not a list) ' . string(l:rc))
elseif empty(l:rc)
call add(l:lines, '> (empty)')
else
for l:ln in l:rc
" normalize embedded newlines for log readability
let l:ln = substitute(l:ln, '\r\?\n', '\\n', 'g')
call add(l:lines, '> ' . l:ln)
endfor
endif
call add(l:lines, '---- } TextYankPost ----')
" try to append; don't let logging break the editor if it fails
try
call writefile(l:lines, l:logfile, 'a')
catch
" fail silently but notify in :messages so user can inspect later
echom 'TextYankPost logger: failed to write to ' . l:logfile
endtry
endfunction
augroup TextYankPostLogger
autocmd!
" call our script-local logger on every TextYankPost event
autocmd TextYankPost * call s:LogTextYankPost()
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment