
Intermediate Vim - signa11
https://dn.ht/intermediate-vim/
======
jnurmine
Maybe you can cover macros since they are conceptually very simple and very
powerful.

They may seem a bit complex but are quite simple. Basically you just record
your editing movements and play it back.

How macros work: press q x to record and q to end. Then repeat with @ x, where
x is the name of the macro you want to use (you can have several macros).
Anything you do will be played back. That's it... Conceptually simple.

A nice trick is to record a macro for a single line and place the cursor on
the start of the next line at the end of the recording. This way it's possible
to operate upon large blocks of text in a similar way by just repeating the
macro. The key then is to use generic movements like "go to the beginning of
line" (^), "go to the end of line" ($), "skip word" (w), etc.

As a silly toy example, if you have a list of strings in a text file, you can
turn it into a list of quotes with (from the top of my head):

    
    
      qx<Home>i"<Esc>$i<Right>",<Down><Home><Esc>q
    

(Record macro, go to beginning of line, insert mode, write a quote, exit
insert mode, go to end of line, insert mode, move right, write a quote and a
comma, move down to next line, move to the beginning of line, exit insert
mode, end macro recording)

Then to process 100 lines, you'd do:

100@x

That turns these:

    
    
      alpha
      bravo
      charlie
      delta
      ...
    

into

    
    
      "alpha",
      "bravo",
      "charlie",
      "delta",
      ...
    

If you have hundreds of lines of that you'll start to appreciate the easy
automation.

I use macros to do drive-by mass-edits without resorting to sed, scripting,
regular expressions etc. since the cognitive load of those is higher for me.

Edit: formatting

~~~
isostatic
I've used vim for a couple of decades, but never pushed to many advanced
features. For your example above I'd do :%s/^/"/ and :%s/$/",/

Unless I use a feature regularly I find it's a higher cognative load. I use
bash, sed and perl regexps on a near daily basis. Macros are very rare.

~~~
chongli
For that same example, you can accomplish the job in one substitute command:

    
    
        :%s/.*/"&",/
    

The _&_ special character gets replaced with the whole matched pattern.

~~~
mooreds
How do you escape the & character? I have been bit by this (not escaping &) a
few times but never enough to have found the answer.

~~~
Asooka
The same way you escape anything - with a \\. E.g. if you wanted to substitute
the character x with the sequence &/\ you would type

:s/x/\&\/\\\

------
robjwells
I’d highly recommend Drew Neil’s Practical Vim[0] for much more like this;
it’s broken down into easy chunks and gets into the _why_ as well as the _how_
of Vim’s techniques.

Modern Vim[1], mentioned elsewhere in the comments, covers more advanced Vim
usage.

[0]: [https://pragprog.com/book/dnvim2/practical-vim-second-
editio...](https://pragprog.com/book/dnvim2/practical-vim-second-edition)

[1]: [https://pragprog.com/book/modvim/modern-
vim](https://pragprog.com/book/modvim/modern-vim)

~~~
wodny
Drew Neil also created great video tutorials, the vimcasts[1].

[1]: [http://vimcasts.org/episodes/](http://vimcasts.org/episodes/)

------
asadjb
I feel composing commands is where the real power of Vi(m) comes from. This
can be really helpful to someone just starting out with Vim.

I got a boost in my Vim productivity after reading a similar StackOverflow
answer a couple of years ago. It's a nice read for people familiar with Vim,
and another good resource for new users.

"Your problem with Vim is that you don't grok vi."
[https://stackoverflow.com/a/1220118](https://stackoverflow.com/a/1220118)

------
ryannevius
I'm not sure I'd call any of this "intermediate" Vim. Most of it appears in
vimtutor, and the rest in the "basic editing" portion of the reference manual.

~~~
hyperpallium
Vim: difficult to learn, difficult to master.

Most of it is "intemediate".

------
campbellmorgan
For anybody who's found more IDE-y activities a bit beyond the current
generation of VIM plugins (looking at you Typescript), the Vim plugins for
VsCode and Visual Studio are actually surprisingly good and I find myself at
least as productive as I do in Vim.

I imagine it might be quite a good starting point for somebody who's used to
VsCode productivity but wanted to get into vim without going full vim!

~~~
diehunde
The problem I have with those plugins is that I use a lot of split buffers not
just for editing but also for exploring directories using :Explore for
example. Some IDEs+vim plugins support horizontal splits but then when you
have to jump between different modes such as explorer or console they use
different shortcuts.

Nevertheless, I think that VIM support for IDEs has improved a lot these past
years. VSCode and Jet brains have done an awesome work integrating it to their
software.

~~~
campbellmorgan
I've managed to get the classic vim `<C>-w` + h|j|k|l working in VSCode. Sadly
my convenient remapping of that doesn't work :(

My annoyances are pretty small: not being able to do `:e ` and then tab
complete the directory structure and the fact that VSCode has splits with tabs
rather than tabs with splits.

------
dhotson
Hey all, I'm the author. Feedback is welcome! :)

The reason I wrote this is because I've been pair programming quite a bit
lately and also mentoring some new vim users—so I wrote this little guide to
help vim beginners level up their skills a bit.

What I noticed is that a lot of vim beginners find composing commands and
text-objects to be kind of mind blowing.. and even more experienced vim users
mentioned that these were the things that made them have that "aha" moment and
convinced them to learn more.

~~~
timrichard
Nice checklist...

I'm not quite convinced about this as general advice :

> If you’re like me and never learned to touch type properly, just use the
> arrow keys, it’s fine, don’t worry about it.

When I decided to go all-in on Vim keys some time ago (trying to find plugins
for everything), it didn't take long to transition to hjkl. I think it's
easier and more convenient to stay near the home row rather than moving my
hand over for the arrows. I don't strictly touch type either.

~~~
fanpuns
Was going to comment the same. OP you must be a glutton for punishment if you
can't touch type and are using vim

------
jaequery
“If you’re like me and never learned to touch type properly, just use the
arrow keys, it’s fine, don’t worry about it.”

Are touch typists rare these days? I feel like people these days forego even
learning to type properly. I dont understand why they refuse to just learn it,
it is such an essential skill to have.

~~~
breyerjs
We were taught to touch type in grade school, but I goofed off during those
lessons. I got through college without needing it. I was a speedy point-and-
peck typist, which was good enough for that period of my life.

Later on, when I learned to program, I found that my slow typing speed
frequently caused me to lose my train of thought midway through a line of
code. It was frustrating enough that I spent a month teaching myself to touch
type. Basically, I took online typing tests over and over after work.

Since then, my typing speed has at least doubled. I don't look at the keyboard
anymore, and I'm able to get my thoughts down with _much_ less friction. I
can't recommend it enough.

~~~
lprd
Mind if I asked which course/website you used to learn how to type properly?

~~~
ElijahLynn
Idea for someone looking for something to build, on my list but probably won't
prioritize it for many years as I'll build it eventually but would welcome
someone else building it. If anyone wants to work on this ping me and maybe I
can help collaborate/mentor.

Typing App for Engineers, MVP:

* Load a canvas with a preloaded code snippet, the text is mostly greyed out

* When typing your text shows over the greyed out text, but darker, red if the character doesn't match

* Time how long it takes to type it perfectly

Gold plating:

* Users can login

* Users can upload own code snippets for community contributions

* Leaderboard shows top times and users for those who typed it perfectly, only perfect scores are registered, because code must be perfect or it won't run.

This could also allow an engineer to learn APIs while learning to type. I did
this with 60 or so pages of Drupal code a few years ago. I used Compiz
fusion's overlay opacity control to put a loaded code snippet into VIM,reduced
the opacity of the window slightly, then laid another VIM terminal on top of
it, reduced the opacity of that terminal window so I could see behind it and
started typing the slightly greyed out text from the window behind.

Been meaning to put this out on my blog but this is a good start.

~~~
breyerjs
I was actually learning React around the time I was learning to touch type.
So, naturally, my first project was to build a typing test[0] :) Looking back,
I cringe at the code quality. But it worked and I had fun doing it. ¯\\_(ツ)_/¯

I like the idea of typing out code though! I think there are some sites that
do that, like [https://typing.io/](https://typing.io/)

[0]
[https://github.com/breyerjs/typequick](https://github.com/breyerjs/typequick)

~~~
ElijahLynn
SWEET! Typing.io is perfect and almost* exactly what I was intending to build.
Can even upload own samples, and it focuses on working code, no typos. I think
I'll actually pay for this too!

* It doesn't seem to have the social/competition/gamification aspect built in like Vim Golf.

------
KhoomeiK
TIL I'm an intermediate user of Vim! /s

I think this is pretty basic in terms of general vim commands. Navigation and
insertion are all basic use cases that beginners should know. That said, the
section about composing commands was really interesting!

~~~
msaharia
That's what I was thinking! These are pretty basic.

~~~
tutfbhuf
I think I need the expert guide.

~~~
intertextuality
It exists, it's called :h(elp). I've barely begun to delve into the mountain
of documentation that is :h.

You can read Pro Vim or Modern Vim as well.

------
cranium
One thing I miss on Vim I have on Spacemacs with the Evil layer is the "a"
object (for "argument"). With it I can delete/change an argument of a function
in a flash.

Example (cursor on the last arg):

    
    
      importAntigravity(usePython, crashTheUniverse)
      <type daa for "delete an arg">
      importAntigravity(usePython)

~~~
url00
This does that in Vim:
[https://github.com/wellle/targets.vim](https://github.com/wellle/targets.vim)

I use it all the time! The only reason I don't use Spacemacs is the startup
time/GUI lag, but if it works for you keep at it!

~~~
Lathie
Running emacs as a daemon will get rid of the lag :)

~~~
aoeusnth1
As an emacs refugee, I disagree. I tried everything to get rid of the lag and
it just became unbearable after having significant exposure to vim through
pair programming. Now I just use Vim instead of trying to get Emacs to work
like Vim.

------
dredmorbius
Recommended:

Learn vim For the Last Time: A Tutorial and Primer

[https://danielmiessler.com/study/vim/](https://danielmiessler.com/study/vim/)

Mastering the Vim Language

[https://youtube.com/watch?v=wlR5gYd6um0](https://youtube.com/watch?v=wlR5gYd6um0)

An Incremental Approach to Vim

[https://ctoomey.com/writing/an-incremental-approach-to-
vim/](https://ctoomey.com/writing/an-incremental-approach-to-vim/)

------
declank
I use Emacs/Evil for hobby programming and vi for quick edits on servers. Wish
I had this guide years ago. Incredibly helpful. :)

------
tebs1200
A well written guide for introducing some of the power of Vim to a new user.

One thing I'd suggest for the author, based on a quote from the article -
"Invest your time to learn new skills" \- Try and invest some time to learn
touch typing.

I worked as a developer for years thinking that it wasn't worth the effort,
but after taking a couple of weeks to learn, I never looked back. My
productivity, particularly with Vim has jumped leaps and bounds.

------
kaitari
After years of using Vim, I recently learned that I could use `Ctrl+C` instead
of `ESC` to get back to command mode. Mind blown.

~~~
EduardoBautista
Several years ago I wrote a simple blog post on ESC alternatives:

[https://www.eduardobautista.com/escape-key-alternatives-
in-v...](https://www.eduardobautista.com/escape-key-alternatives-in-vim/)

------
Ice_cream_suit
Disappointingly elementary.

Even I, an Emacs user who occasionally uses vi am familiar the material in
this.

Can anybody suggest any real intermediate vi material?

~~~
LocalPCGuy
Beginner vim is being able to exit vim successfully, knowing how to hit i to
insert text, and how to save your file. Just because you are familiar with it
doesn't mean it isn't intermediate, it just means you are already
intermediate.

------
knolax
As a Vim user one of my gripes when first using Vim was how cumbersome the
built in help files were. I guess that's why there are so many "vim
cheatsheets" out there, the built in documentation is a pain to use.

~~~
preommr
The biggest pain in vim is the escape key. And no, ctrl+[ isn't any better.

~~~
isostatic
I have capslock mapped to escape and never notice which one I use (started
doing that after my escape key broke on a laptop about 15 years ago)

I believe people with poor keyboards don't even have escape keys any more
though

~~~
jwilk
What do you mean by "poor keyboards"?

~~~
isostatic
My collegues are constantly complaining their (mac) laptop keyboards are
terrible, however aren't ballsy enough to say "F-U" to the corporate choice of
a mac or a windows laptop.

~~~
pcr910303
Well, HNers complains the MacBook keyboard as it’s a complete trash, but
please remember that there are plenty of people that likes and even loves the
butterfly keyboard. The keyboard itself is pretty awesome and provides much
stabler keys than usual keyboards (whether it’s membrane or mechanical). They
work regardless of what part of key I press, which means that typo rates
significantly decreases. I’m happily using my MBP’s butterfly keyboard with
Vim. Just please, don’t say keyboards are terrible after using for a few
hours. There’s a reason why Apple is keep placing the butterfly keyboards in
top-range Macbooks.

~~~
isostatic
I'm not saying it, the people using them all the time are saying it.

I'm happy with the generic HP keyboard I'm using at the moment, circa 2014,
and my T410s old style thinkpad keyboard.

------
throwawaylolx
If this is considered "intermediate," then for more advanced Vim tips I
recommend [http://vimcasts.org/episodes/](http://vimcasts.org/episodes/)

------
lenkite
One thing I always wished VIM had was the generalized ability to repeat the
last navigation command with "," and ";". I mean if I use "[m" to go to the
previous method, then I want to be able to repeat that with ",". Never
understood why ",' and ";" are _only_ for "f" and "F"

------
opan
The balloon comparison is strange. I would've just said that adding shift to a
shortcut often reverses it... / for search and ? for search backwards, alt-tab
to switch windows, alt-shift-tab to go the other way, ctrl-tab to go to next
tab in Firefox, ctrl-shift-tab for backwards. It's incredibly common.

~~~
Izkata
So common, that cars shift into reverse!

------
isostatic
The defaults in vim 8 in debian and ubuntu really changed the way vim worked,
it was horrendous

As far as I'm concerned, the following is an non-negotiable requirement for
vimrc.

    
    
      source /usr/share/vim/vim80/defaults.vim
      set noincsearch
      set scrolloff=0
      set mouse=

~~~
jermy
Just to extend this - if you're often using different users (or need to
otherwise deploy via a configuration manager), I've found out that a good way
of having system-wide options on Debian is /etc/vim/vimrc.local with something
like:

    
    
       " Workaround stupid defaults.vim behaviour
       if filereadable("/usr/share/vim/vim80/defaults.vim")
          source /usr/share/vim/vim80/defaults.vim
       endif
       let g:skip_defaults_vim = 1
     
       " Disable stupid seeking to last position
       autocmd! vimStartup BufRead
     
       " Disable stupid mouse support
       set mouse=

------
johannkokos
I learned a new one recently. zt redraw so that current line is at top, zb
redraw so that current line is at bottom, zz redraw so that current line is at
the center.

If you are on twitter, you might want to follow MasteringVim. You'll learn one
trick every day.

------
robertlf
If this is intermediate, then I must be an expert.

~~~
chapium
Its so easy you can become an expert in merely hours :)

------
sepisoad
I liked it, as someone who has just started learning vim. Thanks.

------
stevebmark
This is less than beginner Vim, certainly less than vimtutor, and far less
than any other Vim tutorial I've seen. This makes the title feel like
clickbait.

~~~
dhotson
Hey yeah thanks, it's really difficult to know where to start and how much to
cover in an article like this.

I think I agree now that the title isn't quite right—my intention was to help
beginners get towards some intermediate topics.

~~~
mikekchar
What about "Towards Vim Fluency"? Just as click-baity, but maybe a bit more
precise ;-)

BTW, even though I've used vim for a long time and consider myself fairly
advanced, I had somehow forgotten about "I". You've saved me countless "^i"
invocations... Wait... That's cording! It's cheating :-) (But it's OK because
I'm a closet Emacs fan)

------
commandlinefan
Well I didn't think I would learn anything but I didn't know about cit/cat -
very cool!

------
cityhome
Cityhometution is an online portal to find the professional tutors and tutor
jobs which give the special and wide opportunity to the students/learners to
select the best Home/online Tutor by their own choice under one roof with our
unique features.

We are in the field of connecting Qualified Home/Online Tutors since 2005 with
an extensive experience in dealing students and tutors in a familiar way.

• Trustworthy Home Tuition Providers • All Major Cities Of India • Over 12
Years Of Impeccable Service • Qualified And Verified Home / Online Tutors •
Provided Tutors to Thousands Of Students Since 2005 • Our Students Are From
Prestigious Corporate Schools and Colleges • Having more than 1,00,000 tutors
in around In India • International Experience Trainer in Corporate Teaching

For more information:
[https://www.cityhometution.com/](https://www.cityhometution.com/) WhatsApp :
+91 9948464333

------
manjana
Adding one to the great article:

Shift+k on a word to enter the corresponding man-page if such one exists :)

~~~
dredmorbius
That command can be remapped according to context. For email and other prose,
I set it to 'dict' instead.

------
flogfr
The most notable tool to help improving your skill in vim (after doing the
excellent vimtutor), is to go and do some vim golf. You can see the solution
from just one point better than you, improving your skill gradually.

------
gigatexal
Love the not shaming for using the arrow keys.

------
ptah
tbh this looks like beginner vim to me

------
rezeroed
These are the basics, not intermediate. Otherwise what are the basics - just i
and esc? Undo and redo are intermediate? Nope.

