Vim Advanced Tutorial Videos

  • :help :g tells you all about the :global command, which is an extremely powerful command-line tool.
  • :help :v tells you that it’s the inverse of the :g command.
  • :help :s talks about the substitute command… oh so powerful.
  • :help :/\( is the aspect of regular expressions we use to create subgroups that are remembered.
  • :help /^ is the way we anchor a regular expression to the beginning of a line.
  • :help /\{ describes how to put “counts” into regular expressions so we don’t have to repeatedly enter characters; we just say how many times they repeat.
  • :help /[ ] lets us specify a collection of characters. Sometimes that collection is merely a collection of things that are “not” something else, which is denoted by [^.
  • :help /\zs lets us make a more specific “start” to a regular expression with respect to its substitution – very cool.
  • :help :normal lets you execute normal-mode commands from the command-line.
  • :help :t tells you about the synonym for the “copy” command.
  • :help search-pattern is a very long and very important section on how to use regular expressions in Vim. Study.

Page 2 of 2 | Previous page

41 comments on this post.
  1. Ludvig Ericson:

    Nice videos – I especially love how you’ve made tutorials for advanced users.

    Watching the Vim registers tutorial I noticed your Python script could be reduced so as to be a lot more elegant, this:

    from uuid import uuid4
    print uuid4()

  2. Ludvig Ericson:

    OK, so I should have probably watched until the end of it. :D

    Anyway, at least use str(uuid4()) – __str__ isn’t something you want to be accessing from outside of the class itself, for a number of convoluted reasons.

    Also, wouldn’t it be possible to do this somehow using the Python support in Vim? I don’t see how to get it to evaluate a Python expression though.

  3. Derek Wyatt:

    There are probably a ton of ways it could be done, all of them better than what I did :). The python code was just a vehicle to demonstrate the Vim functionality and to that end, I think it served its purpose.

  4. Tweets that mention Vim Advanced Tutorial Videos - Derek Wyatt's Blog -- Topsy.com:

    [...] This post was mentioned on Twitter by Kevin Colyar, Derek Wyatt. Derek Wyatt said: New #vim video: Globals, Command-Line and Functions. Check it out at http://bit.ly/d3K6EH [...]

  5. Jens K.:

    You’re back! Eeeeeeeek!

    Very amusing and very informative tutorial.
    Keep up with your absolutely great tuts!

  6. Pascal:

    Finally!!
    I have been wyatt-vim-tutorial deficient for months now!

    Very thankful again for the light-hearted view on VIM.

    P.S. Why are there no keystroke indicators in this movie. I love those.
    I guess you want to hide the fact you use the arrow keys to navigate. Mmm. Derek!?

  7. zl0y:

    Great! It’s awesome!!!
    I love you, Derek!
    I love your videos!
    I love vim!
    I love!

  8. Derek Wyatt:

    No keystrokes because this is “advanced” :) Well… not really. This one’s about the command line, so you can read everything I’m doing anyway, and the duplicity in the keystroke echoing would probably just get in the way. When I do a lot of Normal-Mode work, I’ll definitely be putting up the keycasting.

  9. Knowuh:

    So glad I found your blog.

    Its like what you would get if broccoli tasted like chocolate.

    Bushy dendrites, squirts of dopa, and a smile on my face.

    Thanks!

  10. ktr:

    Great videos, thanks for doing them. One other thing you might be interested in instead of “redirect” is q: in normal mode. It brings up your history which you can navigate as you would expect. If you hit enter it executes that command, or Ctrl-C Esc to not do anything. But you could q: to view the history, jjjj up to the line you want, yG to yank to the end of the history, Ctrl-C Esc to get back to your file and p wherever you want to paste. Note that ‘q/’ and ‘q?’ also work. I just found out about it recently and love it. Just one alternative that might be interesting. Thanks again!

  11. Derek Wyatt:

    Thanks Kevin. You’re right, the q: would be better for that one particularly and I probably should have mentioned it. The main goal for using the :redir method was to introduce and show the :redir command but the q: method is better. I will probably be doing a piece on “command line editing” soon to showcase that particular feature specifically.

    Thanks for watching, and the tip!

  12. ktr:

    Wait, whoops! You were doing command line – not normal mode. q: won’t work :( sorry for confusion!

  13. ktr:

    sorry, i’m out of it today … as you mentioned, it would. but understand your reason for not doing it. sorry …

  14. Derek Wyatt:

    Naw it’s cool. Your method is better and for what I was _doing_ it would have been better. But :redir is so much more applicable in general, I got a bit more bang for my “tutorial buck” there.

  15. Hannes:

    Hellz yeah!

    Thanks once again for a great video, Derek!

  16. edit:

    wow. just, wow.

  17. Loco Screencast Vim 4: Visual Mode « Lococast.net:

    [...] http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-advanced-tutorial-videos/#globals-commands-fun… [...]

  18. mcai8sh4:

    Another really great lesson! Entertaining and educational, the way the world should be. It’s great to see how vimsperts(?) do things, compared to how I would go about a similar task.

    I appreciate how much time and effort it must take for you to do these tutorials, (well the video ~20mins – but I mean the planning…) We all (humankind) appreciate your teachings.

    Thank you.

  19. Charlie Flowers:

    Dude, this is developer porn. And it never gets old … especially the mind map video. Thanks. Vim is simply stunning.

  20. kstep:

    In “find command and path” autosetting “path” option code you use “exe”, but what if dirname contains spaces? You can of cause escape them, but it’s better to use “let” in this case.

    I.e. instead of:
    exe “set path=”.code
    write this:
    let &path=code

    And you are done! No need for “execute”, and this code is bulletproof, no matter what “code” variable contains.

  21. Pen:

    What is the command you used for indentation? *equals g* ???? doesn’t seem to work for me.. and you didn’t include it in final script either..

  22. Derek Wyatt:

    =G, not =g

  23. Pen:

    thanks, worked like a charm..

  24. kirobee:

    What exactly happens when using :g/^\w/t.|s/./=/g ??
    I don’t get what :copy does and what exactly does the |? Why does s/…/g only operates on that line?

  25. Derek Wyatt:

    Let’s see… First, make sure you consult the help topics on these things. Now…

    :g/^\w/ matches all lines that start with a word character. If it starts with a space or some other non word character then it won’t be matched by this

    The ‘:g’ command then runs the command it’s given on the matched line, which is ‘t.’. That copies the matched line and puts it below the current line (again, the matched line).

    The ‘|’ chains another command to the ‘t’.

    So, the substitute (s/./=/g) operates on the copied line. And the substitute merely replaces every character with an equals sign.

    i.e. All of that creates an underline for the matched line that is the exact same width as the line that was matched.

    Now… go read the help :)

  26. kirobee:

    I had some slight trouble while trying to use t. in the normal mode, what obviously didn’t work. When I got some sleep it came to me :).

    It seems that the pipe | much work like on the command line. I wasn’t sure about the scope of the substitution.

    >Now… go read the help :)
    Got me. Didn’t tried to hard. The help is really monumental ^^.

    Thanks and really great work. I’ve learned alot!

  27. fifou:

    Hi!

    I now have a few years experience with Vim but I see all your videos because you’re funny ^^

    I’m no more a beginner but your video “Globals, Commands and Functions” impress me! Thank you for your great work!

  28. Jason:

    Thanks for doing this! These videos have been fun to watch and a great help.

  29. kymnyth:

    Can you provide the xml that was used for the final tutorial. i.e. freemind xml I would like to work my way through what you did here but you were really quick and starting with what you started with would be very helpful.

  30. Derek Wyatt:

    Sorry man, I don’t have it. It’s dead easy to get some XML though; just download freemind, make a map, and hit “save” :)

  31. Norman:

    Great stuff!

    I really learned a lot from this!
    Thanks!

  32. Rick:

    Hi Derek, I’ve financially contributed to you and really appreciate your spirit and knowledge. Can you give me an “overview” solution to this problem?

    A 4,000 line document with 4 “categories” (say, 1,000 lines of a main category). Within each of these sections there are 5 more repeating bits of information (say, sub-category information). I need to save the individual sub-category information and append to each of them some information obtained from it’s parent category.

    So, I can :g/find-a-main-category-line-using-regexps/s/collect-submatch-info/\=save-that-info-by-calling-a-function

    My intellectual struggle is on how to drop down through the next ~1000 lines within that category to pickup the desired sub-category information. I see only two options, but I think I am missing the best one:

    1). I can extend the original regexp (that finds the main category info) and make it discover the lower sub-category information all at once – then bulk save them together. This would mean a seriously long regexp, which is fine if that’s the best method.

    2). I can collect each main category into a register, then act upon that register by passing it back into a another substitute/submatch query. Under this approach I would probably need to repeat that method again in order to separate the lower sub-categories from each other.

    What I “feel” that I SHOULD be able to do is search for the main categories (as described above) and then – once found – continue down (like a sub-search) into the sub-category information, until it finishes collecting the information before proceeding to and through the next main category. I can only get the query that finds the main categories to run through all of the main categories (and not “stopping” to gather the sub-category information – essentially losing my ability to discover the sub-category information IN RELATION to the main category in which it resides.

    Yikes, sorry for the verbosity. Any “guidance” or “direction” would be much appreciated.

  33. Derek Wyatt:

    @Rick

    I’m having a tough time visualizing the problem. Can you post something to http://gist.github.com so I can see it?

    If the text is structured (as you seem to indicate) this may be a candidate for a macro or a function, depending on whether this is a “one off” or something you want to do more often.

    One thing I can suggest is to try and “:copy” the data to the end of the file as you accumulate what you want and then work with it from there. It might be easier to deal with when you’ve put it into a known location with a known format.

    But, if you post to gist then I’ll be able to think about it much easier.

  34. Rick:

    Unfortunately, its confidential information. I am not at liberty to post the 4k line document. In fact, it is 100 documents of this size (yikes), but I have the vim netrw with elinks that will incrementally loop through the 100 webpages and dump the contents of each into a vim buffer (nice) for them to be parsed by the code I am inquiring about – before proceeding to the next.

    But, yes, each document is consistently formated and conducive to capturing the information through regexes – that’s the upside. Here’s a visual:

    This is category A, Section 10:
    …maybe 200 lines of stuff I don’t need….

    Company 1 Info
    Company 1 People
    Company 1 Projects
    …maybe 100 lines of stuff I don’t need…

    Company 2 Info
    Company 2 People
    Company 2 Projects
    …maybe 100 lines of stuff I don’t need…

    Company 3 Info
    Company 3 People
    Company 3 Projects
    …maybe 100 lines of stuff I don’t need…

    Company 4 Info
    Company 4 People
    Company 4 Projects
    …maybe 100 lines of stuff I don’t need…

    This is category B, Section 11:
    …repeating (categorically) again 4 more times…

    All of the lines are very consistent and easy to find via regular expressions. The problem is that I need to build an end result of:

    CatA,Sec10,Company1:People1:Projects1
    CatA,Sec10,Company2:People2:Projects2
    CatA,Sec10,Company3:People3:Projects3
    CatA,Sec10,Company4:People4:Projects4
    CatB,Sec11,Company5:People5:Projects5 <–and so on

    This means I need to collect the Category and Section from the main category heading (easy) and then apply that to the sub-categories below it. I can easily capture the category information and I can easily capture the sub-category information – due to the consistency of the format and naming conventions. And, I can easily reformat the captured data and output it to a new file that will be good for uploading it to where I want it. I am (intellectually) failing at tying the two search/captures together in order to keep their association.

    Thank for the quick response, Derek. :)

  35. Derek Wyatt:

    If all you need to do is stitch a couple of things together then a macro or a function would do just fine. Once you’ve got that, you can just call it as much as you need to get things done.

    Another way to go would be to wreck the buffer. Check the destruction video (start around 1:50) – Destruction.

    If you wipe out all of the stuff you don’t need, and then append the ‘,’ and ‘:’ to the ends of the lines, then just join everything up. Again, toss that in a macro or a function, make the call and you’re done.

  36. Vídeotutoriales sobre Vim | CyberHades:

    [...] creados por el autor de dicho blog. Están divididos en cuatro categorías: principiante, medio y avanzado. También tiene otra serie en la que nos muestra el uso de algunos [...]

  37. Arkadiusz Hiler:

    Getting history the way you did is a bit of pain in the ass. I recommend you to try q: in normal mode or c_ctrl-f. All Visual mode goodies works there, you can yank easily interesting part or even execute stuff with simple hit.
    I saw q: disabled (due to common mistyping :q) in lots of .vimrcs. Kinda sad.

  38. Dave:

    Hi Derek,
    great stuff you provide! Many thanks :)

    I installed your neat protodef plugin – and I enjoy it very much. However, class free functions do not get pulled in the implementation file.
    Is there a trick I’ve missed?

    Cheers,
    Dave

  39. Derek Wyatt:

    It probably doesn’t work :) I don’t recall trying that for quite a while and all of my coding these days is in Scala so I don’t use it much. If you can build a fix for it, then I’ll definitely take a pull request on GitHub. Otherwise, you’re going to have to wait for me to get back into some C++, which I might be doing in a few months when I get back to some mobile development.

  40. Vim «:

    [...] Vim advanced tutorial videos [...]

  41. Thanassis:

    Wow – I thought I knew enough VIM to be very productive… but your videos showed me what a real VIM expert can do. Humbled and grateful – keep it up!

Leave a comment