Vim Tips You Probably Never Heard of

Sdílet
Vložit
  • čas přidán 13. 05. 2021
  • Here are some simple but useful vim commands that many people will not know of. They have to do with line movement, automatic capitalization, moving from file to file and testing substitutions on all lines.
    The theme here is that they all begin with 'g' which is a unique key because it is really only used as a prefix for even more one-off commands.
    My website: lukesmith.xyz
    Please donate: donate.lukesmith.xyz
    Get all my videos off CZcams: videos.lukesmith.xyz
    or Odysee: odysee.com/$/invite/@Luke:7
    BTC: bc1qw5w6pxsk3aj324tmqrhhpmpfprxcfxe6qhetuv
    XMR: 48jewbtxe4jU3MnzJFjTs3gVFWh2nRrAMWdUuUd7Ubo375LL4SjLTnMRKBrXburvEh38QSNLrJy3EateykVCypnm6gcT9bh
    OR affiliate links to things l use:
    www.vultr.com/?ref=8384069-6G Get a VPS and host a website or server for anything else.
    www.epik.com/?affid=we2ro7sa6 Get a cheap and reliable domain name with Epik.
    brave.com/luk005 Get the Brave browser.
    odysee.com/$/invite/@Luke:7 View my videos on Odysee and get a bonus for joining.
    www.coinex.com/register?refer... Get crypto-rich on Coinex. Get reduced exchange fees for 3 months.
    www.coinbase.com/join/smith_5to1 Get crypto-rich on Coinbase. We both get $10 in Bitcoin when you buy or sell $100 in cryptocurrencies.
  • Věda a technologie

Komentáře • 327

  • @fawzanfawzi9993
    @fawzanfawzi9993 Před 3 lety +462

    Quick rundown:
    0:49 gj and gk : Move cursor up and down to wrapped part of a line as if it is a different line.
    2:12 g0 and g$ : Same as previous but move cursor to the first and last letter of a wrapped line.
    3:32 gq : Turn a long line into multiple lines.
    4:55 gu and gU : Uncapitalize and capitalize words/lines.
    6:00 ~ and g~ : Switch capitalization of a letter.
    7:02 gf : Open highlighted text as file.
    8:02 gv : Reselecting previous selected text.
    8:37 gJ : Conjoining lines without leaving spaces.
    10:03 g& : Rerun substitute command for all lines.

    • @dxrbkn5145
      @dxrbkn5145 Před 3 lety +2

      Does gq affect latex documents?
      Im used to write my paragraphs on a single line

    • @yochem9294
      @yochem9294 Před 3 lety +2

      @@dxrbkn5145 Yes sure you can just use gq on that

    • @dxrbkn5145
      @dxrbkn5145 Před 3 lety +2

      @@yochem9294 thanks!

    • @devstefancho
      @devstefancho Před 3 lety +3

      :help g
      for getting more info

    • @bradywb98
      @bradywb98 Před 3 lety +1

      Thanks for saving my time

  • @alkeryn1700
    @alkeryn1700 Před 3 lety +88

    my favorite is "cgn"
    you can search a text or patern with "/" then do "cgn" to change it to something different.
    then typing "cgn" again will jump to the next occurence and change it.
    you can then type "." to repeat as much as you want.
    or do something like "3." or "3cgn".

    • @peacemekka
      @peacemekka Před 3 lety +16

      damn. Its like a book of spells lol. You just keep finding more and more crazy stuff that saves a helluva time.

    • @jimxu1963
      @jimxu1963 Před 3 lety +7

      You are disclosing dark magic... That's dangerous...

    • @iLiokardo
      @iLiokardo Před 3 lety +1

      Don't you just do simple find replace?

    • @mamrezo722
      @mamrezo722 Před 2 lety

      /somethingqacgnsomethingelseq5@a
      That's just ....

    • @camilotello3296
      @camilotello3296 Před rokem

      Woahhh dude, I really liked this one. Thank you c:

  • @mrsansiverius2083
    @mrsansiverius2083 Před 3 lety +77

    This feels like pre-content creator Era of Luke. Back when he used Void and Parabola and had no facecam

  • @IlyesSem
    @IlyesSem Před 2 lety +14

    An awesome one too:
    color0 -> color1
    color0 -> color2
    color0 -> color3
    "v i p", to select the entire paragraph, then "g " to increment sequentially

    • @ocaly
      @ocaly Před 7 dny

      how to do it from 0 indexing?

  • @hnasr
    @hnasr Před 3 lety +52

    That multi-line word-wrap tip is amazing! sweet tips! thanks, Luke

  • @brunobelotticom
    @brunobelotticom Před 3 lety +16

    Another g command I found invaluable is gx, which opens any URL under the cursor in the browser (technically it "execute application for file name", but I use it pretty much only for links). Anyway, thank you for this video: I knew most of them, but the "Conjoining lines" is going to save me SO MUCH TIME. Thanks!

  • @tokiomutex4148
    @tokiomutex4148 Před 3 lety +37

    I've been using vim for a couple of years and I feel like I've barely scratched the surface.
    Nice video btw!

    • @migtrewornan8085
      @migtrewornan8085 Před 3 lety +2

      I've been using vim for 20 years and I didn't know gJ.

    • @arcadesoft294
      @arcadesoft294 Před 3 lety +1

      Well you don't need to go deep, most people just use a subset of commands anyways.

    • @nonconsensualopinion
      @nonconsensualopinion Před 3 lety

      @@arcadesoft294 The problem is sometimes you need to go deep to find that small subset.

  • @JohnDoe_69_420
    @JohnDoe_69_420 Před 3 lety +6

    8:28 bless you

  • @akim5227
    @akim5227 Před 3 lety +34

    Let's gooo, thank you for good content, Luke

    • @sunset-inn
      @sunset-inn Před 3 lety +4

      Luke is a content creator after all.

  • @desktorp
    @desktorp Před 3 lety +16

    gq isn't a keybinding-- it's the magazine whose cover you'll be featured on with that fancy shirt

  • @Theosibo
    @Theosibo Před 5 měsíci +2

    Great video, even a couple years after the fact. Started unlocking the powah of vim motions about 6 weeks ago and videos like this that heavily cover things the :Tutorial only lightly touch on are a tremendous help. Most of us already understand gg (top), G (bottom) 173G (goto line 173) but the rest of this 'g stuff' requires we dig DEEP into the user manual (which I actually started doing last night) to learn. I make it a point every morning to start with the :Tutorial, speedrun through it and then creep into user or reference manuals for deep understanding for 30m before I get started with my daily work and EVERY time I do this exercise another powerful tool is stamped in my forever memory and makes my workflow that much easier. What a powerful tool. Thanks for the info!

  • @johanferozco
    @johanferozco Před 3 lety +3

    Thank you very much, Luke. I ALWAYS enjoy you talk about Vim. It's is because of you that I'm trying to use it more often and it's always good to learn new things about it.

  • @jitessh
    @jitessh Před 3 lety +14

    After hours of ranting in woods, Vim Diesel is back on his uwu linux.

  • @mskiptr
    @mskiptr Před 3 lety +9

    I actually found out
    that formatting text like this
    is way more convenient
    than hard-wrapping lines at a certain offset.
    This gives you nice diffs later on,
    but also is just more readable
    - you can quickly skim through a block of text
    and easily notice actually relevant words.

    • @guidomarrone9562
      @guidomarrone9562 Před 11 měsíci +4

      I read this as a poem.

    • @mskiptr
      @mskiptr Před 11 měsíci +2

      @@guidomarrone9562 It works lol
      Let's call it _poetic formatting_ or something

    • @CamaradaArdi
      @CamaradaArdi Před 9 měsíci +1

      It's really annoying to read though

  • @deeznutz2322
    @deeznutz2322 Před 3 lety +14

    Should have sneezed at the camera to scare the normies.

  • @angusmacgyver
    @angusmacgyver Před 3 lety +2

    Thank you Vim Diesel.

  • @carstenschlegel6975
    @carstenschlegel6975 Před 3 měsíci

    g Adds Numbers in sequence.
    Write:
    Line 0
    Yank this (yy) and copy it 10 times (10p)
    Then mark the last 10 lines (V10j)
    Press g (Control A)
    You have
    Line 0
    Line 1
    Line 2
    ...
    This works for the FIRST Number that VIM found in each line.
    data[0] = "Number 0";
    data[0] = "Number 1";
    data[0] = "Number 2";
    data[0] = "Number 3";
    ...
    where renumbered to
    data[0] = "Number 0";
    data[1] = "Number 1";
    data[2] = "Number 2";
    data[3] = "Number 3";
    ...
    The Number in the String (Number 0...) was unchanged.

  • @a_maxed_out_handle_of_30_chars

    Finally a video which I know almost 90% :)

  • @himanshushukla6451
    @himanshushukla6451 Před 3 lety +50

    Finally he posts something useful!

  • @zneix
    @zneix Před 3 lety

    Very good idea for a video, I've learned like 3/4 of all those shortcuts. Thanks Luke!

  • @TheTrojan665
    @TheTrojan665 Před 3 lety

    ty for doing the needful. i've been working with markdown and the gj tip is a lifesaver.

  • @alternateperson6600
    @alternateperson6600 Před 3 lety +2

    "et ut illi, qui converti non possunt, non minus per opera sapientiae quam per laborem bellicum reprimantur" seems like the perennial approach to wisdom. Thanks for the book (and author) suggestion by the way; adding it to my own personal library.

    • @teacon7
      @teacon7 Před 3 lety

      A hardened heart isn't going to budge for anything. "Having ears, they do not hear..." Better to ask, I suppose, What it is that causes the "converti."

  • @s.espinoza1167
    @s.espinoza1167 Před rokem +1

    thank you a lot for this video, Luke. As a programmer, I'm always trying to learn all the tricks and tweaks that I can to make my development process faster, and your tips helped me with that. Cheers!

  • @sanchopanza9907
    @sanchopanza9907 Před 3 lety

    Thank you Luke, I needed this to navigate large one line json files pulled from an API.

  • @testertech
    @testertech Před 3 lety

    Thanks a lot, very useful beyond the basics of VIM! Will surely try to use these keybindings to unleash more of the Power of VIM in my workflow.

  • @tunina6421
    @tunina6421 Před 3 lety +1

    Where I work, there are a lot of monitors that are vertical and single line wrapping is quite common in files that I work with. This is quite helpful.

  • @GonzaloOviedoLambert
    @GonzaloOviedoLambert Před 2 lety

    As Always, you are a master!, thank you for all your vim teaching.

  • @mamadkhan6708
    @mamadkhan6708 Před 2 lety

    I'm new to Vim , and it's been two weeks that I've been using Vim as my main code editor . It's just mind blowing and awesome! By combining different commands u can do crazy things much faster. It's just great . I LOVE VIM!

  • @victoralcorta
    @victoralcorta Před 6 měsíci

    amazing, it's incredible how you never stop learning vim things haha
    here you got another one with substitution that is really cool for me
    when you got a bunch of text selected you can press : and make a substitution like you did with s/text/replace and that will apply only to that block of text selected, also you can do it like with the number lines :1,5s/text/replace but this is very much practical, no need to see line numbers
    Cheers, nice video!

  • @KbIPbIL0
    @KbIPbIL0 Před 3 lety +2

    blew my mind with gq, man, thanks!

  • @timothyvandyke9511
    @timothyvandyke9511 Před 3 lety +23

    Also, if Vim is too scary for someone to try just jumping in (especially if you need to stay productive for work or something) the VS Code (and Visual Studio) Vim Extension(s) are fantastic. You still keep 100% of the editor commands the same if you're in insert mode too so you can have "training wheels" if you don't have time to look up "how to do x in vim" all the time. It lets you pick a piece or two to learn at a time. I love them

    • @oscarlove4394
      @oscarlove4394 Před rokem +3

      as an additional anti-frustration feature, you can toggle the extension on/off with a custom hotkey, I have mine bound to ctrl+d. so if vim feels like its getting in the way or you don't know how to do something in fim, like find and replace or whatever you can just quickly toggle it off and back on again.

    • @jongeduard
      @jongeduard Před rokem +1

      As a developer using VS at work especially, while also being a Linux enthousiast at home, I am currently also on the Vim path and I started using the VsVim extension. It's really great and also respects your existing key bindings a lot, and you can (and probly want to) configure much around that behaviour, at least a real need for me, because I already customized a lot of things in other ways and certain things just need more time to change, even though the whole thing looks pretty much worth it.
      I yet have to install the one for VSCode too, but I believe that one may be great as well.

    • @console.logged
      @console.logged Před 5 měsíci

      My problem with that is I get too comfortable. I’m pretty good with VS Code shortcuts, which means it’s almost always slower for me to do it the Vim way. I only really learned Vim motions when I had to use Xcode or ssh into a Pi or something

  • @alanbarnett328
    @alanbarnett328 Před 2 lety

    Feels pretty slick watching this and the only thing you learned was g&. Love me some g commands. Literally at the beginning when he said "one key on the keyboard that is unique in vim" I said with him 'g'. Feelsgoodman

  • @prajwalbasnet4461
    @prajwalbasnet4461 Před rokem +1

    I subscribed!
    Thank you for the awesome tips.

  • @camilotello3296
    @camilotello3296 Před rokem

    Man, I loved this video, insightful!

  • @kirkgraham6469
    @kirkgraham6469 Před 3 lety +1

    I've used vi (and variations) since 1985 and learned some new things today. Thanks! :)

  • @archuser7607
    @archuser7607 Před 3 lety

    So good to see you making some educational videos after so many days

  • @pawekoaczynski4505
    @pawekoaczynski4505 Před 3 lety +8

    Similar to gV, gi puts you where the cursor was the last time you were in insert mode

  • @vlmath314
    @vlmath314 Před 3 lety +2

    great video.
    regarding the gq command, you will have issues storing text formatted this way if you are using git to track the changes in the document. it's highly recommended to save one sentence per line, one line per sentence; the git diff will be way easier to understand as opposed to the situation where a sentence is split between multiple lines (diff will show a difference for the current sentence and all the words that append to be at the end and start of the lines in that paragraph, even if you don’t change anything in these sentences).

  • @catwhisperer911
    @catwhisperer911 Před 9 měsíci

    When Bram wrote Vim he created a lasting legacy to his name. May he RIP.

  • @ravidesai9556
    @ravidesai9556 Před 11 měsíci

    This was very helpful. Thank you.

  • @GityaLIVEdnb
    @GityaLIVEdnb Před 3 lety +1

    VIM Diesel is back !

  • @linuxmanju
    @linuxmanju Před rokem

    Wooow, the best video i have seen till date. Thanks and subbed.

  • @VulcanOnWheels
    @VulcanOnWheels Před 3 lety

    8:27 Bless you!
    Some of what you explain in this video is actually included in vimtutor. I did learn something new though.

  • @vterpko
    @vterpko Před 3 lety

    Nice video. Thanks Luke!

  • @KurtSchwind
    @KurtSchwind Před 3 lety

    Well done tips vid. I haven't made good use of the 'g' modifier before. If you want a concrete example of joining lines and losing spaces. I recently had an out of control PATH variable. So I saved it to a file, split lines on `;`, got rid of dupes and changed the order. Then I had to 'restore' the line and I did the Jx thing a few dozen times (yes, I could have done a macro), but had I known about `gJ` it would have made my life easier.

  • @octopusonfire100
    @octopusonfire100 Před 6 měsíci

    I miss this kind of content. It is what got me into Vim

  • @none-cc7im
    @none-cc7im Před 3 lety +3

    >g&
    WOOW. I learned a new world.

  • @Zen-lz1hc
    @Zen-lz1hc Před 2 lety

    Really cool video
    Thanks Man!

  • @GauthamReddy
    @GauthamReddy Před rokem

    Some great useful tips for Vim users. Thank you.

  • @wafflelite
    @wafflelite Před 3 lety +18

    I subscribed to this channel for the thumbnails

  • @Xhisorz1
    @Xhisorz1 Před 3 lety

    gv is great!
    Didn't know about that one.
    Thanks!

  • @utvikler-no
    @utvikler-no Před rokem

    Awesome tutorial ❤

  • @peteryates308
    @peteryates308 Před 2 lety

    The one disadvantage of splitting up your lines of prose is that when you rephrase it your version control history can be more difficult to read, especially if you need to rerun gq across your paragraph.

  • @gavinridley5727
    @gavinridley5727 Před 3 lety +1

    I actually hit "0" to go to the beginning of the video... and it frickin works!

    • @zackinator1439
      @zackinator1439 Před 3 lety

      Ha ha, reminds me of the time I was using Windows for the first time in a while after using LARBS and discovered some of the shortcuts I kept instinctively pressing actually did things. Super+number opens that numbered item on the taskbar for instance. And since I was so used to pressing super all the time, when I tried to alt-tab I pressed super by accident and realized super-tab is like a better alt-tab.

  • @MaxCoplan
    @MaxCoplan Před 2 lety

    Great video. This guy's a real G

  • @lelandkwong
    @lelandkwong Před 3 lety

    luke coming through with the vim fu as always

  • @labrat324
    @labrat324 Před 3 lety

    Luke dropping some heaters!!

  • @beron_the_colossus
    @beron_the_colossus Před 3 lety

    To get the `g~` functionality by default you can `set tildeop`

  • @matj12
    @matj12 Před 3 lety

    I prefer when each paragraph is on one line, because, then, the text can be wrapped at different widths as it's needed. A downside of putting line breaks after a certain line width is that the text looks ugly when it's displayed with a proportional font. A Vim plugin that softly wraps lines at a certain width and draws the text at the centre is goyo.vim.

  • @miladini1
    @miladini1 Před 3 lety

    Thank you, Luke!!

  • @Danscottmusic
    @Danscottmusic Před 3 lety

    thanks for the tips g

  • @kublaios
    @kublaios Před 10 měsíci

    Thanks a bunch, these will save me tons of time. One question regarding gJ - usually, in the source files, there's indentation, so gJ joins the lines with too many spaces obtained from the indentation level. Is there a way to avoid that?

  • @teacon7
    @teacon7 Před 3 lety +1

    good vid. I love it.
    How on earth do i figure out how to print in linux? It won't support my workplace's printer, which I need to use to do my job.

  • @codedsprit
    @codedsprit Před rokem

    Learned new tq luke

  • @haesklar3635
    @haesklar3635 Před 3 lety

    you saved my life thanks for the cool info

  • @iurysza
    @iurysza Před 3 lety +2

    I've just learned about gj and gk in the first two minutes.
    This is enough content for me to assimilate right now. Thanks!

    • @danielmwale9959
      @danielmwale9959 Před 3 lety

      Yeah, the power of learning is to assimilate in smaller chunks.

  • @gurdeepgss
    @gurdeepgss Před 3 lety +1

    ^ takes you to most recent buffer and not file as luke said

  • @GavinFreeborn
    @GavinFreeborn Před 3 lety

    Figured it is worth mentioning that gq can do much more than you mentioned doing a quick `:help gq` will give you a quick explanation. You can basically use it as a code formatted that is much more powerful than `g=`. There is also a video on code formatting in vim that covers this much better than I ever could in a comment.

  • @creonte38
    @creonte38 Před 3 lety

    Very nice! thank you for one more amazing usefull video.

  • @besheraladdam9325
    @besheraladdam9325 Před 3 lety

    Very useful ty.

  • @archuser
    @archuser Před 3 lety +1

    Bless you

  • @fernandomota7193
    @fernandomota7193 Před 3 lety

    0:59 I'm going up and down side to side like a roller coaster.

  • @dixztube
    @dixztube Před 2 měsíci

    Whoa you’re the dude in one of Kenny’s hilarious video posters lol. Hahahahahaha that’s great - came for the vim tips got a big lol

  • @johnpaulhumphrey2981
    @johnpaulhumphrey2981 Před rokem

    I have been using vim for several years now, and I didn't know about gj and gk!

  • @WilliamMelton617
    @WilliamMelton617 Před 3 lety

    gj and gk will forever change how I use vim. Thank you sir 😭

  • @hoshiya4522
    @hoshiya4522 Před 3 lety +6

    YESS I NEEDED THIS

    • @Yeso00
      @Yeso00 Před 3 lety

      YYYEEEEEESSSSSS

  • @octavylon9008
    @octavylon9008 Před 3 lety +1

    How do you get that bar thing on the screen that shows what keys ur pressing ?

  • @bashisobsolete.pythonismyn6321

    thanks imma practice these. BTW, have you returned to teaching?

  • @quanzhou4608
    @quanzhou4608 Před 3 lety

    For the g&, I found I did substitute in on line, but g& applies the substitute to all other lines?

  • @arijitkumarhaldar3197
    @arijitkumarhaldar3197 Před 3 lety

    Alternative title : Discovering the secrets of g- with Luke Smith.

  • @naughtiusmaximus789
    @naughtiusmaximus789 Před 3 lety

    8:27
    uh oh.. Luke Smith contracted the c-word

  • @anonymousanon5390
    @anonymousanon5390 Před 3 lety

    Can you document this video as a text based document and publish it somewhere so we can grab and read this tips any time we need them?

  • @Hexbyte965
    @Hexbyte965 Před 3 lety

    Thanx Luke for the video. (gthanx)

  • @leoliu2079
    @leoliu2079 Před 3 lety

    Luke is the only one making useful Linux videos

  • @lloydbond13
    @lloydbond13 Před rokem

    Damn. That was really useful.

  • @badpotato
    @badpotato Před 3 lety

    really useful commands

  • @hellozdm3701
    @hellozdm3701 Před 3 lety

    I never see you use completion in vim , what do you think about this? builtin or plugin completion

  • @jesterflint9404
    @jesterflint9404 Před 3 lety

    Not the content we deserved, but the content we needed.

  • @majam1n
    @majam1n Před 3 lety

    Missed thumbnail opportunity of Vim Diesel on the cover of gq.

  • @WafflesOinc
    @WafflesOinc Před 3 lety

    Going to add this video to tutorialvids

  • @edvonrattlehead2135
    @edvonrattlehead2135 Před 3 lety

    he did it, vim diesel teached more vim, finally!

  • @snipzmattio5887
    @snipzmattio5887 Před 3 lety

    Thanks, really usefull!

  • @kinzoku777
    @kinzoku777 Před 2 lety

    Luke Smith out here like a G

  • @chezchezchezchez
    @chezchezchezchez Před rokem

    What about the VIM addon for Visual Studio?
    How do I get the "scripts" to run each time?
    (I had to run a script to get the Ctrl-A cool inc a number thing going)
    Thanks!

  • @dxrbkn5145
    @dxrbkn5145 Před 3 lety

    Not even one minute and Im already learning woah

  • @milesrout
    @milesrout Před 3 lety

    g& is pretty cool

  • @Alec_Reaper
    @Alec_Reaper Před 3 lety +7

    HOW DO I EXIT VIM 👁️👄👁️

    • @PASRC
      @PASRC Před 3 lety +2

      Why would you exit vim?

    • @Alec_Reaper
      @Alec_Reaper Před 3 lety +2

      @@PASRC I need to do my taxes 👁️👄👁️

    • @beavatatlan
      @beavatatlan Před 3 lety +7

      Unplug your computer

    • @PASRC
      @PASRC Před 3 lety +6

      @@Alec_Reaper do your taxes in vim

    • @arkayenjay
      @arkayenjay Před 3 lety +1

      :! poweroff

  • @asadmoosvi
    @asadmoosvi Před 3 lety +1

    Here's another one I use quite a bit. It opens the thing underneath the cursor in its default application. (gx)

  • @hz8711
    @hz8711 Před rokem

    Love it!

  • @linuxinside6188
    @linuxinside6188 Před 3 lety

    Vim diesel is bacc