50+ Vim Tips and Tricks from Beginner to Expert

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024
  • This is an epic video that goes on for way too long, but it's done. There are over 50 tips here for Vim from some very beginner stuff to some more advanced stuff. Enjoy.
    Patreon - / thelinuxcast
    Liberapay - liberapay.com/...
    ===== Thanks to Our Patrons! ====
    Devon C. -- Tier 4 Patron
    Chris - Tier 4 Patron
    EastCoastWeb - Tier 4 Patron
    Gentoo is Fun Too- Tier 4 Patron
    Marcus B. - Tier 3 Patron
    Maeglin - Tier 3 Patron
    Sven C. - Tier 3 Patron.
    Jackson Knife and Tool - Tier 3 Patron
    Joshua Lee - Tier 3 Patron
    Mitchel V - Tier 2 Patron
    ArchSinner - Tier 2 on YT
    Marek M. - Tier 1 Patron
    Camp514 - Tier 1 Patron
    Mr. Fox - Tier 1 Patron
    ===== Follow us 🐧🐧 ======
    Odysee - odysee.com/$/i...
    Mastadon - @drmdub@distrotoot.com
    / thelinuxcast
    / mtwb
    github.com/mtwb47
    Subscribe at thelinuxcast.org
    Contact us email@thelinuxcast.org
    #vim #tipsandtricks #thelinuxcast

ความคิดเห็น • 129

  • @TheLinuxCast
    @TheLinuxCast  3 ปีที่แล้ว +12

    Two things. As Umka said below. yw will yank from the cursor position to the end of the word, similar to cw. Also, the first tip (vim filename + Line number ) seems to only work some of the time for some people. Very unreliable, and seems to depend a lot on your vimrc.

    • @interakctif2540
      @interakctif2540 2 ปีที่แล้ว +4

      Your 1st tips seems incorrect: there should be no space between the `+` sign and the number. So, instead of `+ 34`, you should write it as `+34`. For sure it will work.
      'Love from Indonesia'

    • @mathiaslueer
      @mathiaslueer 2 ปีที่แล้ว +2

      `vim .zshrc -c:100` will bring you directly to the line you want no matter what you have configured

    • @jongeduard
      @jongeduard ปีที่แล้ว

      @@interakctif2540 I noticed it to. Space should not be there, otherwise it works perfectly. When I do it with a space, basically making it 2 separate command arguments for vim, the file is opened at the last line, just like in the video happened (I don't know why that happens by the way).

    • @Gett37
      @Gett37 11 หลายเดือนก่อน

      Use yaw to yank-a-word no matter where your cursor is. yaw, daw, caw are very useful

    • @icetmzz9074
      @icetmzz9074 11 หลายเดือนก่อน

      Do you use qwerty or any other alternative layout?

  • @CyberBoy8799
    @CyberBoy8799 3 ปีที่แล้ว +33

    As someone who is learning vim, I find this super useful. Great video!

  • @bjorn7696
    @bjorn7696 3 ปีที่แล้ว +22

    I learned a few things! 😀
    But I also wanted to point out that in the sed like search and replace (:%s), the % means 'the whole document' and the 'g' means multiple replacements on 1 line. You can run it on just the current line without the %.

    • @josephsmy1994
      @josephsmy1994 2 ปีที่แล้ว +7

      "...and without the g means just the first match on the line" ;)

  • @nhojllahsram7808
    @nhojllahsram7808 2 ปีที่แล้ว +7

    I had a big smile on my face when you admitted it was a lot at the end. things like vim are so amazing and wonderful to learn because you can STILL BE DISCOVERING TRICKS AFTER YEARS!!!(At least I am!) Anyways, keep on being awesome. Thank you so much for this. Really enjoyed learning.

    • @no_name4796
      @no_name4796 2 หลายเดือนก่อน

      Yeah i used neovim for 2 years, and while i now can use it pretty fast, and know most thing, i costantly descover new bindings or command or things i never knew
      Like few days ago i randomly descover that ctrl+6 allows to switch to last used buffer. A very useful binding!

  • @batchrocketproject4720
    @batchrocketproject4720 24 วันที่ผ่านมา

    Some useful stuff there, thanks for sharing. I watched over a few days, taking notes (in vim) and testing each as I went along. One or two didn't seem to work in my vim (some initially because I was not doing them properly), but it's still useful to know of the features for future reference when needed.

  • @morty1317
    @morty1317 3 ปีที่แล้ว +7

    Great work!!!!
    Waiting for the next 50

    • @TheLinuxCast
      @TheLinuxCast  3 ปีที่แล้ว +9

      I'm still exhausted from this one, LOL

  • @marcelangulo510
    @marcelangulo510 หลายเดือนก่อน

    I really apreciate all your videos. Thanks for sharing your knowledge

  • @umka7536
    @umka7536 3 ปีที่แล้ว +12

    yw copies letters from cursor to the end of the word. Not full word. To copy full word in the middle of it: yiw. The same for changing. If you are in the middle of the word, then cw will delete part of word from cursor to the end of the word and goes into INSERT mode. To change word from any position in it - use ciw.

    • @TheLinuxCast
      @TheLinuxCast  3 ปีที่แล้ว

      Yeah, I always forget that y works like c. Thanks for that.

    • @thingsiplay
      @thingsiplay 3 ปีที่แล้ว +3

      Also `ye` will only copy the word and `yw` will copy the word and the space.

  • @umka7536
    @umka7536 3 ปีที่แล้ว +2

    It is never enough VIM videos! Thanks!

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars 3 ปีที่แล้ว +6

    1) 14:27, adding "g" to the substitute command does not change the word globally, the reason it changed was because of "%", which specifies the range and means entire document, what "g" actually does is, it changes multiple instances of the specified word on the same line.
    e.g:
    ```
    lorem ipsum lorem
    lorem ipsum lorem
    ```
    ":%s/lorem/what/gc", the "%" is range(global), "g" changes multiple instances i.e all "lorem" will changed to "what" on single line", and "c" is for confirmation, "y" to change "n" to skip and go to next instance :)
    2) Also, "%" contains the filename of active buffer, so you could just ":source %" to source the current file, I mainly use it to run my bash/python script without opening another terminal
    e.g
    ```
    #!/bin/bash
    echo hello
    ls
    ```
    to execute I do, ":!chmod +x %" to give it executable permission and then either ":!./%" or ":!bash %" to execute it.

    • @bjorn7696
      @bjorn7696 3 ปีที่แล้ว

      I already commented that! 😀

  • @iAmTheWagon
    @iAmTheWagon 3 ปีที่แล้ว +4

    Vim was painful at first, and I kept putting it off, but after building some muscle memory it became addictive and now I don't wanna use any other editor or IDE.

  • @Pidgethate
    @Pidgethate ปีที่แล้ว

    I love your approach man! Thank you for taking us with you during the exploration and explanation of vim. Regards from the Netherlands.

  • @jairunet
    @jairunet ปีที่แล้ว +1

    Dude, excellent tutorial, very clear and with great references, I appreciate it, and keep up the good work. All the very best my man!

  • @emuel5844
    @emuel5844 2 ปีที่แล้ว +2

    Such a valuable video for both beginners and experts!

  • @sundarbe
    @sundarbe 2 ปีที่แล้ว +9

    At 31:15, the | symbol means "or" in regular expression. You escape it with \ and get \|. So when you type "/word1\|word2" what you are saying is "Search (/) for *word1* or(\|) *word2*". After that you are using regular expression "^\s*$" what this means is that "From start of line (^) look for zero or more (*) space characters like tabs, space, carriage return, new line etc., (\s) till end of line($)", this pattern will match all empty lines.

  • @machman23
    @machman23 2 ปีที่แล้ว

    Watched all the way through, I'm learning vim but emacs is what I use. I use Emacs more for journalising, note keeping and organizing so I might employ evil mode to gain some vim functions. Cool tips thankx

  • @nokiacthree809
    @nokiacthree809 ปีที่แล้ว +1

    Thank you. Hi from India. appreciate your effort.

  • @Nukelover
    @Nukelover 3 ปีที่แล้ว +7

    :g/^.\s$/d is a regular expression. It's saying from the beginning of the line (^), find all non-printing characters (.\s) all the way to the end of the line ($) and then delete all such lines globally (:g/.../d). The only thing that matches that expression are lines with nothing visible in them -- blank lines. Btw, gf was boss mode. :)

    • @nomadvagabond1263
      @nomadvagabond1263 2 ปีที่แล้ว +1

      Its not what he used. He used ^\s*$ which means to match any empty or a line that contains spaces. Urs look funny. It matches lines that contain any character followed by a space. (.) Means any 1 character including
      and space.

  • @hyperthreaded
    @hyperthreaded 6 หลายเดือนก่อน

    Actually the g in :%s/static/whatever/g makes the "s" command (which works on a line, not on the whole file) replace all occurrences of "static" on the *line* the command is working on, rather than just the first occurrence. The "%" at the beginning is the thing that applies the s command to all lines in the file. (if you leave out the %, s will only be run once, on the current line; or you could use e.g. .,$ instead of % to run the s command on all lines from the current line to the end of the file) So basically the expression before the "s" tells vim on which lines to apply the "s" command, and the letters behind the last "/" tell "s" what to do on each line it's applied to.
    It's kinda logical and makes sense, but it really takes some time to grok it all. 😎

  • @xila8861
    @xila8861 4 หลายเดือนก่อน

    Such a good tutorial.

  • @CyperN077
    @CyperN077 3 ปีที่แล้ว

    Always some things to learn. Good video. I think I'll youtube-dl it for future reference.

  • @rism8345
    @rism8345 2 ปีที่แล้ว

    Exactly what I needed. Thanks!

  • @iAmTheWagon
    @iAmTheWagon 3 ปีที่แล้ว

    Excellent information and presentation

  • @diegonavia1404
    @diegonavia1404 2 ปีที่แล้ว

    I loved this video, Im learning vim and this is super fun. Greetings from Chile

  • @bg4801
    @bg4801 3 ปีที่แล้ว +2

    Thanks for this video. Need to learn vim and this is great.
    Im still trying to find a way to copy with the mouse in a terminal with two vertical panes and it only copies from one pane. =(

    • @TheLinuxCast
      @TheLinuxCast  3 ปีที่แล้ว +2

      If you're talking about splits, the yy and p bindings will copy and paste between the two buffers.

    • @mathiaslueer
      @mathiaslueer 2 ปีที่แล้ว +2

      If you really want to learn vim forget that mouse exists mouse. to use the mouse is a anti pattern in vim ;)
      you can switch to visual mode with v(character), Shift+v(line) or Ctrl+v(column). mark what you wish to copy and press y to copy. Press Ctrl+w Ctrl+w to jump to the other split and press p to insert. thats it

  • @jd-dev
    @jd-dev ปีที่แล้ว

    Thank you! I learned so much

  • @thedeparted_one
    @thedeparted_one ปีที่แล้ว

    I just wanted to say thank you.

  • @mazharkhaliq1971
    @mazharkhaliq1971 2 ปีที่แล้ว +1

    Thanks

  • @Gett37
    @Gett37 ปีที่แล้ว

    This is awesome and very useful, thank you

  • @BrucesWorldofStuff
    @BrucesWorldofStuff 3 ปีที่แล้ว

    Well I did set and watch it all. Only nodded off once and I noticed my beard was longer... LOL
    As I was watching this I kept feeling you make this video for me. I know silly me while I'm special, I'm not that special. :-P
    I never get through the vimtutor I try and just give up, bad brain cells or something...
    Wow, 100 tips that scares the hell out of me both in commands and a 2 day video... Lol
    Thanks for the video Matt!
    LLAP

  • @EPICfranky
    @EPICfranky 4 วันที่ผ่านมา

    very useful!

  • @anjalimesh
    @anjalimesh 2 ปีที่แล้ว

    Excellent work

  • @maguilecutty
    @maguilecutty 10 หลายเดือนก่อน

    Also when u realise every action can be done w every motion. Ie cb cuts the word behind the cursor, dh deletes the letter to the left. Also action a is also rad. Cut around { ca{ will cut your whole function

  • @keithturnas6456
    @keithturnas6456 2 ปีที่แล้ว

    Great video!!! I learned much

  • @SharifTarek
    @SharifTarek ปีที่แล้ว

    thanks a lot ya pro

  • @seaseasee
    @seaseasee ปีที่แล้ว

    appreciate the great effort

  • @jasonfreeman8022
    @jasonfreeman8022 ปีที่แล้ว

    diw and daw. diw deletes all word characters from within the word regardless of cursor position. daw deletes all word characters and surrounding witespace (i.e. it is "all" inclusive). This is true for change, yank, visual selection, and likely some I'm forgetting. Alternate jump to line is 123G (123{shift}g). That will jump to line 123.

  • @jeffreymagedanz8130
    @jeffreymagedanz8130 2 ปีที่แล้ว

    ZZ - To my frustration, I regularly quit vim by accident, and could
    never figure out why. Watching this video, I realized that ZZ is what
    I've been accidentally typing all along.

  • @derFeind
    @derFeind 2 ปีที่แล้ว

    very very helpful thank you!

  • @Skatox
    @Skatox ปีที่แล้ว

    Nice video! I loved it.

  • @MajinHico
    @MajinHico 2 ปีที่แล้ว

    Thank you

  • @alexisbatyk6301
    @alexisbatyk6301 ปีที่แล้ว

    ¡Gracias!

    • @TheLinuxCast
      @TheLinuxCast  ปีที่แล้ว

      ¡De nada! ¡Gracias por el Súper Gracias!

  • @ККЂК-р4щ
    @ККЂК-р4щ 2 ปีที่แล้ว

    Can u provide pdf of theses commands

  • @xydez
    @xydez ปีที่แล้ว

    31:11 it's regex

  • @VulcanOnWheels
    @VulcanOnWheels ปีที่แล้ว +4

    2:09 I believe the problem you're having because of the space between the + and the number. If you don't add the space it should work.
    7:30 They're called braces.
    26:28 That's in ascending order. I see you uploaded this video about a year ago. I hope you have overcome your nervousness since then.
    27:23 Not really, because Vim did exactly what you told it to do; it saved the file under the new name.
    31:11 Maybe Derek Taylor aka Distrotube can tell you.
    32:54 You don't need the + here.

  • @gokulp6878
    @gokulp6878 2 ปีที่แล้ว

    How to select some group of of lines in visual block mode .For example, I have 1000 lines of code I want to select only 500 to 700 lines (without scroll the mouse).Please explain

  • @TheRealFrankWizza
    @TheRealFrankWizza 3 ปีที่แล้ว

    My arrow keys type letters in vim. As such I don't use it. I know that can be changed, but I haven't bothered. I use nano.

    • @TheLinuxCast
      @TheLinuxCast  3 ปีที่แล้ว

      Mine do too. That's why I use the vim keys.

    • @TheRealFrankWizza
      @TheRealFrankWizza 3 ปีที่แล้ว

      @@TheLinuxCast Fair enough. I should probably check out a VIM basics tutorial and jump back to this.

  • @zeocamo
    @zeocamo 3 ปีที่แล้ว +1

    :source % ... source the current file ... or :so % do the same thing
    edit: for many of us that use lua now, it is :luafile %

    • @zeocamo
      @zeocamo 3 ปีที่แล้ว

      @Terminalforlife (LL) yes that is true, things like plugin systems, don't like to be loaded again and again ... and now i gluss it is more like :luafile % ... because we all convert to lua by now

  • @intermsofreality
    @intermsofreality 2 ปีที่แล้ว

    Useful stuff but would've probably been better served in chunks of separate videos. No way I'm going to remember all of this in a single sitting.

    • @TheLinuxCast
      @TheLinuxCast  2 ปีที่แล้ว

      Yeah, if I were to ever do more, they'd be in a smaller video. I did another with 10 tricks. This one took way too much time and you're right it's hard to digest.

  • @windowsrefund
    @windowsrefund 2 ปีที่แล้ว

    Just so you have it handy, you can refine that global remove all blank lines with :g/^$/d
    The ^$ is just a regular expression matching lines that only contain a beginning (^) and end ($). All lines matching that regex of ^$ will be deleted as you've pointed out.

  • @ArtemCYOU
    @ArtemCYOU 2 ปีที่แล้ว

    у меня уходит около 4-5 часов на съёмку одного видео без остановки, но спасибо за выпуск)

  • @aryakiran256
    @aryakiran256 3 ปีที่แล้ว

    emacs4life

  • @ChrisCox-wv7oo
    @ChrisCox-wv7oo ปีที่แล้ว

    :g/^\s*$/d
    ^ is beginning of line anchor
    \s is any whitespace character
    * is quantifier meaning 0 or more
    $ is end of line anchor
    Delete all lines that have 0 or more white space, and they have no other characters

  • @christopherexline6247
    @christopherexline6247 2 ปีที่แล้ว

    Should be: vim +34 config.def.h

    • @christopherexline6247
      @christopherexline6247 2 ปีที่แล้ว

      could also be vim config.def.h +34: no space between plus and the number

  • @sepehralimohamadi5310
    @sepehralimohamadi5310 2 ปีที่แล้ว

    This was amazing, thank you for very helpful video

  • @JuanVqz
    @JuanVqz 3 ปีที่แล้ว +6

    16:53 you can use :source % where % means the current path to the file

    • @matiasbpg
      @matiasbpg 3 ปีที่แล้ว +4

      Or so% for that matter!

  • @keithturnas6456
    @keithturnas6456 2 ปีที่แล้ว +1

    g/ global
    ^\s*$ is regular expression
    (^ is beginning of line
    \s* is a line with 0 or more spaces
    $means end of line)
    /d is delete

  • @paulnuker1831
    @paulnuker1831 ปีที่แล้ว +2

    It's better to use : instead of / for the substitute command, then it's not as confusing when you get a bunch of escaped characters. Easier to keep track of the different sections when there's a colon to look for 👍

  • @johndescy5814
    @johndescy5814 2 ปีที่แล้ว +1

    !sort calls sort on the shell. However Vim has it's own builtin sort fuction, so the ! is not necessary. Furthermore sort n will sort numerically.

  • @fahimabrar2922
    @fahimabrar2922 3 ปีที่แล้ว +1

    Do a live stream on how to configure & rice vim/ neovim please.

  • @Codigger-br2rt
    @Codigger-br2rt 6 หลายเดือนก่อน

    Recently, it was discovered that there was a significant delay in opening vim. log the opening process of vim, found that the total time is 603.661 ms, the time is sorted (sort-nrk 2), I found that opening buffers and VimEnter autocommands take a large proportion of time. The value is above 100ms.
    How to optimize this problem?

  • @penvzila
    @penvzila 27 วันที่ผ่านมา

    As someone who has used vi and vim for almost 30 years I have one tip: don't fucking bother with it. Know how to use it. But don't force yourself to use it when you don't need to.

  • @skafiend4319
    @skafiend4319 10 วันที่ผ่านมา

    :D my head exploded in the middle of the video, so I took a break. great video, thank you

  • @ricardorien
    @ricardorien 3 ปีที่แล้ว +1

    Vim videos are always welcome! Greetings from Venezuela.

  • @go6obg92
    @go6obg92 2 ปีที่แล้ว +1

    Thank you! I learned a lot. This really motivated me to keep learning VIM

  • @thegameoflife9179
    @thegameoflife9179 ปีที่แล้ว

    Vim can clean your bathroom... just press cb in Normal mode

  • @gjermundification
    @gjermundification ปีที่แล้ว

    0:04 You mean insert mode? Where vim behaves like a text editor.

  • @FrasSmith
    @FrasSmith 3 ปีที่แล้ว +4

    Some great tips here. I've been using vim and before that vi for almost 30 years now and I'm still learning new tricks. :-) My best vi story however comes from the early 90s. A programmer colleague was showing off his newly learned juggling skills at work one day. It turns out that he wasn't as good as he thought and one of his juggling balls fell and bounced off his keyboard. 5 5 d d. Oops.

  • @hasanalattar9561
    @hasanalattar9561 ปีที่แล้ว

    u can count the tips using vim

  • @Gett37
    @Gett37 ปีที่แล้ว

    For some reason this video is not in your vim playlist

    • @TheLinuxCast
      @TheLinuxCast  ปีที่แล้ว +1

      The video was created before the playlist. I'll add it to it now

  • @ke30_
    @ke30_ 2 ปีที่แล้ว

    Thank you for this, very helpful!

  • @johndescy5814
    @johndescy5814 2 ปีที่แล้ว

    You can delete (or change or whatever) inside a word like you change inside brackets or braces. Just add i to your command. diw deletes the word you are in the middle of.

  • @maguilecutty
    @maguilecutty 10 หลายเดือนก่อน

    C is actually cut which is incredible to realise cause copy asta becomes incredibly powerful

  • @gjermundification
    @gjermundification ปีที่แล้ว

    Nice to see vim tips by different people, there are always new attack vectors to learn.

  • @crazychicken0378
    @crazychicken0378 3 ปีที่แล้ว

    This video made me realize I don’t play around with vim enough. It needs to change, good vid

  • @smsrivastava100
    @smsrivastava100 2 ปีที่แล้ว

    Thanks for the tricks brother! Love from India

  • @mohammedalbatati5529
    @mohammedalbatati5529 2 ปีที่แล้ว

    Many thanks, that was great informative video

  • @V7x
    @V7x 2 ปีที่แล้ว

    w = one word forward and b = one word back!

  • @lubeckable
    @lubeckable 2 ปีที่แล้ว

    esta bonito tu terminal compa

  • @ebmpinyuri
    @ebmpinyuri 2 ปีที่แล้ว

    good video , very helpful

  • @BluePhantomGames
    @BluePhantomGames 2 ปีที่แล้ว

    yw,cw,ci and dw was very useful

  • @TrueWordsOfEternity
    @TrueWordsOfEternity 3 ปีที่แล้ว

    R u the new prime :)

  • @OliNorwell
    @OliNorwell ปีที่แล้ว

    Great video, nice pace and well explained.

  • @oneanime5551
    @oneanime5551 3 ปีที่แล้ว

    amazing!

  • @markring40
    @markring40 2 ปีที่แล้ว

    Thank you! Thank you! Thank you!

  • @lohanguedes6413
    @lohanguedes6413 3 ปีที่แล้ว +1

    Keep on the good work man! live your videos! I would love to see one about gimp or photogimp

  • @mehdikhawari8830
    @mehdikhawari8830 3 ปีที่แล้ว +6

    Most of vim-users end up switching to emacs

    • @umka7536
      @umka7536 3 ปีที่แล้ว +18

      Not really. :)

    • @oneanime5551
      @oneanime5551 3 ปีที่แล้ว

      why?

    • @bjorn7696
      @bjorn7696 3 ปีที่แล้ว +21

      I've been a vi/vim/nvim user for 22 years... When do you recon my due date to switch to emacs is?

    • @MrCradleman
      @MrCradleman 3 ปีที่แล้ว

      @Terminalforlife (LL) Never say never) I also thought so) But I tried emacs + evil and this is so much customizable, vim will never have such customization level)

    • @leonvolq6179
      @leonvolq6179 8 หลายเดือนก่อน +2

      Not sure If your trolling or not but that was funny 😂

  • @chonky_ollie
    @chonky_ollie ปีที่แล้ว

    “You can use ‘i’ like Neanderthal, or rather use ‘a’” 😂😂😂😂 dude you’re amazing