vim-caser
vim-caser copied to clipboard
Feature request: Support act-on-whole-line mappings
Great plugin! One thing that would be cool to have is if the functions could know to apply themselves to the entire current line if the last character of the mapping is supplied twice, as is the case in many plugins (such as vim-commentary).
E.g.: gstt would expand to 0gst$, gs.. to 0gs.$, etc.
Actually I think the more paradigmic mapping for these would be gsst, gss., etc. That's how vim-surround does it with yss, anyway.
The first version had this behavior (the one you described in the post itself).
The problem with that is that things like gstt would be confusing (or delayed by Vim), because gsttt is "go case title until t". Also things like gsst could mean "go case snake until …", meaning an unfinished motion.
I thought of having mappings like in Atom's vim-mode-plus, though they would suffer from the same issues: gtt and gttt (go title until t) would clash.
I also removed this feature because I'm not sure if it would be of much use (changing the case of a whole line of code doesn't seem to me a very frequent action). I understand, however, that it's kind of bad to not have this.
I'd like to discuss possibilities, alternatives and possible drawbacks before trying to implement such a feature.
Good point. One approach would be to straight up copy the mapping prefix used by Abolish: cr. There wouldn't be any problem with commands like crrt or crrp would there?
I believe not until a case using r is implemented (highly unlikely, though). A better solution could be implementing this functionality as an option (g:allow_line_commands, maybe?) for any chosen prefix (via g:caser_prefix [default: gs]).
Maybe it's better to have a custom textobject for line:
xno il g_o^
ono il :normal vil<cr>
xno al $o0
ono al :normal val<cr>
Then one can simply do gstil instead of proposed tstt.
@arthurxavierx I think you misunderstand me. I'm saying that the default g:case_prefix could be switched to cr, as Abolish has for "coerce": crs = coerce snake case,
Either way, I realized that that isn't even necessary, since the solution would be to repeat the second letter of the mapping, not the third: gsst for title-case line, rather than gstt. What do you think?
@fictionic, yes, I understood that. The problem I see with this is that it's confusing, as gsst could be understood by the user (and by Vim) as "go case snake untill …", that is, an unfinished command. This ambiguity can't be solved, only if the g:case_prefix were cr or any other combination that wouldn't clash. What I meant as a solution is to allow these line commands as an option, and not by default, as it could cause unexpected behavior to other commands depending on the choice of g:case_prefix.
@sudo-nice, that could be a good solution, though defining a text object for a line shouldn't be the responsibility of this plugin, as it could override users' mappings.
@arthurxavierx Ok I see the problem. I'm ok with just implementing the mappings myself (with cr as the custom prefix).
As @sudo-nice has pointed, I also think it is better to simply use a line text object. The whole point of using operators is to benefit from text objects, I really don't like the yy dd etc mappings. I prefer to use a "in line", or, "a line" text object, it's just one more keystroke, but it's much better aligned with the whole idea and the way we think. So we can simply do: cr_il (coerce _ in line). It works fine for me, there are line objects already available.
I also preffer the 'cr' prefix. Anyhow, good job with the plugin!