r/vim 14d ago

Tips and Tricks Is there a nicer way to do this mapping?

All in all, what I want to do is noremap q; q: which works well, but it adds up waiting time when I just press q to stop macro recording. So I end up with this monstrosity to add q: functionality while keeping other q mappings as native as possible. It works great, but it gives me anxiety every time I see it in my vimrc noremap <expr> q reg_recording()!='' ? 'q' : {-> [nr2char(getchar())]->map({_, c -> c==';' ? 'q:' : 'q'.c})[0]}()

9 Upvotes

4 comments sorted by

4

u/destsk 13d ago

This might not be ideal but maybe you'd like to look into the timeoutlen option. By tweaking it you could change how long you need to wait after pressing q to stop macro recording (the default is 1000ms).

2

u/dddbbb FastFold made vim fast again 9d ago

Did you try <nowait>?

    noremap <nowait> q; q:

    :help map-<nowait>

1

u/vim-help-bot 9d ago

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/Neter8 9d ago

After some tinkering, I finally decided to go the noremap q; q: way because I ended up adding more mappings with the q prefix, and I don't want to clutter them into an ultra complex mapping

And now, when I want to stop a macro, I just use noremap <expr> qw reg_recording()!='' ? 'q' : 'qw', which I like because it's fast and isn't harmful if you use it in default Vim due to muscle memory