Question

When I record and paste a macro in vim, I end up with this:

<80>kl - these 3 characters (the <80> is just 1 character) represent <Left>
^[ - represents <Esc>
^M - represents <cr>

This is no good, as when I paste then to try to edit the macro, these characters not as legible.

I just want vim to paste macros using these more legible abbreviations instead of that cryptic nonsense. Alternatively, a function that I can run on a pasted line to do the replacements would work fine.

Was it helpful?

Solution

You could use a simple function like this to substitute each occurrence (on the current line) of ^M, ^[, etc. with their replacements. You can add extra entries to the replacements dictionary as you find you need them.

function! ReplaceWeirdCharacters()
  let replacements = {
    \ "\<C-[>": '<Esc>',
    \ "\<C-M>": '<CR>',
    \ "\u80kb": '<BS>'
    \}
  for [a, b] in items(replacements)
    execute "s/" . a . "/" . b . "/ge"
  endfor
endfunction
nnoremap <leader>rwc :call ReplaceWeirdCharacters()<CR>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top