Vim Tips You Probably Never Heard of
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
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
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 ?
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?
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
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!
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.
8:28 bless you
Let's gooo, thank you for good content, Luke
Luke is a content creator after all.
gq isn't a keybinding-- it's the magazine whose cover you'll be featured on with that fancy shirt
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!
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.
After hours of ranting in woods, Vim Diesel is back on his uwu linux.
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
Should have sneezed at the camera to scare the normies.
Thank you Vim Diesel.
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.
Finally a video which I know almost 90% :)
Finally he posts something useful!
Very good idea for a video, I've learned like 3/4 of all those shortcuts. Thanks Luke!
ty for doing the needful. i've been working with markdown and the gj tip is a lifesaver.
"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."
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!
Thank you Luke, I needed this to navigate large one line json files pulled from an API.
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.
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.
As Always, you are a master!, thank you for all your vim teaching.
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!
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!
blew my mind with gq, man, thanks!
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
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
I subscribed!
Thank you for the awesome tips.
Man, I loved this video, insightful!
I've used vi (and variations) since 1985 and learned some new things today. Thanks! :)
So good to see you making some educational videos after so many days
Similar to gV, gi puts you where the cursor was the last time you were in insert mode
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).
When Bram wrote Vim he created a lasting legacy to his name. May he RIP.
This was very helpful. Thank you.
VIM Diesel is back !
Wooow, the best video i have seen till date. Thanks and subbed.
8:27 Bless you!
Some of what you explain in this video is actually included in vimtutor. I did learn something new though.
Nice video. Thanks Luke!
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.
I miss this kind of content. It is what got me into Vim
>g&
WOOW. I learned a new world.
Did he hit your g-spot?
Really cool video
Thanks Man!
Some great useful tips for Vim users. Thank you.
I subscribed to this channel for the thumbnails
He almost banned because of this
gv is great!
Didn't know about that one.
Thanks!
Awesome tutorial ❤
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.
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.
Great video. This guy's a real G
luke coming through with the vim fu as always
Luke dropping some heaters!!
To get the `g~` functionality by default you can `set tildeop`
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.
Thank you, Luke!!
thanks for the tips g
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?
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.
Learned new tq luke
you saved my life thanks for the cool info
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.
^ takes you to most recent buffer and not file as luke said
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.
Very nice! thank you for one more amazing usefull video.
Very useful ty.
Bless you
0:59 I'm going up and down side to side like a roller coaster.
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
I have been using vim for several years now, and I didn't know about gj and gk!
gj and gk will forever change how I use vim. Thank you sir 😭
YESS I NEEDED THIS
YYYEEEEEESSSSSS
How do you get that bar thing on the screen that shows what keys ur pressing ?
thanks imma practice these. BTW, have you returned to teaching?
For the g&, I found I did substitute in on line, but g& applies the substitute to all other lines?
Alternative title : Discovering the secrets of g- with Luke Smith.
8:27
uh oh.. Luke Smith contracted the c-word
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?
Thanx Luke for the video. (gthanx)
Luke is the only one making useful Linux videos
Damn. That was really useful.
really useful commands
I never see you use completion in vim , what do you think about this? builtin or plugin completion
Not the content we deserved, but the content we needed.
Missed thumbnail opportunity of Vim Diesel on the cover of gq.
Going to add this video to tutorialvids
he did it, vim diesel teached more vim, finally!
Thanks, really usefull!
Luke Smith out here like a G
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!
Not even one minute and Im already learning woah
g& is pretty cool
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
Here's another one I use quite a bit. It opens the thing underneath the cursor in its default application. (gx)
Love it!
Vim diesel is bacc