Command Mode, Ranges and 'g' in Vim

Поділитися
Вставка
  • Опубліковано 29 сер 2024

КОМЕНТАРІ • 101

  • @klimenkodr123
    @klimenkodr123 4 роки тому +136

    I like how there are youtubers that are suffering from "creativity crisis" running out of ideas for new videos, and then there are linux youtubers getting infinite inspiration from manuals.
    10/10 content

    • @FreeMan-wz3hj
      @FreeMan-wz3hj 4 роки тому +10

      It's more of an unmined resource, like gold on the moon.

  • @primalpenguin
    @primalpenguin 4 роки тому +94

    Well that thumbnail just gave me a new idea on how to spell out vim when they ask me if I prefer vim or emacs

    • @fuseteam
      @fuseteam 4 роки тому

      lol, looks like 6 4 14 to me :p

    • @jameshall5556
      @jameshall5556 4 роки тому

      @ I mean. You could always summon the demons of azerath.

    • @finndriver1063
      @finndriver1063 4 роки тому +1

      Pretty sure there's an Emacs package for doing that, actually

    • @sukhmandersingh4306
      @sukhmandersingh4306 Рік тому

      @ you can just use your...

  • @engageintellect
    @engageintellect 4 роки тому +40

    This thumbnail is the greatest thing I’ve ever seen. DT is the best Linux channel on UA-cam, period. These videos are well scripted and easy to follow. I have learned more from DT than any other single source.
    Thank you for the great content.

    • @bobbob2658
      @bobbob2658 4 роки тому +3

      I dont think he scripts his vids

  • @stevem3432
    @stevem3432 4 роки тому +26

    "Who you with fool? What hood you from?" *Throws up every possible gang sign simultaneously

  • @KodyVonBargen
    @KodyVonBargen 4 роки тому +11

    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.

  • @AtomToast
    @AtomToast 4 роки тому +11

    One of the most powerful global command applications in my opinion is in combination with the `normal` command. It lets you execute a sequence of keypresses as if they were typed from normal mode.
    This way you can have something like :g/^\s*int/normal ^cwlong to replace every line starting with int to start with long instead. Just something I came up with in the moment but the possibilities are endless. You can kind of think of it as a multiple cursor implementation of sublime text in vim.

    • @gurdeepgss
      @gurdeepgss 4 роки тому +1

      You would use substitute for this case

    • @vlmath314
      @vlmath314 4 роки тому

      Or apply a macro with :g/patter/normal @q

  • @ninimouss
    @ninimouss 4 роки тому +10

    :.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)

  • @davidh.4944
    @davidh.4944 Місяць тому

    An interesting addition to the :g command not mentioned is that it can also take a range itself, limiting its "global" scope to whatever section of the file you want.
    So to reverse only lines 10-20 in your file:
    :10,20g/^/ m9
    Note that you move the matched lines to one above the point you want the insertion to start at.
    You can also nest multiple global commands.
    One slightly tricky gotcha with :g is that it always needs to include a match string. This means that to use :s with it instead of %, you would need:
    g/^/ s/foo/bar/
    Combine all the multiple ranges and matches available and you can target quite complex and powerful selections.

  • @antonioquintero-felizzola5334
    @antonioquintero-felizzola5334 4 роки тому +6

    Dude, I have no doubt you run the best Linux channel on UA-cam.

  • @threee1298
    @threee1298 Рік тому

    This is so valuable to me, it sticks in my brain so much better when someone’s explaining it conversationally

  • @RAndrewNeal
    @RAndrewNeal Рік тому +1

    "Once you discover Vim, it's a way of life. I could never use another text editor." - Doom Emacs User

  • @rounakjain5774
    @rounakjain5774 2 роки тому

    I knew about running shell commands with :! and I knew about using :read command to paste file contents. But I didn't think of using :read ! to paste the shell output. Very useful!

  • @andrewpalm2103
    @andrewpalm2103 4 роки тому +1

    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.

  • @pavelsapehin4308
    @pavelsapehin4308 3 роки тому +1

    00:36 command mode intro
    00:58 run shell commands from vim
    01:37 read a shell command's output and put it to the current line, e.g. :read !date
    02:41 :$read !date

  • @darthcabs
    @darthcabs 4 роки тому +1

    Never seen the power of vim so well showcased anywhere before like in this video. Excellent job, dt!

  • @simonslater7257
    @simonslater7257 4 роки тому +1

    Wow, this was a really good vim tutorial! Most of the things you showed had real practical uses, which is great, because I can already imagine myself using them.

  • @CairosNaobum
    @CairosNaobum 4 роки тому +1

    Came here for the featured pic. NOt disappointed !
    You a very talented bald bro .

  • @okdoomer620
    @okdoomer620 4 роки тому +1

    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

  • @ChadsHobies
    @ChadsHobies 4 роки тому +1

    Excellent job with separating your brand from the static. I love the video and the thumbnail.

  • @raccoons_stole_my_account
    @raccoons_stole_my_account 7 місяців тому

    Very useful video, thanks DT!

  • @6w817
    @6w817 4 роки тому +1

    Thumbnails for the past few vids have been absolute fire

  • @natas8256
    @natas8256 4 роки тому +4

    thumbnail had me rollin!

  • @RichardBronosky
    @RichardBronosky 3 роки тому

    6:20 That was new info to me. Thank you! (I've been using vim since 1995.)

  • @quisge
    @quisge 3 роки тому

    Uh... this video blew my mind. So much great stuff I did not know about!

  • @johnathantorres6396
    @johnathantorres6396 2 роки тому

    Quick note about the :s/(pattern)/
    Command the (pattern) is a regular expression which is a whole other beast

  • @windowsrefund
    @windowsrefund Рік тому

    Very nice job. Interesting topic!

  • @_jdfx
    @_jdfx 3 роки тому +1

    another amazing video! thanks DT!
    btw I use xmonad!

  • @kevinwood5048
    @kevinwood5048 4 роки тому

    Nice! Always fun to learn new vim commands. Only thing missing was the confirmation option for global search and replace.

  • @angryfish404
    @angryfish404 4 роки тому +1

    Thank you! Helped me understand command mode better \o/

  • @ThrivingInLife
    @ThrivingInLife 2 роки тому

    Very Helpfull!

  • @kylemanley915
    @kylemanley915 4 роки тому +1

    This is so whack today I used the
    :%s /pattern/replace/g command today in some C++ programming and I googled "What does g command do in vim" and it all didn't make sense to me, your video shows me not only what g does but also what % does and so much more. Funny how sometimes you don't even got to search for what you were trying to figure out earlier and it pops in your reccomended when you are subbed to some good channels. 🙌

  • @edonan85
    @edonan85 4 місяці тому

    9:16 I find using :%s/^/
    to insert a blank line before each line easier than your g command

  • @davidgomez79
    @davidgomez79 4 роки тому +2

    That last trick straight up G. 🤣

  • @Mega_Casual
    @Mega_Casual 4 роки тому +4

    Gettin' all gangsta' here in da' dtube bruh!

  • @Jeff_Seely
    @Jeff_Seely Рік тому

    I have never enjoyed receiving the fanger so much🤣

  • @lawi1390
    @lawi1390 4 роки тому +2

    200IQ thumbnail sir

  • @karimdelamora1064
    @karimdelamora1064 4 роки тому

    Thank you DT!

  • @VulcanOnWheels
    @VulcanOnWheels 4 роки тому +1

    I thought I understood how powerful vim was. I had no idea!

  • @brunomontezano
    @brunomontezano 4 роки тому +2

    Hey DT, could you make a video installing Arch, a window manager and ricing it from scratch? Nothing really extreme, just basic stuff. Cheers from Brazil!

    • @rochr4
      @rochr4 4 роки тому +1

      Why?

  • @riseabove3082
    @riseabove3082 4 роки тому

    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.

  • @augustebaum7791
    @augustebaum7791 4 роки тому

    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!

  • @webbonyoutube
    @webbonyoutube 4 роки тому +5

    I'm keeping that thumbnail in my image collection forever.

    • @ade5324
      @ade5324 3 роки тому

      im intrested in seeing your collection

  • @ramkumars2329
    @ramkumars2329 4 роки тому +1

    excelent man!, i moved from emacs to Vim recently and i find it pretty well than emacs!!,,.. please do a lot of video like these.. Thanks

  •  4 роки тому +1

    Liked for reversing lines of a document. :g/^/m0

  • @AliensInc.
    @AliensInc. 4 роки тому

    ...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

  • @francoissevestre3893
    @francoissevestre3893 2 роки тому

    "I could never use another text editor" DT.

  • @Jordan4Ibanez
    @Jordan4Ibanez 4 роки тому

    I think you should edit the thumbnail with even more signs and gestures with arms coming from every direction surrounding you

  • @truth-mojo
    @truth-mojo 4 роки тому +2

    Dude, what happened to your intro ditty? I really liked that.

  • @kojoig
    @kojoig 4 роки тому +2

    Like for the thumbnail.

  • @Drazil100
    @Drazil100 4 роки тому +2

    I bet you were great at N64 games

  • @christbaumer
    @christbaumer 4 роки тому +1

    Dt bought fully functional arm device.

  • @urugulu1656
    @urugulu1656 4 роки тому +1

    but can you use g to move stuff to a different file (say move all source code in a latex document to an external file you can then import, instead of being put in verbatim)

  • @henrikleion9861
    @henrikleion9861 4 роки тому

    Crikey. Yesterday, I found myself having to reverse a file for the first time in my life. Googled and found a sed oneliner. Happy.
    Today, this pops up first in my UA-cam recommendations! Now paranoid...

  • @albuslrc
    @albuslrc Рік тому

    G is so powerful😄

  • @justray510
    @justray510 3 роки тому

    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?

  • @CabbageBloke
    @CabbageBloke 4 роки тому

    Quick question Mr DT or anyone else that wants to answer.
    I've just bought a new ASUS laptop that has a 4k screen.
    Does Ubuntu or any of the flavours of Ubuntu 20.04 (MATE etc) work ok in 4k?

  • @saeidsaati4021
    @saeidsaati4021 4 роки тому

    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!

  • @Mickey_McD
    @Mickey_McD 4 роки тому +1

    Ha! I had to read others comments to understand what's going on in the thumbnail.

  • @r__9_1____a34
    @r__9_1____a34 4 роки тому

    Could you give us your top lightweight distros?

  • @hodicha
    @hodicha 3 роки тому

    :g or g! /pattern/command is crazy

  • @humanexperience75
    @humanexperience75 4 роки тому +1

    The thumbnail is a subtle gesture to eMac users

  • @BarryArthur
    @BarryArthur 4 роки тому +1

    Get your Vim range, global and substitute black-belt with WAZ -- github.com/dahu/vim_waz_ere

  • @angryfish404
    @angryfish404 4 роки тому +1

    btw : in youtube speeds up the video. :D

  • @BeOnlyChaos
    @BeOnlyChaos Рік тому

    :t and :m were nice new tricks I learnt :D

  • @leviticus8930
    @leviticus8930 4 роки тому +1

    You quarantined by a nuclear reactor? Cause in my neck of the woods, ppl usually only have 2 hands. Btw, if you found a way to add number 3, do a video on it.

  • @batsu47
    @batsu47 4 роки тому +1

    In my opinion this channel is a real virus ;) This one inspired me to use arch and DWM as my daily driver and I wouldn't come back. Thank you for all that you do!

  • @1987slide
    @1987slide 4 роки тому +1

    no one? ok, i'll say it then... Vim Diesel! :D

  • @kautsaralbana7366
    @kautsaralbana7366 4 роки тому +2

    Now you have three hands dt?

    • @rochr4
      @rochr4 4 роки тому +3

      I believe his body responded this way when he was using emacs, now He flexes his new form on us mortals, go challenge him in epic VIm battle and perish (idk. Like VIm golf maybe).

    • @Drazil100
      @Drazil100 4 роки тому +2

      rochr4 nah he was probably playing N64 before he made this video.

  • @jimmythenthusiast6149
    @jimmythenthusiast6149 4 роки тому

    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

  • @Jordan4Ibanez
    @Jordan4Ibanez 4 роки тому

    What distro is this?

    • @bobgrimes8618
      @bobgrimes8618 4 роки тому +1

      Oil_boi_ He usually runs Arcolinux.

  • @DeshierArchitecte
    @DeshierArchitecte 4 роки тому +1

    Gangster.

  • @dorko3031
    @dorko3031 4 роки тому +2

    Did DT just showed us his baby arm?

  • @dustinmorse8497
    @dustinmorse8497 4 роки тому +5

    Thumbnail getting video flagged in 3 2..

  • @AlekseySamoilov
    @AlekseySamoilov 4 роки тому

    Why you have change your microphone every single video?

  • @comp7on940
    @comp7on940 4 роки тому +1

    Not only did you spell out vim, but it's also 213.

    • @fuseteam
      @fuseteam 4 роки тому +1

      looks like 6 4 14 to me :p

  • @Arkayaplays
    @Arkayaplays 4 роки тому

    hey can anyone help me i am not able to join distrotube riot becaue of nick reggeed something

  • @tiktok.4527
    @tiktok.4527 4 роки тому +1

    First like😁

  • @urugulu1656
    @urugulu1656 4 роки тому

    1:59 read? no imma gonna stick with $ is easier

  • @QuoteVG
    @QuoteVG 4 роки тому +2

    Second

  • @joanmilev6156
    @joanmilev6156 4 роки тому +2

    That thumbnail is cringe.

  • @usrname1105
    @usrname1105 4 роки тому +2

    FiRsT

  • @carstenschlegel6975
    @carstenschlegel6975 4 місяці тому

    Top Video, thank you.
    Insert 2 Lines alternative:
    :g/./norm 2o
    or
    :g/./norm A
    (Just press ctrl-v and enter, do not type this characters ;-) - displayed was :g/./norm A^M^M )
    For every line with min. 1 Character (.) run the normal command 2o (insert 2 lines)
    No further lines are inserted under empty lines.
    Use ^ instead of . to insert 2 lines under empty lines.
    Use ^$ instead of . to insert 2 lines ONLY for empty lines.
    (^...$ only for line with exact 3 Charactes, ^... for lines with min. 3 Characters; its just regex)
    Use `norm 2O` to insert the lines above or `norm yyp` to copy every line with content.