this post was submitted on 07 Jul 2023
10 points (100.0% liked)

Programming

423 readers
2 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

TL;DR: I use a vim like editor which tackles Vim's greatest weakness: vis.

top 6 comments
sorted by: hot top controversial new old
[–] noeontheend 4 points 1 year ago (1 children)

This is interesting—I hadn't heard of vis or Sam. Thanks for sharing!

I will say that I like to think of myself as a reasonably advanced Vim user, and the substitution commands used for the example wouldn't have even occurred to me for changes 1 and 2. I would have automatically done it the alternative ways listed. I'm pretty sure those would be faster to type too (they're fewer keystrokes). Is it really true for most people that "the substitute command is used 90% of the time when using commands"?

[–] wgs@lemmy.sdf.org 3 points 1 year ago* (last edited 1 year ago) (1 children)

I guess my point was not really clear then. I wanted to point out that vim's "command" mode is not optimal because when you use it, you'll use the substitute command 90% of the time. This might be more visible if you compare sam to ed or sed, which are not visual editors.

Of course vim's normal mode is better for the changes I listed, but I wanted to make a point about sam's commands being more powerful than vim's commands.

This is the whole point of this post: using vim with sam's command mode makes it a better editor !

[–] noeontheend 1 points 1 year ago

Thanks! I think we just have very different ways of using Vim, which is fine! I personally hardly ever use the substitute command beyond the occasional find and replace to change a variable name. Perhaps my main takeaway ought to be that I should look for more chances to use it--there's always more power to unlock :)

[–] Kache@lemmy.one 1 points 1 year ago* (last edited 1 year ago) (1 children)
[–] wgs@lemmy.sdf.org 2 points 1 year ago* (last edited 1 year ago)

Well, partly. g/pattern/cmd will let you select lines where you want to apply cmd. For the use case I present in the post, it solves the problem. But the g command, has the same limitation as every command in vim: it works on line only. On the other hand, the x command in sam applies to the whole text. It doesn't matter whether or not you have new lines in the pattern.

Imagine that you have a text file, and you want to make sure that all paragraphs are separated by only one blank new line. I cannot think of a way of doing it easily in vim, while with sam expressions, you can do: x/\n+/ c/\n\n/ and call it a day :) Another cool feature is that as x is a command like any other, which applies to any predefined selection. For example, you can do stuff like that:

Emacs is considered an advanced editor.
And while Vim users tend to swear on Emacs.
Emacs users are still convinced that Emacs rules!

x/Emacs rules/ x/Emacs/ c/Sam/

This will first extract "Emacs rules" from the whole text, then extract "Emacs" from it, then change it to "Sam". This means that you can narrow down the parts of the text that your commands will apply to portions of the line. The g command here would simply select the last line for you, but then you'd have to be very careful not to substitute the first occurrence of "Emacs", leading to the following in vim (I'm exaggerating the command for the example of course) :

g/Emacs rules/s/Emacs rules/Sam rules/
[–] ollien 1 points 1 year ago

In case anyone, like me, was wondering what "structural regular expressions" are, here's a write-up Rob Pike did in his Bell Labs days

http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf

load more comments
view more: next ›