Vim Tips I Wish I Knew Earlier

  Рет қаралды 38,693

Sebastian Daschner

Sebastian Daschner

3 ай бұрын

When starting out your journey with Vim, there are so many things to learn. Over time, you will see which features will stick with you and which ones are helpful in your work. In this video, I’m showing Vim tips that I'm using now, that I wish I knew earlier.
For more information: blog.sebastian-daschner.com/e...
Developer Productivity Masterclass: www.sebastian-daschner.com/co...

Пікірлер: 133
@dexedrine404
@dexedrine404 Ай бұрын
Timestamps: 0:24 - Relative line numbers 2:26 - Mapping Esc to Caps Lock 3:22 - :norm 4:41 - C-v (similar to :norm A & I) 6:04 - in(de)crement numbers with C-a / C-x 8:36 - using o to change visual select direction 9:24 - % for jump to matching pair: ({[ 11:04 - i / a (inside / outisde) 13:55 - W vs w 15:51 - Invoking external scripts/binaries 19:08 - Creating (dynamic) snippets 20:25 - Using netrw/fzf/search
@pldvs
@pldvs 3 ай бұрын
Has to be the most underrated piece of software ever. I'll never go back.
@flflflflflfl
@flflflflflfl 3 ай бұрын
You think vim is underrated???
@excel9566
@excel9566 3 ай бұрын
i'm sorry
@pldvs
@pldvs 3 ай бұрын
@@flflflflflfl By people who prefer nano.
@flflflflflfl
@flflflflflfl 3 ай бұрын
@@pldvs ok but that's that's like, 7 people
@pldvs
@pldvs 3 ай бұрын
@@flflflflflfl I think you'd be surprised.
@GOTHICforLIFE1
@GOTHICforLIFE1 2 ай бұрын
highly recommend placing some segments and timestamps on these videos, as you rarely have everything being new for Vim users. That way we can easily click to those points that might apply.
@Snollygoster-
@Snollygoster- 2 ай бұрын
Vertical visual mode with the multi cursor was the only thing I saw an emacs user have that I wanted, and vim turns out to have it too. It's such a nice experience using that. Absolute chad developers.
@yash1152
@yash1152 Ай бұрын
how multiple cursor?
@andrewiglinski148
@andrewiglinski148 2 ай бұрын
Dude I've been using vim for almost 2 years and you're the first person that's actually taught me something new past the first month of this endeavor.
@nahblue
@nahblue 2 ай бұрын
I've been using vim for 15 years and I learned something new from the video
@LeviNotik
@LeviNotik 2 ай бұрын
Great video, nicely done. Didn't know about o for adjusting the visual selection. I've always cancelled and started from scratch when I screwed up. No longer!
@teohz
@teohz 2 ай бұрын
One of my favourites has to be a way to "encase" text in quotes/braces/etc: replace the text either after selecting in visual or with motions, i.e. cw {" " "} --- the " after ctrl+r pastes the text you just cut from the " register.
@ElPikacupacabra
@ElPikacupacabra 2 ай бұрын
...noice 😮
@SlothWindGod
@SlothWindGod 2 ай бұрын
Couldn't you just use "p" to paste the text instead as by default it pasted from the " register?
@ElPikacupacabra
@ElPikacupacabra 2 ай бұрын
@@SlothWindGod You can, but you have to exit insert mode and navigate back two characters before pressing "p". About the same.
@SlothWindGod
@SlothWindGod 2 ай бұрын
@@ElPikacupacabra ctrl + o to perform a command from insert mode means you don't have to navigate out of it
@ElPikacupacabra
@ElPikacupacabra 2 ай бұрын
@@SlothWindGod You're not in the correct position I think 🤔. But many ways to skin a cat
@EmielvanGoor
@EmielvanGoor 3 ай бұрын
What the...! I absolutely love that :norm command! I didn't knew it was that easy! Thanks a lot Sebastian.
@pldcanfly
@pldcanfly 3 ай бұрын
Yep! Gamechanger!... And here I was q-macro record such things and then @q all the lines or do some fancy recursive things. This makes things so much more easy!
@EmielvanGoor
@EmielvanGoor 3 ай бұрын
@@pldcanfly I did exactly the same!
@vutranang8053
@vutranang8053 2 ай бұрын
true, that :norm blow my mind
@zyriab5797
@zyriab5797 3 ай бұрын
You can use i/a with a lot of stuff: f = function p = paragraph t = HTML tag And probably a ton I don't know about
@nahblue
@nahblue 2 ай бұрын
f requires treesitter and neovim- I think?
@catfan5618
@catfan5618 2 ай бұрын
2:59 Mapping escape to caps lock is pretty easy on every major operating system. Under MacOS its under Settings/Keyboard/Modifier Keys and under Windows you can install PowerToys by Microsoft and do it under Keyboard manager/Remap a key. I highly recommend doing this.
@user-me8dk7ds7f
@user-me8dk7ds7f 2 ай бұрын
One very helpful keybinding in vim, is Ctrl+R in insert mode, when pressing it you are able to paste directly from some register. I was finding my self a lot of the times, just pressing escape to go into normal mode, and press p (to paste) and i again to move to insert mode. It is very helpful...
@yash1152
@yash1152 Ай бұрын
thanks if it works. will try it next time i get my hands on nvim.
@Yeet_the_code
@Yeet_the_code 3 ай бұрын
Set environment variable "EDITOR=vim" or whatever you like Write some command in your bash terminal and press (CTRL + X & CTRL + E) This allows you to modify the command you want to write by opening up the command in your "$EDITOR" Especially useful when writing commands that you want to split over multiple lines, but still be executed as if it was all in one command. Or just want to get some syntax highlighting in your favorite text editor. Most people might already know this... but if you don't, you're welcome.
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
Yes, been using that in my zsh/vi-mode setup, very helpful!
@ivanheffner2587
@ivanheffner2587 2 ай бұрын
Got a typo in your previous command (or just want to edit it and run the new command)? Try `fc` to “fix command” using your $FCEDIT editor.
@secondculs
@secondculs 22 күн бұрын
norm is a pretty new to me, this is really great to put in to my arsenal
@lasombra_br
@lasombra_br 3 ай бұрын
Fantastic video, Sebastian! Really interesting with some great tips!
@phaberest_
@phaberest_ 2 ай бұрын
Loved this! Thank you Sebastian, awesome content
@roryhendrickson
@roryhendrickson 20 күн бұрын
I needed these tips, thanks for sharing!
@MrPolyphonicpoi
@MrPolyphonicpoi 2 ай бұрын
Windows users - reading the friendly manual: "Since CTRL-V is used to paste, you can't use it to start a blockwise Visual selection. You can use CTRL-Q instead."
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
Oh man... isn't Windows fun 🤦‍♂️ Thanks for pointing that out!
@nahblue
@nahblue 2 ай бұрын
I like automatic session saving, that's the big one I've learned recently. Didn't get into it until it was automatic in some neovim config I was using. It always saves your session on exit, and when starting vim there's an *option* to resume the session by pressing a keybinding - and it knows which session based on which directory you are in.
@aksh1618
@aksh1618 2 ай бұрын
Nice tips, subscribed! One suggestion for such videos: you need to code in the memory of these things otherwise anyone will forget them 5 minutes after watching! The way I remember these is how the creators of vim motions intended it: by looking at the meaning of the letters, such [o] for [O]ther end of highlighted text, and [a] for [A]round.
@Vic-ky3cc
@Vic-ky3cc 23 күн бұрын
This was very insightful, thanks
@VinitNeogi
@VinitNeogi 3 ай бұрын
Didn't know about o for switching direction of selection
@devfagundes
@devfagundes 2 ай бұрын
Nice video! I recently learned about the ctrl+f trick in command mode, its usefull
@chai01724
@chai01724 2 ай бұрын
Thank you for this video! Espanso is a great text expander to check out too!
@julian-fricker
@julian-fricker 3 ай бұрын
Been using vi/vim/neovim since 1992 and still learn new things from this kind of video, o especially. What are you using for the markdown headings to be shown at the top of your screen as you scroll down? This was in the section about relative line numbers.
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
That's the 'wellle/context.vim' plugin
@DanAlmenar
@DanAlmenar 2 ай бұрын
sessions and copy-paste to/from clipboard (I don't have clipboard support) has been my newest tools for vim
@creativenull
@creativenull 3 ай бұрын
I've know almost all of them for a while, but these are some great tips! For me, I had to turn off relative numbers because it was not great for pair programming with a colleague when they had to point out at what line should a change go, etc, but overall is a nice feature that I like One thing I learned from this was the `o` in visual mode, that's actually pretty neat I think I might start using that instead of thinking about where to start the highlighting from and to, everyday you learn something new in vim 😅
@wetfloo
@wetfloo 3 ай бұрын
you can execute your line number in ex mode, for example :141 would go to line 141
@zyriab5797
@zyriab5797 3 ай бұрын
You can also type `141G` :)
@creativenull
@creativenull 3 ай бұрын
@@wetfloo That I know but not what I meant. For example, when I'm pair programming with someone and they want to suggest a change at a particular line. With relativenumber enabled, they won't be able to tell me which line in the code to go to and might get confused by the numbering (that I would understand). It was just easier to keep relativenumber disabled for the session or entirely so that my colleagues can better direct me 😅
@wetfloo
@wetfloo 3 ай бұрын
@@creativenull hmm, you could disable relative line numbers in pair programming with :set nornu
@creativenull
@creativenull 2 ай бұрын
@@wetfloo yup exactly!
@buildervision7082
@buildervision7082 2 ай бұрын
Great content, learnt something new
@somnvm37
@somnvm37 3 ай бұрын
the thing that I use in vim is that, in KDE you can download certain keyboard layouts that have 3rd and 4th layer, and then in keyboard settings select "use caps lock for the third layer" now if I press caps l I get ľ, caps j gives ± and so on this allows for a lot of new potential keybindings, ď for emmet ľ for esc ± and ł for scrolling by line [C-Y and C-E] so now i can move cursor with j k and move screen with caps j k (every press moves the screen by 1 line) also š for :w i only have these right now, but I can add more in the future [oh and also, in kde settings you can make caps mode go on from both shifts being tapped at the same time]
@exegeteio
@exegeteio 3 ай бұрын
w/W is great, but don’t sleep on b/B for going the other way. o will be a game changer for me. Thank you!
@r4s3
@r4s3 Ай бұрын
I've been using vim for years and knew I knew about invoking with ! from command mode but the fact that you can replace the contents in place with the output blew my mind.
@NormTurtle
@NormTurtle 2 ай бұрын
did i knew it already : YES did i watched it again : YES
@odb7393
@odb7393 Ай бұрын
Sweet video dude!
@SethMilliken
@SethMilliken 2 ай бұрын
Another nice one with some of the text-objects (i.e. va", vi
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
Oh nice, thanks!
@cristobaljvp
@cristobaljvp 2 ай бұрын
I'm definitely gonna use that `o` visual mode trick
@pv3201
@pv3201 3 ай бұрын
Had no idea about o or using ex mode with . on a visual selection.
@heroe1486
@heroe1486 3 ай бұрын
Nice video, for fuzzy finding I personally use fzf-lua and Telescope, I have a script that spawns fzf-lua if I'm in my home directory (since way faster) and Telescope otherwise (with the smart-open extension that gives you a mix of old opened files, ones from the current directory etc, all of that weighted). But I recently discovered that you can have a whole "real" (like ranger or vifm) file manager inside of neovim, I'm thus now also using the yazi file manager inside of neovim, you can do everything from within it, cd, use zoxide, fzf, searching, and ofc copy/paste/cut/rename etc, it can even preview images. But I'm using neovim as an "IDE", so it's pretty much essential to have convenient navigation.
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
Nice setup. Yes, that's also what I found, when you use Vim as an IDE, you're well-advised to use Neovim with such plugins, esp. good navigation. For me, my (simpler) Vim setup works well
@TechJolt3d
@TechJolt3d 3 ай бұрын
Interesting, I'm just using netrw as my file manager in vim.
@007arek
@007arek 2 ай бұрын
There is a plugin `fm-nvim` that allows to spawn any predefined program inside a new buffer - lazygit, broot or ranger
@odanabunaga2505
@odanabunaga2505 2 ай бұрын
Would you consider making an overview of vim plugins that you find most useful in your everyday work? Or have I missed it ?
@mainframe9374
@mainframe9374 Ай бұрын
Interesting. Actually I use "w" and "W" constantly, it's basically one of my most used navigation ways
@Codigger-br2rt
@Codigger-br2rt 2 ай бұрын
How do I set up gvim to automatically load files that were opened when the editor was last closed each time I started it?
@mvargasmoran
@mvargasmoran 2 ай бұрын
I have relative and absolute numbers, so when I share my screen my team mates can point to the line they want me to go naturally (or in a way they are familiar with).
@EluLawlielt
@EluLawlielt 2 ай бұрын
Hi Sebastian, thanks for the tips! What is the colorscheme that you are using (is it maybe default vim? I am an nvim user after all...)
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
Not sure about the name; in oh-my-zsh I'm using the ZSH_THEME="afowler" (but I think with some modifications). I think Vim mainly adopts these. You can check out my Dotfiles, it's all there: github.com/sdaschner/dotfiles
@semanser
@semanser 3 ай бұрын
Is this some sort of plugin? I have relative line numbers enabled but don't can't get these sections/subsections stuff to work (2:04)
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
Yes, it's the 'wellle/context.vim' plugin
@miguelborges7913
@miguelborges7913 Ай бұрын
a in selections stands for "around'.
@markhunt6499
@markhunt6499 3 ай бұрын
Hello, Sebastian. Can you tell please which OS do you use?
@heroe1486
@heroe1486 3 ай бұрын
Arch + i3wm
@whym1here
@whym1here 3 ай бұрын
What font are you using? it looks nice.
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
That's JetBrains Mono
@soufianemssd
@soufianemssd 2 ай бұрын
Can you please tell me, what plugin are you using for creating snippets
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
It's called vim-snippets: github.com/honza/vim-snippets (though I think I forked it)
@vanvothe4817
@vanvothe4817 3 ай бұрын
Use control-[ instead ecs or remap caplocks
@zyriab5797
@zyriab5797 3 ай бұрын
Tap caps lock = esc Hold = ctrl Really nice ergo imho
@devshmsec
@devshmsec 27 күн бұрын
Could you please move the keylogger to above you? I think it will be better there.
@ishaankapoor933
@ishaankapoor933 2 ай бұрын
Which screen key software are you using?
@SebastianDaschnerIT
@SebastianDaschnerIT Ай бұрын
It's called key-mon
@joechea_
@joechea_ 3 ай бұрын
to select inside html tag vat 😁
@rodelias9378
@rodelias9378 2 ай бұрын
Nice vídeo. However, I think the dynamic snippets section should have better explanation.. I mean: how to really do it the way you just show us?
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
Oh ok, what part of it wasn't clear? You use a snippet plugins (I use honza/vim-snippets) and you expand them (per default I think it's )
@CyperN077
@CyperN077 3 ай бұрын
I map the left arrow key to ESC in insert mode and down to write the file in all modes,
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
Oh ok, that's an interesting one
@codingwithrendi
@codingwithrendi 25 күн бұрын
super coollllllll
@kendlemintjed7571
@kendlemintjed7571 2 ай бұрын
this is a great video, but you keystrokes are way to fast they need to linger a bit bc i can't keep up with them XD
@LukasSmith827
@LukasSmith827 3 ай бұрын
Luke Smith would be proud, by far the best vim video I've seen
@jaadus
@jaadus 3 ай бұрын
was kinda hoping you'd show how to create the snippets
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
Have a look at github.com/honza/vim-snippets , it's quite straightforward
@odanabunaga2505
@odanabunaga2505 2 ай бұрын
how did you make this split happen at 1:48?
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
You mean the lines inbetween the example titles that I created to show the contexts? That was just a high number (I think 100 or so), and o for creating a lot of newlines. Or do you mean this context-aware plugin in general? That'd be wellle/vim-context
@odanabunaga2505
@odanabunaga2505 2 ай бұрын
@@SebastianDaschnerIT Yes it's the plugin I was curious about! Cheers! Thanks for the tutorials, they are awesome!
@zodoturtle3779
@zodoturtle3779 28 күн бұрын
I strongly recommend against remapping of Caps Lock to Escape. When you do eventually switch computers, maybe trying to repair someone elses. Any keyboard remapping is going to make life difficult.
@SebastianDaschnerIT
@SebastianDaschnerIT 28 күн бұрын
That's right, but thinking in this limitation will sadly prevent you from a lot of optimizations that you can do on your system (starting with the keyboard mapping, over shortcuts, to shell setup). But yes, if portability is important to you, fair enough
@zodoturtle3779
@zodoturtle3779 28 күн бұрын
@@SebastianDaschnerIT My reality is that I eventually had to physically remove my Caps Lock key after removing the remap in order to stop trying to use it as an Escape key.
@zodoturtle3779
@zodoturtle3779 28 күн бұрын
I just use Ctrl+[ instead.
@fplove
@fplove 2 ай бұрын
After 25 years of use there are still vim tricks and commands I still don't know.
@gjermundification
@gjermundification 2 ай бұрын
0:28 `set nu rnu`
@anasouardini
@anasouardini 3 ай бұрын
7:23 I feel like I'm flying!! thank you.
@gjermundification
@gjermundification 2 ай бұрын
17:20 vim has its own sort, no?
@SebastianDaschnerIT
@SebastianDaschnerIT 2 ай бұрын
Oh yes, that's right. I'm just used to the Unix commands, I guess :)
@gjermundification
@gjermundification 2 ай бұрын
@@SebastianDaschnerIT The moment you bring a pipe to the equation shell is the way to go.
@adjbutler
@adjbutler 3 ай бұрын
that is all well and good... but how do you exit VIM? can someone just tell me!!!
@pldcanfly
@pldcanfly 3 ай бұрын
Pull the plug out of the wall. If on a laptop, wait for 2-12 hrs afterwards. (Please don't just power off your computer, bad things can happen...)
@sub-harmonik
@sub-harmonik 3 ай бұрын
I like "jk" =
@SebastianDaschnerIT
@SebastianDaschnerIT 3 ай бұрын
That's what I had in the beginning as well, but I like having a reachable Esc on my system anyway (hence on Caps Lock)
@yash1152
@yash1152 Ай бұрын
== i didnt know yet: * o: switch selection direction * snippets * fzf/explorer inside vim == i already know & use daily/prominently * relativenumber * :exe & :norm * C-v box visual mode * i/a: in/around * w/W * scripts, is it talking about :! ? == i know but disagree with: * Mapping Esc to Caps lock * %: jump to matching: finnicky & unpredictable
@yash1152
@yash1152 Ай бұрын
still missing things: * multi-cursor * change case of word/letter * how to specify case insensitive search (with / or ?) * paste as replace mode * :z to scroll current line to top is not working at times * sending neovim to background to run some command etc (no, i dont want to use ! exclamation) * move past the last character i.e. at the line end newline char (this often helps with `db`)
@mvargasmoran
@mvargasmoran 2 ай бұрын
How do I exit vim? 🤣
@TawaraboshiGenba
@TawaraboshiGenba 2 ай бұрын
Of course I know how to exit vim... It's sudo killall vim
@pustunt
@pustunt 3 ай бұрын
I wish I had no need to deal with VIM
@NostraDavid2
@NostraDavid2 2 ай бұрын
Just use Nano. It's fine if that works for you.
@pustunt
@pustunt 2 ай бұрын
@@NostraDavid2 both are usless, look aroud it's 2024 already
@andreasproteus1465
@andreasproteus1465 2 ай бұрын
Lose the talking head.
@onetwothree123-
@onetwothree123- 2 ай бұрын
About math, you don't need to increase/decrease number by one using or actually if you need for ex. increase number by 10, it will looks like this 10
@nekoill
@nekoill 3 ай бұрын
Even better than just relative numbers: try `set nu rnu` (exactly like this, single line, one `set`, two arguments)
@NostraDavid2
@NostraDavid2 2 ай бұрын
That's what he has though
@edward7555
@edward7555 Ай бұрын
👊 Promo_SM
@mvargasmoran
@mvargasmoran 2 ай бұрын
the i / a I would call it: Inside / Around. better nemonic
@morpheus4564
@morpheus4564 2 ай бұрын
thx. 🙏🏼 asciidoc script I have to steal;) from u
How To Become Better At The Keyboard
12:46
Sebastian Daschner
Рет қаралды 3,5 М.
10 Advanced Vim Features (You Probably Didn't Know)
21:47
Sebastian Daschner
Рет қаралды 66 М.
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
FOOLED THE GUARD🤢
00:54
INO
Рет қаралды 48 МЛН
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
thoughtbot
Рет қаралды 868 М.
Reacting to Controversial Opinions of Software Engineers
9:18
Fireship
Рет қаралды 2 МЛН
VIM, The Most HATED Text Editor of All Time
7:20
ForrestKnight
Рет қаралды 14 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 35 М.
Vim Tips And Tricks Some Of My Favorite Vim Commands
17:05
DistroTube
Рет қаралды 59 М.
SWE Stop Learning - The Rise Of Expert Beginners
49:09
ThePrimeTime
Рет қаралды 225 М.
50+  Vim Tips and Tricks from Beginner to Expert
42:37
The Linux Cast
Рет қаралды 58 М.
7 Amazing CLI Tools You Need To Try
18:10
Josean Martinez
Рет қаралды 227 М.
I Love Neovim But I WONT Use It | Prime Reacts
23:22
ThePrimeTime
Рет қаралды 107 М.
What Makes A Great Developer
27:12
ThePrimeTime
Рет қаралды 139 М.
AI от Apple - ОБЪЯСНЯЕМ
24:19
Droider
Рет қаралды 126 М.
MacBook Air Японский Прикол!
0:42
Sergey Delaisy
Рет қаралды 534 М.
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 719 М.
Мечта Каждого Геймера
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,5 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 2,4 МЛН