Elektrine lite

← Feed

@simontatham@hachyderm.io

Post #1848097

2026-05-01 13:50 UTC

A thing I've only just realised about #less: When you press '/' to search forward, or '?' to search backward, and enter a regex, two changes of state occur: 1. The regex is remembered, so that 'n' or 'N' will search for the same thing again. 2. The direction is remembered, so that 'n' searches in the same direction again, and 'N' searches in the opposite direction. I've only just noticed that #2 happens at the instant of pressing / or ?, not at the instant of pressing Return. Because it takes effect even if you change your mind and cancel the attempt to input a new search regex: • enter "?foo", which searches backward for /foo/ • press 'n', which searches backward for /foo/ again • press '/', which prompts for a forward-search string • press Backspace, which cancels that prompt • now pressing 'n' searches *forward* for /foo/ I think this must be why I sometimes get confused about which direction I'm searching in. But also, wow, it's taken me _decades_ to notice. I think it must be because when I start and then cancel a prompt like that, I don't consciously remember doing it at all – I expected so strongly that it would be a no-op that I forget it immediately!

Replies (7)

  • @drj@typo.social 2026-05-02 07:55

    @wordshaper@weatherishappening.network @simontatham@hachyderm.io now you know 25% of vi the editor. And if you use j and k to go up and down, that's another 12.5% shared with vi.

    Open ##3197825

  • @jyrgenn@mas.to 2026-05-04 10:42

    @wordshaper@weatherishappening.network @simontatham@hachyderm.io I knew that, but not that 'N' reverses the search direction. Could have used that many times. Thanks!

    Open ##3197826

  • @simontatham@hachyderm.io @barubary@infosec.exchange Instead of using n/N, you can also just hit / or ? again with no pattern to repeat the previous search. I believe this is the reason for the behavior you’ve discovered.

    Open ##3197827

  • @thaodan@mastodon.social 2026-05-01 14:08

    @simontatham@hachyderm.io Less is essentially vim but stuck in view mode.

    Open ##3197830

  • @praxiscode@mastodon.online 2026-05-01 14:15

    Are you aware of the & command in less? It's like applying a grep to the file, after which you can also perform /? searches @simontatham@hachyderm.io

    Open ##3197832

  • @leeloo@c.im 2026-05-01 14:28

    @simontatham@hachyderm.io Glad I didn't know about ?. I always use / followed by N. To be honest, I don't think I would have used it even if I knew. N searching forward and n backwards seems like a case of "if not not not" in my mind.

    Open ##3197838

  • @minego@pdx.social 2026-05-01 16:42

    @simontatham@hachyderm.io Weird... I am not able to reproduce this behavior. Are there multiple implementations of less out there? I also didn't realize that you could cancel a search with backspace. Somehow it never occurred to me to try that.

    Open ##3197841