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.
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".
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!
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!
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.
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.
"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.
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."
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.
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.
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!
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
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!
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!
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
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.
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.
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
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.
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).
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.
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.
I accidentally found the J command. I just assumed it meant "modify the down command" instead of capital J for "join". That's one of my favorite commands
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.
2:05 | 3:07 | 3:18 > _"format your lines properly so they're not [too long] like this"_ - yeah, i strictly adhere to this (long ruler at 70 characters) for code, - but yeah, this becomes a bit demanded to keep track of on normal/markdown text and stuff... i heard some tools automatically reflow dynamically in realtime while typing? 3:44 hmm, that's good for doing it at one final time, but how about automating that in realtime? - I know some will say it will be jarring and what not, - but while typing, i only focus on current text, so the rapid rearranging movement will be only within one line - which i can tolerate 8:43 > _"conjoining lines: actually the opposite of gq"_ - yeah, what i meant by above "dynamic reflow" is that - how about automatically breaking and conjoining lines adhering to some specified character limit per line? (like say 73) - :wink: this can be made non-constant to get some pretty dashing ASCII art flowing inside some particular shape. wow.
All these decades of using ed/vi/vim/nvim and I never knew about opening a file with "gf". So then I started looking at all the other things "g" does. Turns out "gD", "gd", "gI" and "g8" were all useful for me. The "g" key used to be my leader key in vi because the "g" key was one of the rare keys that had no mappings. Now I can replace some of my mappings with it. Thanks.
I don't subscribe to gq. I used to always format my lines (of e.g. LaTeX) into 80 char limit myself, but at some point I realised it's just unnecessary work, a document with long lines can actually be navigated _faster_ (and just as accurately, thanks to gj / gk), and additions of a few words won't show up as multiple lines changed in the git diffs anymore. It's still a good idea to keep _source code_ lines below 90 chars, and definitely break line after every other sentence or so. But there's not point sticking to a fixed 80 chars, when text editors can just display long lines with line-wrap.
@@harleyspeedthrust4013 honestly now I don't even remember writing this comment and also don't know what I meant by async plugins. Neovim is better anyway :)
I thought that I would not be confortable with vim at first, but 2 weeks in and I don't want to back to VSCode. I even got a US standard keyboard to vim instead of PT-BR ABNT standard
Wow, thanks for letting me know about gq, g0, and g$. I use Vim bindings in Obsidian to jump to the end of my notes quickly, and I found it really annoying to navigate long bullet points or paragraphs (especially with Obsidian's narrow default line wrapping). This will help a lot with my note-taking.
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.
Does gq affect latex documents?
Im used to write my paragraphs on a single line
@@dxrbkn5145 Yes sure you can just use gq on that
@@yochem9294 thanks!
:help g
for getting more info
Thanks for saving my time
An awesome one too:
color0 -> color1
color0 -> color2
color0 -> color3
"v i p", to select the entire paragraph, then "g " to increment sequentially
how to do it from 0 indexing?
@@ocaly select second one down, or c-x after doing g
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".
damn. Its like a book of spells lol. You just keep finding more and more crazy stuff that saves a helluva time.
You are disclosing dark magic... That's dangerous...
Don't you just do simple find replace?
/somethingqacgnsomethingelseq5@a
That's just ....
Woahhh dude, I really liked this one. Thank you c:
This feels like pre-content creator Era of Luke. Back when he used Void and Parabola and had no facecam
And still not used org mode
What do you mean ?
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!
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!
That multi-line word-wrap tip is amazing! sweet tips! thanks, Luke
Right?
Sweet gqG 😆 It just saved me a lot time
so basically "g" stands for god mode ?
hello hussein
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.
8:28 bless you
I've been using vim for a couple of years and I feel like I've barely scratched the surface.
Nice video btw!
I've been using vim for 20 years and I didn't know gJ.
Well you don't need to go deep, most people just use a subset of commands anyways.
@@arcadesoft294 The problem is sometimes you need to go deep to find that small subset.
I actually hit "0" to go to the beginning of the video... and it frickin works!
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.
"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.
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."
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.
I read this as a poem.
@@guidomarrone9562 It works lol
Let's call it _poetic formatting_ or something
It's really annoying to read though
Finally a video which I know almost 90% :)
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.
I've used vi (and variations) since 1985 and learned some new things today. Thanks! :)
Finally he posts something useful!
gq isn't a keybinding-- it's the magazine whose cover you'll be featured on with that fancy shirt
Thank you Vim Diesel.
is there a vimtutor that teaches me how to get a gf?
Vim community believes in keeping things realistic.
So, no.
I just found out that vim was invented on the Amiga, maybe you can get one of these?
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!
Let's gooo, thank you for good content, Luke
Luke is a content creator after all.
After hours of ranting in woods, Vim Diesel is back on his uwu linux.
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
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.
blew my mind with gq, man, thanks!
8:27 Bless you!
Some of what you explain in this video is actually included in vimtutor. I did learn something new though.
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!
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!
ty for doing the needful. i've been working with markdown and the gj tip is a lifesaver.
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
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.
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.
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
Thank you Luke, I needed this to navigate large one line json files pulled from an API.
Great video! I am using vim everyday for coding. And very often all commands with g modifier are helpful indeed
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.
I've just learned about gj and gk in the first two minutes.
This is enough content for me to assimilate right now. Thanks!
Yeah, the power of learning is to assimilate in smaller chunks.
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).
gj and gk will forever change how I use vim. Thank you sir 😭
VIM Diesel is back !
>g&
WOOW. I learned a new world.
Did he hit your g-spot?
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.
^ takes you to most recent buffer and not file as luke said
I subscribed to this channel for the thumbnails
He almost banned because of this
I miss this kind of content. It is what got me into Vim
So good to see you making some educational videos after so many days
Some great useful tips for Vim users. Thank you.
As Always, you are a master!, thank you for all your vim teaching.
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.
Very good idea for a video, I've learned like 3/4 of all those shortcuts. Thanks Luke!
I subscribed!
Thank you for the awesome tips.
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.
Similar to gV, gi puts you where the cursor was the last time you were in insert mode
Missed thumbnail opportunity of Vim Diesel on the cover of gq.
Iʼve remapped `Q` to `q:`. The meaning stays similar, and `q:` is ridiculously nice and useful (especially compared to `Q`, lol).
7:30: @Luke Smith: "Press the little caret thing."
Vim is the most advanced software there is.
0:59 I'm going up and down side to side like a roller coaster.
I have been using vim for several years now, and I didn't know about gj and gk!
YESS I NEEDED THIS
YYYEEEEEESSSSSS
I accidentally found the J command. I just assumed it meant "modify the down command" instead of capital J for "join". That's one of my favorite commands
Alternative title : Discovering the secrets of g- with Luke Smith.
You could actually crack Harry Palmer 😵💫
Luke is the only one making useful Linux videos
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.
Man, I loved this video, insightful!
2:05 | 3:07 | 3:18 > _"format your lines properly so they're not [too long] like this"_
- yeah, i strictly adhere to this (long ruler at 70 characters) for code,
- but yeah, this becomes a bit demanded to keep track of on normal/markdown text and stuff...
i heard some tools automatically reflow dynamically in realtime while typing?
3:44 hmm, that's good for doing it at one final time, but how about automating that in realtime?
- I know some will say it will be jarring and what not,
- but while typing, i only focus on current text, so the rapid rearranging movement will be only within one line
- which i can tolerate
8:43 > _"conjoining lines: actually the opposite of gq"_
- yeah, what i meant by above "dynamic reflow" is that
- how about automatically breaking and conjoining lines adhering to some specified character limit per line? (like say 73)
- :wink: this can be made non-constant to get some pretty dashing ASCII art flowing inside some particular shape. wow.
To get the `g~` functionality by default you can `set tildeop`
Luke Smith out here like a G
1:39 in and already my mind is blown. Thanks for this! Very useful!
All these decades of using ed/vi/vim/nvim and I never knew about opening a file with "gf". So then I started looking at all the other things "g" does. Turns out "gD", "gd", "gI" and "g8" were all useful for me. The "g" key used to be my leader key in vi because the "g" key was one of the rare keys that had no mappings. Now I can replace some of my mappings with it. Thanks.
Bless you
Wooow, the best video i have seen till date. Thanks and subbed.
This was very helpful. Thank you.
gv is great!
Didn't know about that one.
Thanks!
Luke dropping some heaters!!
Learning gJ was useful here.
I don't think I'll ever need the rest.
luke coming through with the vim fu as always
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.
8:27
uh oh.. Luke Smith contracted the c-word
Great video. This guy's a real G
really useful commands
When Bram wrote Vim he created a lasting legacy to his name. May he RIP.
he did it, vim diesel teached more vim, finally!
How has nobody told me about gf. Incredibly useful with import statements.
Not the content we deserved, but the content we needed.
It's amazing how long you can go about using Vim and not bother to learn all the keybinds this thing has...
I like g; it goes to the place you last edited, you can also go forward with g,
gJ and g& were new to me, thanks. Among others unimportant ones like hjkl -- I use mouse for vim navigation duh
Vim diesel is bacc
Nice video. Thanks Luke!
g; is one I use often
Exactly. He forgot the two most important ones, g; and g, .
I don't subscribe to gq. I used to always format my lines (of e.g. LaTeX) into 80 char limit myself, but at some point I realised it's just unnecessary work, a document with long lines can actually be navigated _faster_ (and just as accurately, thanks to gj / gk), and additions of a few words won't show up as multiple lines changed in the git diffs anymore.
It's still a good idea to keep _source code_ lines below 90 chars, and definitely break line after every other sentence or so. But there's not point sticking to a fixed 80 chars, when text editors can just display long lines with line-wrap.
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
Thank you, I'm switching to neovim. IMO, there is no reason to use just vim for developing. Autocompletion, async plugins are useful.
you can get autocomplete for plain vim, i use ycm for that. idk what u mean by async plugins
@@harleyspeedthrust4013 honestly now I don't even remember writing this comment and also don't know what I meant by async plugins. Neovim is better anyway :)
Not even one minute and Im already learning woah
Intellij has a vim plugin, cannot use other to develop with android, hope is gonna improve so that can become proficient in VIM
Thank you, Luke!!
I thought that I would not be confortable with vim at first, but 2 weeks in and I don't want to back to VSCode. I even got a US standard keyboard to vim instead of PT-BR ABNT standard
damn capital J is the thing i should use. instead of opening sublime text to join the lines and reopen vim.
Wow, thanks for letting me know about gq, g0, and g$. I use Vim bindings in Obsidian to jump to the end of my notes quickly, and I found it really annoying to navigate long bullet points or paragraphs (especially with Obsidian's narrow default line wrapping). This will help a lot with my note-taking.
HOW DO I EXIT VIM 👁️👄👁️
Why would you exit vim?
@@PASRC I need to do my taxes 👁️👄👁️
Unplug your computer
@@Alec_Reaper do your taxes in vim
:! poweroff