Saturday, February 25, 2017

Custom Macros that Behave Like 't' and 'f'

Greetings,

I'm working on a plugin that I believe will be helpful to a great many Vim users. Right now, I need a method for developing a macro that is entered and then takes a character to operate on as its final component. This idea is most similar to the way users enter the 't' and 'f' commands in Normal mode.

The closest I've come to this behavior is the following (inspired by reading ":h map-expr"):

nnoremap <expr> \e ':echo "\"' . nr2char(getchar(0)) . '\""' . "\<CR>"
nnoremap <expr> \ee ':echo '"e"'<CR>'

This macro will echo any character that follows '\e' in Normal mode. When you enter '\e', the macro does not patiently wait as with 't' and 'f', it times out like a standard mapping.

If this is not possible, it would make some sense given the way that normal user mappings behave, but I would greatly appreciate a consistent and reasonable "Vim way" to make this work.

Best to all,
Jason

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment