On Structured Regular Expressions and neovim (and vis) ###################################################### :date: 2020-03-03T16:37:39 :category: computer :tags: neovim, regexp, plan9, vis (meant as an extended comment on `neovim’s bug #8457`_: “Support sam/vim Structured Regular Expressions?”) This is not a comprehensive review of vis or even just its comparison with vim. I would like to just describe my small moment of epiphany when working on some document with vis_. There is my large to-do list (actually maintained with VimOutliner_, so that’s another problem) with all my work tasks. There is a couple of bugs which I am fixing with one large submit request. Unfortunately, it was a really huge request (basically rebasing of Python package for old SLE distribution to the latest 2.7.* version), and I haven’t managed to make the submission right on the first attempt. Or even on the second one. Or even … You get the picture. So, I have to update the number of the submit request multiple times. The solution with the regular :code:`vim` (or :code:`neovim`, or any other vi_-like editor) is something I can do in my dreams: .. code:: vim :%s/\(ssr#\)oldnumber/\1newnumber/gc When thinking about this, it surprise how ridiculous this is. I really don’t to “search for the line which contains this particular pattern from it and replace it with this new pattern”. And of course, this is just very simple example, ``substitute`` command can get a way more complicated. When doing the same with :code:`vis` the command was slightly different (and not the only one possible), but it seems to me much more logical: .. code:: vim :x/ssr#oldnumber/ x/\d+/ c/newnumber/ Couple of comments on this. Yes, these all three commands are on one command line just separated with space. Vis, not being kept down by the compatibility with vi uses more normal regular expression engine (libtre_, which implements `POSIX Extended REs`_ with some enhancements like approximate matches). More on the higher level. I have intentionally used this very simple example to show that even in this level it makes more sense to me (more complicated examples_ are available_). “Select broadly what you want, pinpoint on what exactly you want to change, and do it” makes much more sense, than (subconscious) translating my real task into the world of lines and matching them. My suspicion is that with the rising complexity of the task, complexity of the :code:`vim substitute` command rises exponentially, whereas the commands with :code:`vis` rises just linearly. However, I would have to work on this more. .. _`neovim’s bug #8457`: https://github.com/neovim/neovim/issues/8457 .. _vi: https://en.wikipedia.org/wiki/Vi .. _vis: https://github.com/martanne/vis .. _VimOutliner: https://github.com/vimoutliner/vimoutliner .. _libtre: https://github.com/laurikari/tre/ .. _`POSIX Extended REs`: https://www.boost.org/doc/libs/1_72_0/libs/regex/doc/html/boost_regex/syntax/basic_extended.html .. _examples: https://asciinema.org/a/41361 .. _available: https://youtu.be/y41MyOrPt8Q