VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » IT, programs, coding
Command Mode, Ranges and 'g' in Vim DistroTube

Command Mode, Ranges and 'g' in Vim DistroTube

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Command Mode, Ranges and 'g' in Vim DistroTube I'm going to briefly discuss a few things you can do with command mode, ranges, and especially the 'g' command in Vim. 'g' doesn't stand for 'gangsta' but it should!
Date: 2022-03-30

Comments and reviews: 10


I like to use the normal command with the global command. One example I use when I install Arch that many of you will probably find useful is going into /etc/pacman.d/mirrorlist and doing:
:g/## United States/normal VjdGp
That moves all of the mirrors from the US to the bottom of the document so I can just do:
gg6jV/United Stateskd
And now my mirror list is all from the US.
But a nice thing to know is that you can combine it with macros. Basically, you go to a line you would want to affect, start recording a macro only on that line, stop recording the macro, then call the macro in the global command prompt. This is handy when you're doing a complex macro on a ton of lines because just doing the global command can be confusing since you don't visually see what's happening. And making the macro in a way that it does the stuff, goes to the next instance, then redoes it can be extremely slow.
For an extremely simplified example, if you want to put the word -foo- as the second to last word of any line that says -bar- already, you can do:
qw$Bifoo q
:g/bar/normal -w
And if you have a long macro and/or a lot of lines to do it on, it's much faster than recording the same macro except making it go to the next instance as well, and then doing 100-w or something like that.
And finally, if you need to use a special character/key in the global call, like you need to emulate the person pressing the enter button, just press ctrl+v and then the button.

reply

:.write
command is actually pretty useful when you are editing a script and want to test one of the line.
Indeed, you can redirect the output of the write command to the stdin of any other process.
:.write !bash
would execute the particular line you are on and see the ouput from your shell (here I choose bash but obviously could be any shell)

reply

Love this. I have just been getting into VIM and learning new and more useful commands and bam I run into your video showing me even some more to add to my list. Awesome stuff. btw - VIFM is another great command line file browser (like ranger) related to VI so maybe you could talk more on that too.
reply

Can anybody help me where to find a list of command like -t- in g/import/t$ -takes- and -m- for move in vim? since i cannot locate them on any available cheatsheet online and need to specifically look fort them in :help. P.S: i originally the t /m are only meant for findiing Till and Mark till today lol
reply

Hey DT, have you heard of Kakoune? I learned about it in the comments of one of your videos. It-s reminiscent of Vim but tries to stick to the Unix philosophy better. In particular, it gives visual feedback to commands and relies heavily on what it calls -selections-.
Great video, as always!

reply

when using mode() to display in my StatusLine, why does it never show 'c' for COMMAND, it remains as NORMAL and the mode() function does not return 'c'. For insert mode it changes to 'I' but never changes to 'c' when entering into COMMAND like yours does. Am I missing something?
reply

Thanks for a very informative video, Derek! This helps to nudge my vim-fu ahead another baby step. Once thing I discovered on my own was doing a Visual or Visual Line and hitting colon, which puts the selected range on the command line, ready for a substitution, etc. Cheers.
reply

Interesting... In most cases I find it easier to mark ranges with visual line mode. You can then type a colon which brings you into command mode with your range already specified, and you can add what ever you want, like substitutions, write to a new file, and so on
reply

Hey, Can you please make a video about how we can have follow-mode in Emacs inside vim/nvim? There are some tutorials about :set cursorbind and :set scrollbind in vim, but they don't do the follow-mode job. thank you!
reply

...and I thought I knew enough but this is superb, thanks :D
I wrote this too fast.. holy crap what you can do in there!!
Can I move to your place for like 3-5 months or so for some real cram of Linux :P

reply
Add a review, comment






Other channel videos