Vim Tips You Probably Never Heard of

113,439
0
Published 2021-05-14
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 YouTube: 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_code=ndf87 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.

All Comments (21)
  • @fawzanfawzi9993
    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.
  • @alkeryn1700
    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".
  • This feels like pre-content creator Era of Luke. Back when he used Void and Parabola and had no facecam
  • @hnasr
    That multi-line word-wrap tip is amazing! sweet tips! thanks, Luke
  • @IlyesSem
    An awesome one too: color0 -> color1 color0 -> color2 color0 -> color3 "v i p", to select the entire paragraph, then "g " to increment sequentially
  • @brunobelotticom
    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
    I've been using vim for a couple of years and I feel like I've barely scratched the surface. Nice video btw!
  • @johanferozco
    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.
  • @Theosibo
    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!
  • @akim5227
    Let's gooo, thank you for good content, Luke
  • @zneix
    Very good idea for a video, I've learned like 3/4 of all those shortcuts. Thanks Luke!
  • 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!
  • @TheTrojan665
    ty for doing the needful. i've been working with markdown and the gj tip is a lifesaver.
  • @sanchopanza9907
    Thank you Luke, I needed this to navigate large one line json files pulled from an API.
  • @testertech
    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.
  • @mamadkhan6708
    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!
  • 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.
  • @victoralcorta
    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!