flit.nvim icon indicating copy to clipboard operation
flit.nvim copied to clipboard

Comma and Semicolon triggers previous character search

Open grezp opened this issue 2 years ago • 5 comments

It would be nice to be able to recall the previously searched character to trigger f/t again. This would exhibit the default n/vim behavior.

Example: press f then a to search for a char press ; to trigger forward search for a char press , to trigger reverse search for a char

grezp avatar Mar 18 '23 19:03 grezp

It's show stopper for me at the moment.

borisbrodski avatar May 12 '23 06:05 borisbrodski

I would also very much like to have this feature in flit. The reason why ; and , do not work as normal when flit remaps f, F, t, and T is that the character to be repeated is never set in the first place - this is the same as pressing ;, or , in (n)vim without flit before searching for a character with fFtT. I've tried to find out if (n)vim enables programmatically setting the last searched character and the last search mode (to or till before/after), just like it's possible to set the last search pattern with let @/ = "pattern" and let v:searchforward. But I haven't found any way how to do it properly. I've experimented a little and added some code to flit.lua that created an autocommand which upon VimEnter created a scratch buffer and every time a flit keybinding fFtT was triggered, I'd switch to that scratch buffer and run :normal! f<char><cr> - with the ! flit's mapping was not be used and the character and search mode were recorded correctly, and could be repeated with ;, and , even in the main buffer. This hack was buggy however, since sometimes the scratch buffer could not be created for some reason and then I'd get a lot of annoying error messages (which probably contained hints on how to solve it but I didn't have the perseverance to figure it out myself. I could probably try to create a pull request and then have my solution improved by somebody more experienced.

jakubbortlik avatar Jul 13 '23 11:07 jakubbortlik

@jakubbortlik The input is saved in flit's state table, which is currently private, so just return that from the module, if you want a less hacky hack: https://github.com/ggandor/flit.nvim/blob/498b3a4864e697f1ed1145e518c4c78c776c55d8/lua/flit.lua#L3

ggandor avatar Jul 13 '23 11:07 ggandor

I've had a closer look on what would have to be done in order to get the requested functionality and I realized it was beyond my capabilities with Lua. I've been able to get a limited "comma-semicolon" repeat to work in the manner I describe above, but it is not the optimal behaviour (it would only trigger the classic one-line repeat, not the enhanced multi-line repeat with highlights and stuff). Then I found flash which has the requested functionality and more so for me this issue is solved :)

jakubbortlik avatar Jul 31 '23 18:07 jakubbortlik

Then I found flash which has the requested functionality and more so for me this issue is solved

Same here, decided to use char mode from flash instead of flit to get back ;/, functionality that is missing here and also due to the annoying behavior described in https://github.com/ggandor/flit.nvim/issues/50.

awerebea avatar May 10 '24 07:05 awerebea