"=" as a command synonym for "textfilter "
Description
Make "=" (without a space) be a synonym for "textfilter " (with a trailing space) in the command entry box.
Benefits
- Reduce typing a very command command (for me). "textfilter" is really powerful, and I use it a lot.
- Avoid a shift sequence (by using "=" rather than "!" as vi does). [This is a keyboard specific consideration, as pointed out in comments below. It would work well for US keyboards, but is (unfortunately) not universal.]
Although no character is likely to be "guaranteed" to work unmodified across keyboards, "." or "," or ";" may be more likely candidates, and any such would be fine.
Example
Current
ctrl-e textfilter right 70 s Right Aligned Header
Proposed
ctrl-e =right 70 s Right Aligned Header
(The intent is that this is a synonym, so "textfilter " would still work.)
For the curious, this does the following...
Right align text, based on a width of 70, use a space (s) to do the alignment, and the text to align is "Right Aligned Header"
Environment
- OS: Anywhere micro runs
General Comments
I use these types of textfilters (typically written in Perl, sometimes in Lua, Python, Bash, or Ruby) to format text for text documents, or do other functions, sometimes within code.
"textfilter" is as powerful as you want to make it.
Note, I'm using Micro 2.0.10. And if no text is marked (or perhaps since the "filter" doesn't read anything, or both), it just inserts the string, which is GOOD (please don't change this behavior!) I also have filters that reflow text, which is the more typical/intended use of "TEXTFILTER". That would look something like "=flow 70" under my proposal, with text marked! Please note that this is not a request for a specific filter, I have many of them already. I just want to make them take a bit less typing to access.
I considered "!" from vi[m], but I don't see any real convention in other editors for how this is done, and "=" wouldn't required a shift.
I've been using Micro for over a year (maybe more), I think, and it is now my favorite editor. The above, however, is a frequent "paper cut" for me.
Whether this is accepted/implemented or not, thanks for a great editor!
Whether "built in" or done with a plug-in is irrelevant to me, although I couldn't quite see (from various examples) how to do the above with a plug-in (though I suspect is is possible, and I'm just missing something). I think it would be a good feature built in, but it certainly doesn't have to be implemented that way.
The "without a space" would need to be special cased in the command parsing system so I'm not sure about that, but I agree that textfilter is needlessly long for such a common operation and it should have a shorter alias built-in. There are fortunately multiple pretty good workarounds to make textfilter command easier to access:
- Add a keybinding that prefills the "textfilter " part (
"Alt-z": "command-edit:textfilter ") - (in a plugin) Register a new command with a shorter name of your choosing
- (in a plugin) Use
micro.InfoBar():Promptto create a custom prompt
"=" wouldn't require a shift
You shouldn't make assumptions about which characters require a modifier key because people use all kinds of different keyboard layouts. On my (Nordic) keyboard layout = is Shift+0.
Thank you for your comments, and for correcting me on the modifier key issue. My apologies for being myopic. Although I'd very much like to see this happen, I'll give the first option a try. I'm not good with plugins yet. I need more examples of different things. If I were a bit more fluent with writing plug-ins, I'd give the second and third options a try. But I'm not up to that at present.
Again, many thanks!
I need more examples of different things. If I were a bit more fluent with writing plug-ins, I'd give the second and third options a try.
Here's an example of the third option from my dotfiles: ~/.config/micro/init.lua#L75-L86
It creates a pipemode command which I then bind to Ctrl-p. I prefer this approach because
- The custom prompt has its own history, separate from the regular prompt (Ctrl-e)
- I made it always run the command with
sh -cso I can use environment variables and other things that are expanded by the shell (like$HOMEand~).
I'm looking through the code and a bit overwhelmed - and spending too much time on this during my work day (meaning I'll need to look at this later).
But I think a separate prompt is likely to be the better implementation anyway, specifically with your point of having a separate history.
- Add a keybinding that prefills the "textfilter " part (
"Alt-z": "command-edit:textfilter ")
This is micro's standard way of doing things. Why not just use it? And, pressing a single key combo is faster than pressing Ctrl-e (or whatever) and then =, right?
As for this concern:
But I think a separate prompt is likely to be the better implementation anyway, specifically with your point of having a separate history.
You can bind up and down keys in the command mode to HistorySearchDown and HistorySearchUp (like I do, for example):
"command": {
"Down": "HistorySearchDown",
"Up": "HistorySearchUp"
}
which, unlike the default actions HistoryUp and HistoryDown, search the history for only those commands that start with the text before the cursor. So, then, when you press Ctrl-z and it opens the command prompt pre-filled with textfilter , and you press the up key, it will only search through previous textfilter commands, not through all previous commands.
but I agree that
textfilteris needlessly long for such a common operation and it should have a shorter alias built-in.
If at all, textfilter should not be a special case. We could implement, for example, the same thing that vim does: for any command, allow using an arbitrarily short prefix instead of the whole command name, as long as it is unambiguous. So you could use just te instead of textfilter, since there is no other command starting with te.