Vim As You Editor - Advanced Motions P1

ThePrimeagen · Advanced ·💻 AI-Assisted Coding ·3y ago

Key Takeaways

The video demonstrates advanced Vim motions and techniques for efficient text editing, including horizontal movements, text object commands, and selecting text within various brackets and parentheses. It showcases tools like Vim, Vimby Good, and Neo Vim, and provides steps for jumping forward to text object commands, selecting text, yanking text, and pasting over text.

Full Transcript

my name is the primogen and i have been using vim for about 10 years now and i'm pretty fast at using these motions i just wanted to share with you ways to use vim better because the problem with vim is that there's a lot of ways to do things and if you're newer to vim you're probably inundated with the different ways in which you can accomplish various text editing motions and commands and i want to help set you on that right path that good path that coconut oiled path so let's do this let's master some vim motions specifically i find one of the most annoying parts about vim when i started off was the horizontal movements so getting fast at that is huge and we're going to go through ways to get fast coconut oily fast that is i did want to start with something kind of like a little pre-note here if you're not comfortable just doing something like like that just wwcw really quickly and being able to cut out and start typing in something different i i do emphasize that practicing the basics will help you in the long run if you do not feel creamy smooth with w with f and t then you probably need to go back to the drawing board and get good with those ones i have been developing a program called vimby good which i will be upgrading here soon in which has games to become good at these motions honestly just practicing relative line jumping uh w's f's and t's you will honestly get really fast but i want to go even faster so for those that are feeling extra amazing let's go over some very i don't even have a word to put in there yeah so let's just do this alright so the first thing i want to show you is jumping forward text object commands now back in the day if you were to ask me to hey highlight this this type right here and let's replace it with bar i would have done something like this i would have jumped forward to that pressed v jumped to the end yanked it out walked down forward vw back it up one paste it now that's a probably a pretty standard way most people think when they use vim you're using the basic commands and you're using them fairly fast and you can honestly get a lot done just knowing the basic commands so if you're not familiar there's there's this actually pretty neat thing so if i'm in between these parentheses and i go vi parentheses i select everything within those parentheses if i go within these squirrely braces and i go vi within those squirly braces it selects everything in there i can also do a v a squirrely braces and it selects everything and around okay this is very very good to know that means if i am before a squirrely brace and i'm not in between any squirrely braces and i go va squirrely i'll actually select the next one in the line that's pretty awesome it doesn't i don't believe it works with older versions of vim if you're in sevens and below but i believe it works at eights and it works in the latest neo vim if not you can always jump forward to it and then va squirrely brace and it will still work but for our case if we wanted to do this quick we could do y a squirrely brace yank everything in between the squirrely braces plus the squirly braces themselves then i can just do a four down word over viw now i always use a viw and the reason why i always use viw is it doesn't matter where i'm at within the word it always selects that so viw selects it if i'm in the middle viw selects it awesome and once i do that i can just simply paste and i'll paste in that type this is a move i do all the time i'll select something out jump to what i want to replace either do a viw or a vi capital w meaning i select all text until white spaces and then paste over it it's really really nice especially with types with colons in them you can replace types quite quickly so let me actually give you an example that let's pretend we're right here in the result and we want to use that some long type as the return value of our result in rust now there's a couple different ways in which we could do this but the fastest most amazing way is actually to jump back to the closing parentheses and then do a y i capital word that means i selected everything that's contiguous contiguous text jump forward to this bracket paste it in replace it with a bracket and so you can actually accomplish that pretty fast so i love the iws and the capital iws over selecting sometimes is fun and even has some advantages because i think before what i would have done is i probably would have jumped back by space use semicolon to walk back forward one with either l or w v t that yank it jump forward paste it in a that exit right that's way too many steps when really all you need to do is just simply jump back to that select the whole word jump forward paste replace right it's just that simple it's that simple i know this is a lot that's why i said you really do want to be able to master the concrete of this all right master the concrete that's actually not a phrase nobody uses that phrase i don't even know where i'm getting it from okay i don't i don't even know where i'm getting it from but having like a really strong grasp on the fundamentals to the point where you don't have to think is incredibly important and i did want to make a note about capital f jumping or f jumping one of the problems i see with that is that when you do these jumps you have to understand the character in which you want to jump to and if there's any characters in between you have to use semicolon or comma to jump backwards or forwards within that list and for me that's a lot of overhead that's why lately i've been doing a lot of y i capital w's or y i w's because what they do is they allow you to just select a word and it doesn't matter what you need to select up to it just will select the whole thing and for me that is a lot less mental overhead than yt closing brace because it doesn't matter a where i'm at within it and b i don't have to look for the closing brace and then jump too up to it but not including it right there's just a lot less overhead just to go ah just give me the whole thing i can fix that later on and so i could jump here i could va uh you know whatever that thing is and i could paste the whole thing in if i wanted to replace it or i could vi that and then paste it in now one of the problems that just happened there is that when i did that when i pasted i lost what was in my paste buffer paste register it's not a buffer buffers are where you put text registers a lot different there so a super cool remap to have is leader p if i'm in some sort of visual mode and i do leader p it will actually do a delete to the underscore register which means that it just it's gone and then it'll capital p back into that paste let me show you what that looks like so let me change this type to say uh you size right notice that i just did a ci capital w right i didn't have to think about jumping it didn't matter where i was i could just delete the whole thing so now i'm going to do a yw i'm going to jump into this and do a vi carrot and instead of just pasting i'm going to space paste now using that remap what it just did is it replaced everything right it deleted and then pasted it backwards but look what's still inside of my register i still have the use size as opposed to that some type extremely useful to have and to get into the muscle memory to use when you need to do it because sometimes the find and replace sucks right you don't want to have to type out a huge thing for the find and replace instead you just copy it once and you go to the two places that you need to find and replace and then you can just use lead or p to paste it in without losing that paste i don't know i thought it was awesome i thought it was awesome all right so another thing i see a lot of people in vim never take advantage of is a not using something like y y but instead you shift v y the reason why is you get the exact same effect but it's way faster to press two distinct characters than a single like a double tap i hate double tapping i like that kind of that double tap not the other double tap same thing works with vd it's not venereal disease you just simply visually delete that whole line and it doesn't matter whether it's capital uh y or lowercase y same effect as yielded all right so like i said a lot of people never take advantage of already having some of the text you know typed so right now i want to be able to create this serialized buffer method it's going to be a private method so i can jump down paste it in private four jump buffer di squirrely f to the bar dt squirrely brace now notice what i did is i didn't have to type nearly as much and it kind of made it like into a fun game now one thing i really think is important with vim is having fun along the way and for me running these large amounts of sequence of commands is actually really fun because it's like okay i gotta maze my way through right i gotta jump to this one type in a word jump out delete everything inside of it jump forward delete right like you're just like bam bam bam bam going sequentially through the line i find that to be just out of this world fun so that's kind of like a double whammy tip right there make it fun use vyvd and if you already have a line use it so i did give you guys a lot of cool things to be practicing horizontally hopefully that made a lot of sense if you like this subscribe to this channel already press that button if there's any motions horizontal motions that you feel like i didn't really take advantage of or i'm missing let me know in the comments down below if this blows your mind then join the discord or twitch and quit being a pleb and then on a like a final note uh something that's really important to me is having fun so i hope ultimately when you see all these things it's not discouraging but instead it's encouraging that there's still a lot more you can do with vim that it makes you feel like you really want to master these things for me it's it's that intersection of having fun making it feel like editing is a game and getting things done that i just love like when i'm in the zone and i can just edit text at an incredible speed and i'm having a good time doing it for me just enjoy it love it well thank you very much for watching the name is the primogen ghost ride to whim

Original Description

YES!! that is right. A new vim series. IF YOU LIKE THIS, BETTER LIKE THE VIDEO BECAUSE I'LL TAKE THIS FAR IF THERE IS ENOUGH LIKES ### Twitch Everything is built live on twitch Twitch : https://bit.ly/3xhFO3E Discord: discord.gg/ThePrimeagen Spotify DevHour: https://open.spotify.com/show/4MLaDrQcQ5mi3rsnvWkwPt ### Editor All my videos are edited by Flip. Give him a follow! https://twitter.com/flipmediaprod He is also open to do more editing, so slide deeeeeeeeep into his dms. ### Links Linode: https://linode.com/prime https://discord.gg/ThePrimeagen Twitch: https://twitch.tv/ThePrimeagen Insta: https://instagram.com/ThePrimeagen Twitter: https://twitter.com/ThePrimeagen VimRC & i3: https://github.com/ThePrimeagen/.dotfiles Keyboard 15% off https://bit.ly/Prime360 USE CODE PRIME360 #vim #programming #softwareengineering
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from ThePrimeagen · ThePrimeagen · 32 of 60

1 Two Simple Steps to go from IDE to Vim
Two Simple Steps to go from IDE to Vim
ThePrimeagen
2 Git's Best And Most Unknown Feature
Git's Best And Most Unknown Feature
ThePrimeagen
3 My Developer Workflow - How I use i3, tmux, and vim
My Developer Workflow - How I use i3, tmux, and vim
ThePrimeagen
4 Github Copilot MAKES A CLI GAME IN GOLANG FROM SCRATCH?!?!
Github Copilot MAKES A CLI GAME IN GOLANG FROM SCRATCH?!?!
ThePrimeagen
5 I made the greatest tool ever! | tmux & cht.sh & fzf
I made the greatest tool ever! | tmux & cht.sh & fzf
ThePrimeagen
6 Is TypeScript (NodeJS) Faster than Go?? |  A server comparison
Is TypeScript (NodeJS) Faster than Go?? | A server comparison
ThePrimeagen
7 How to make TypeScript Blazingly Fast (JavaScript/NodeJS)
How to make TypeScript Blazingly Fast (JavaScript/NodeJS)
ThePrimeagen
8 Learn Vim in Less than 2 Minutes
Learn Vim in Less than 2 Minutes
ThePrimeagen
9 The biggest lie about programming?  REACTING to tech twitter
The biggest lie about programming? REACTING to tech twitter
ThePrimeagen
10 Rust or Go for my next project? WHAT TO CHOOSE? (as a senior intern engineer)
Rust or Go for my next project? WHAT TO CHOOSE? (as a senior intern engineer)
ThePrimeagen
11 Go is faster than Rust??!  Go vs Rust vs TypeScript Servers (as a scientist)
Go is faster than Rust??! Go vs Rust vs TypeScript Servers (as a scientist)
ThePrimeagen
12 You only Git Merge?!? feat Theo : DevHour #1
You only Git Merge?!? feat Theo : DevHour #1
ThePrimeagen
13 YOU DONT UNIT TEST??? DevHour #1 Theo
YOU DONT UNIT TEST??? DevHour #1 Theo
ThePrimeagen
14 Tech TikTok - Is this really programming? | React
Tech TikTok - Is this really programming? | React
ThePrimeagen
15 I am dying
I am dying
ThePrimeagen
16 Comparing Rust (Yew) vs TypeScript (React) NodeJS | SSR times
Comparing Rust (Yew) vs TypeScript (React) NodeJS | SSR times
ThePrimeagen
17 Why I use Vim in 2022
Why I use Vim in 2022
ThePrimeagen
18 How programming feels
How programming feels
ThePrimeagen
19 Why I Quit Netflix
Why I Quit Netflix
ThePrimeagen
20 Programming on TikTok
Programming on TikTok
ThePrimeagen
21 If I could give advice to myself when starting as a software engineer
If I could give advice to myself when starting as a software engineer
ThePrimeagen
22 How am I suppose to get a job as a software engineer?
How am I suppose to get a job as a software engineer?
ThePrimeagen
23 Why do I feel burnt out? (software engineering)
Why do I feel burnt out? (software engineering)
ThePrimeagen
24 I am done with vim
I am done with vim
ThePrimeagen
25 Maintaining Motivation as a Software Engineer
Maintaining Motivation as a Software Engineer
ThePrimeagen
26 Bun (TypeScript) is faster than Rust!?!
Bun (TypeScript) is faster than Rust!?!
ThePrimeagen
27 Go is blazingly faster than Zig?
Go is blazingly faster than Zig?
ThePrimeagen
28 Facebook Recommends Rust?
Facebook Recommends Rust?
ThePrimeagen
29 5 Things I Hate About JavaScript
5 Things I Hate About JavaScript
ThePrimeagen
30 Why I Make Content
Why I Make Content
ThePrimeagen
31 Is ADHD Bad For Programming?
Is ADHD Bad For Programming?
ThePrimeagen
Vim As You Editor - Advanced Motions P1
Vim As You Editor - Advanced Motions P1
ThePrimeagen
33 How I Would Get My First Job If I Started Over
How I Would Get My First Job If I Started Over
ThePrimeagen
34 Vim as your editor - Advanced Motions P2
Vim as your editor - Advanced Motions P2
ThePrimeagen
35 My Best Decision Professionally
My Best Decision Professionally
ThePrimeagen
36 Should you use RUST as your FIRST programming language?
Should you use RUST as your FIRST programming language?
ThePrimeagen
37 How I Made JavaScript BLAZINGLY FAST
How I Made JavaScript BLAZINGLY FAST
ThePrimeagen
38 Is JSON Blazingly Fast or...?
Is JSON Blazingly Fast or...?
ThePrimeagen
39 Vim As Your Editor - Introduction
Vim As Your Editor - Introduction
ThePrimeagen
40 Vim As Your Editor - Horizontal
Vim As Your Editor - Horizontal
ThePrimeagen
41 Astro IS SO GOOD
Astro IS SO GOOD
ThePrimeagen
42 STOP LYING, The truth about Software Engineering
STOP LYING, The truth about Software Engineering
ThePrimeagen
43 Does Your Editor Matter?
Does Your Editor Matter?
ThePrimeagen
44 React Is This Fast???
React Is This Fast???
ThePrimeagen
45 Vim As Your Editor - Vertical Movements
Vim As Your Editor - Vertical Movements
ThePrimeagen
46 Rust for TypeScript devs : Borrow Checker
Rust for TypeScript devs : Borrow Checker
ThePrimeagen
47 Will ChatGPT Terminate Your Job?
Will ChatGPT Terminate Your Job?
ThePrimeagen
48 0 to LSP : Neovim RC From Scratch
0 to LSP : Neovim RC From Scratch
ThePrimeagen
49 From Meth To Netflix
From Meth To Netflix
ThePrimeagen
50 Faster than your favorite JS framework?
Faster than your favorite JS framework?
ThePrimeagen
51 Primeagen Answers the Webs Most Asked Questions for a Software Engineer
Primeagen Answers the Webs Most Asked Questions for a Software Engineer
ThePrimeagen
52 This Algorithm is 1,606,240% FASTER
This Algorithm is 1,606,240% FASTER
ThePrimeagen
53 Looking Under the Hood of JavaScript
Looking Under the Hood of JavaScript
ThePrimeagen
54 What Next...Finding a New Job In Software
What Next...Finding a New Job In Software
ThePrimeagen
55 JSON, I hardly know 'er
JSON, I hardly know 'er
ThePrimeagen
56 RUST Enums ARE Better
RUST Enums ARE Better
ThePrimeagen
57 CoPilot Review: My Thoughts After 6 Months
CoPilot Review: My Thoughts After 6 Months
ThePrimeagen
58 How to Vim in 2023: Tips and Tricks
How to Vim in 2023: Tips and Tricks
ThePrimeagen
59 Twitter's Algorithm Has MASSIVE Problems
Twitter's Algorithm Has MASSIVE Problems
ThePrimeagen
60 Rust Foundation IS DOING WHAT????
Rust Foundation IS DOING WHAT????
ThePrimeagen

This video teaches advanced Vim motions and techniques for efficient text editing, including horizontal movements and text object commands. It provides hands-on examples and steps for mastering Vim. By watching this video, viewers can improve their Vim skills and become more efficient in their coding workflow.

Key Takeaways
  1. Jumping forward to text object commands with vi
  2. Selecting text within parentheses, curly braces, and square brackets with vi
  3. Yanking text with vi
  4. Pasting over text with viw
  5. Replacing types with colons in them quickly with viw
  6. Copy a line with 'y'
  7. Paste a line with 'p'
  8. Copy a line with 'shift v y'
  9. Visually delete a line with 'vd'
  10. Type commands in a sequence
💡 Mastering Vim motions and text object commands can significantly improve coding efficiency and productivity.

Related Reads

📰
Why AI Coding Widens the Senior–Junior Developer Gap
AI coding can exacerbate the senior-junior developer gap by producing code that looks polished but lacks underlying quality, making it essential for senior developers to review and mentor junior developers
Dev.to AI
📰
AI Code Security Audit for Startups: What to Check Before Deploying
Learn to secure your startup's AI-generated code with a structured security audit to prevent invisible risks and technical debt
Dev.to AI
📰
We Let AI Write a Third of Our Code. Here's the Review Process That Kept Us Sane.
Learn how to effectively review AI-generated code with a structured process, ensuring quality and sanity in AI-assisted development
Dev.to · Marketing wizr
📰
AI in Software Testing
Learn how AI is revolutionizing software testing and why it matters for efficient development
Dev.to · Thomas Silva
Up next
Azure Security Priorities for 2026: Identity, Governance, AI Security & Zero Trust
Valto Microsoft Specialists
Watch →