this post was submitted on 07 Jul 2023
13 points (93.3% liked)
Programming
17398 readers
104 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 [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Well, partly.
g/pattern/cmd
will let you select lines where you want to applycmd
. For the use case I present in the post, it solves the problem. But theg
command, has the same limitation as every command invim
: it works on line only. On the other hand, thex
command insam
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 withsam
expressions, you can do:x/\n+/ c/\n\n/
and call it a day :) Another cool feature is that asx
is a command like any other, which applies to any predefined selection. For example, you can do stuff like that: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 invim
(I'm exaggerating the command for the example of course) :