2

I have @@ mapped to Space. This can be really convenient.

Sometimes I want to combine a macro with another. So maybe I need to record q as @:/jump to run my last regex substitution and move to the next place I probably want to run it. Then @q and press Space until I'm happy.

Unfortunately if you run @q, during the macro the @@ repeat will be set to @:. Is there a way to run @: without setting it to @@ while recording the macro for q?

In this toy example, instead of combining macros I could copy the substitution into a register and paste it during the q recording, but that requires more foresight, and a bit of fiddling.

Edit:

I guess as far as combining @: goes, I can always use :%s/\v//gc... There are situations I've wanted to combine macros that have nothing to do with regex though. Only option I can think of so far to do what I want is remap Space to always be @q, instead of the last macro, which might be okay since that's 80% of the time what I mean.

2 Answers 2

3

Is there a way to run @: without setting it to @@ while recording the macro for q?

Yes:

For normal 'character' registers:

:call feedkeys(@a)


": needs special handling:

:call feedkeys(':' . @: . "\<CR>")


If you use this often, you may want to map it:

" for @:
:noremap @- :<C-u>call feedkeys(':' . @: . "<Bslash><lt>CR>")<CR>

" for normal char registers
:noremap @_ :<C-u>call feedkeys(@)<Left>

" more complex version of the latter, improved to not need a final <CR>
noremap @_ :<C-u>call FeedReg()<CR>
function! FeedReg()
  echo 'Enter register name character:'
  let reg=nr2char(getchar())
  call feedkeys(getreg(reg))
endfunction
1
  • A cookie for the right answer. Although before I read this, I realised that I have a keyboard with programmable layers, and have greedily made one of the layers my macro layer, where every letter is mapped to @ and the letter. For me being on that layer and hitting asd or whatever is as and perhaps more convenient. I like your @- @_ though, that's a nice extension to existing finger memory.
    – Wumbo
    Dec 22, 2016 at 17:00
5

Is there a way to run @: without setting it to @@ while recording the macro for q?

Yes:

:<C-p><CR>

(or equivalently

:<Up><CR>

.)

0

Your Answer

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

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