viernes, 13 de mayo de 2016

Asymmetry on searching

Recently I started using helm-occur as a default for c-s. It has some nice things like searching for the word at point, which many times is what you want to do [1].  But it also has its drawbacks.

  • One of them is speed. For big buffers it can be quite slow [2].  
  • Also,when there's more than one match in a line, you can't easily keep pressing c-s and move along the matches.
  • If the matches far in long lines, you don't see them. Can't decide where to stop when lines are similar at start.
  • It doesn't work as a navigation tool [3].

Try to open a giant xml file (all in one line), and work with it. You'll understand it.

But! it's not all lost yet. I found out that if I keep c-r as isearch-backward, I can then press c-s and be in the good old isearch. So you get both functionalities, and the keybindings are not confusing. you just have to remember that sometimes, the fastest way to move forward is to go backwards.

[1]. that same functionality can be done with '*' in evil (but you'll have to configure syntax tables to make it match the whole word instead of symbol). Also, pressing c-w on isearch-mode will add next word to the searched content.

[2]. Some say ivy is faster, but the times I tried m-x ivy-mode, it takes over the whole emacs input system. Probably I should invest more time on learning how to activate it just for buffer searches.

[3]. And I don't buy the yak shaving 'you should use ace-jump', because its aim is not the same (doesn't work to move where you WANT but don't SEE), and now I have 2 problems.

3 comentarios:

David Barrutia dijo...

I use helm for many things, but it feels too slow to replace fast-paced commands like C-s, even on small files (helm itself doesn't feel snappy enough)

Have you tried swiper instead? It's faster than helm-occur and IIRC the author himself uses it as a C-s replacement.
As for me I kept C-s after trying it out for a while.

Tassilo Horn dijo...

You are looking for M-x swiper or M-x counsel-grep-or-swiper. Both use ivy internally without requiring it to be enabled globally. And the latter will automatically fallback to grep in super-sized buffers where a pure elisp implementation like swiper or helm would have problems. Try it out! The packages are named swiper and counsel and are both available from MELPA.

Raimon Grau dijo...

Thanks for the suggestions. I'll give swiper a try. Still, I think this solves only the first point of the 4 in the list, but hey!, it's something already :)