..

How to vim

Description

Short version (200 chars)

Want to start viming your way around? Here’s a good place to start

Long

To be done

Presentation

Contents

How to vim

Basics and not so basics for future vimers

Why vim?

First things first

You can exit by typing :q!

Modes

Vim has different modes. We’ll cover some of them here

Normal mode

It’s the default mode, and where you can move around. You can use these to move the cursor:

Now we can combine number and letters (omg why? just because we can)

But maybe you want to move more in a line… That’s ok

Enough with lines. You wanna move more

Insert mode

Now that we know how to move, we can start editing right? Okay, alright? I get it.

You can use a bunch of different things to start editing

Visual mode

We can visually select things

More normal mode stuff (Operators)

While we’re talking about copying and pasting, we can talk about pasting from the clipboard (not from vim) You should enter insert mode and use OS paste command (ctrl+v or cmd+v)

Combining things

You can combine things to make your life a bit easier

Searching for patterns

I need to find the occurrences of something in a file

Alternatively, you can select the word under the cursor

Command mode

Special comment to say you don’t need to quit vim to go back to the terminalo You can use ctrl+z as it suspends (doesn’t interrupt) terminal processes

In this mode, you can setup your preferences

These preferences can be saved in the vimrc file and that’s basically it

Tabs

You can open many tabs to work on many files if you want

Ok, you have too many tabs now, how do you go to each of them?

Splitting screen

Cool, tabs are cool. But noy you want to split your screen, because you always want more… There’s a couple of ways to do this. I’m going over only one. Enough is enough right?

And combine it with some other commands

Now you can make the windows bigger and/or smaller

Moving from a place to another

And combine again

We need to remember the moving buttons (hjkl)

Let’s move things around

And combine again

We need to remember the moving buttons (hjkl)

Search and replace

Searching and replacing nedds a bit of knowledge of REGEX

**:%s/searching_pattern/replacing_word/options

Where to search and replace

Searching pattern

Here you can use your REGEX knowledge (out of scope of this)

Useful options

Registers

If you’re not yet, you’d be mad with me. But why is that?

Because you might run into this scenario:

  1. You y copy a line
  2. You want to delete another line to paste the one you just copied
  3. Cool, you’re smart and dd delete the line
  4. Then you p paste and you have the line you just dded

INFURIATING

Worry not! You about to become vim-smarter!

We have a magical thing called REGISTERS It’s basically a storage for strings

When you copy or delete something you change the content of the “default” register And when you paste, that’s the register vim uses. But we can change that!

So now we can paste using our new knowledge

Macros

Repeating things!

We have the mini macro .

Your last change can be deleting, pasting, whatever

A change starts when you enter insert mode and stops when going back to normal mode

You can create your own macros. YAY!!

You choose you register and start having fun

  1. qa starts
  2. Start your changes
  3. Not only insert mode changes
  4. q in normal mode to stop recording

You can see your macro on the :reg

And you can execute your macro with @a (a being the reg you chose)

Don’t forget we can always (always? not sure) combine things

Marks

You can mark and get back to it

Jumps

Tags

When working on a project you might need to jump into definitions Use ctags to generate them.

Or from terminal

vim -t method-name

Plugins

Plugin managers

Useful plugins

References

vim game: https://vim-adventures.com/

vim movement cheat sheet: https://vim.rtorr.com/

Further info

You can see this presentation in vim. It is best viewed using Presenting vim and figlet