I've written a short vim function that allows me to edit the contents of vim registers:

fun! RegBuff()
    let vimstuff = "/tmp/vimstuff"
    if !isdirectory(vimstuff)
        call mkdir(vimstuff)
    let reg = getchar()
    let reg = nr2char(reg)
    exec 'au BufWrite vimreg-* exec "normal gg0\"'.reg.'yy"'
    exec '1new '.vimstuff.'/vimreg-'.reg
    exec 'normal ggdG"'.reg.'P'
nnoremap <leader><F2> :call RegBuff()<CR>

If I do, for instance, qqi1234^[ to record insert 1234 into the q register, and then call my function :call RegBuff() or <leader><F2>, I get a nice little window at the top with the contents of the buffer. Cool. if I edit it to be i12345678^[, save the file and exit, and then do @q, it properly now enters insert mode and inserts 12345678. Also cool.

The problem is that I generally run vim in tmux, and for some reason after executing this macro it switches to the tmux pane below vim. This is as if the macro is additionally running <Ctrl>j after the macro is run.

If I go back to the vim pane, and type "qp to see whats in the q register it looks totally normal, it just contains what I expect to be in there.

Why does there appear to be this extra key code sent after I call the macro?

  • Are you writing the buffer? It might be, that when writing the buffer, Vim writes an additional EOL. Try setting 'nofixendofline' – Christian Brabandt Jul 7 '17 at 15:02
  • Thanks for the help Christian. I am writing the buffer, which triggers the BufWrite autocommand that copies the first line of the buffer back into the register. Neither putting set nofixendofline in the function or setting it manually doesn't change the behavior. – Brian Albert Monroe Jul 7 '17 at 15:07
  • Note that you can call :echomsg @q to see what is in register q, including special characters. – piojo Feb 15 '19 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.