DEV Community

Cover image for Exploring Vim

Exploring Vim

Jaime González García on November 06, 2018

This article was originally posted in barbarianmeetscoding.com. 😊 Since I became a programmer I've been quite fixated with the idea of making more...
Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

This was awesome. Thanks for posting.

Now I need to plug Atom's vim-mode-plus, specifically, it's incredible occurrence operators:

d o i l delete occurrence in line - deletes all instances of the current word in line
c o i l change occurrence in line - changes all instances of the current word in line
c o i p change occurrence in paragraph - changes all instances of the current word in the paragraph - perfect for refactoring the name of a function param
c o i p change occurrence in paragraph - changes all instances of the current word in the paragraph - perfect for refactoring the name of a function param

And even more. I'm so completely hooked on these workflows because they're so nice.

I also added some vim/emmet crossover keymappings, like

'atom-text-editor.vim-mode-plus:not(.insert-mode)':
  'g e r t':  'emmet:remove-tag'

That one's clutch:

<a href="#"><p⌨️re><code>Bar</code></pre></a>

With cursor at ⌨️, I escape to normal mode and hit g e r t and voila - I get

<a href="#"><code>Bar</code></pre></a>

I'm so hooked on VIM, I even baked simple commands into my keyboard's firmware. It's a little buggy, but you're free to use it, and if you're interested, PR's are welcome ;)

Collapse
 
vintharas profile image
Jaime González García

Thank you! And thank you for the comment!

I really like the occurrence operator. It feels very convenient! Like a shortcut for the vim substitute command that plugs in as a text object with all other commands. I'm not fluent enough in vimscript yet but it sounds like something that could be implemented as a vim plugin :D

Collapse
 
vonheikemen profile image
Heiker • Edited

Stop it. You had me at "Vim"

I remember a post where someone compared their .vimrc to a zen garden or something like that. They said that they loved visiting that file and make a few tweaks every now and then.

That post was right, it is surprisingly entertaining to find out that Vim has a motion/command/whatever that is useful (like go to matching curly brace) and go to your config file and make it even more convenient. Piece by piece it grows into something that makes you productive and you love it because it's yours and you made it.

Collapse
 
vintharas profile image
Jaime González García

hahaha :D

It does indeed feel like a beautiful zen garden _^

Collapse
 
antonmelnyk profile image
Anton Melnyk • Edited

It's all cool and geekish but in real world any other modern editor is just more practical and productive. There is absolutely no point to learn billion of shortcuts for basic stuff. Writing code is not about typing, that part of coding takes like 20% of work and most of it doesn't require vim-like spell casting on the text.

It is more than enough to have editor like Atom or VS Code which you can extend with plugins at your need. There are plenty stuff to learn in modern programming, why would you add on top of that learning a whole vocabulary of unnecessary shortcuts which won't even benefit you much.

Collapse
 
vintharas profile image
Jaime González García

Thank you for your comment!

A modern editor is definitely more practical because they typically have a great user experience from the get-go and you don't need to configure anything to get started. In my experience using a modern editor in combination with vim (a vim plugin) is amazing. You don't need to learn a billion shortcuts right away, you go learning them one by one as you go, normally when you feel the pain and wonder "there's got to be a better way to do this".

Even if 20% of our work is writing code (we don't need to debate that), I prefer that 20% to be frictionless, and vim allows me to be extremely adept at writing and changing code, so that I can express whatever is in my head in code in a fast and smooth way. If we all have a finite amount of keystrokes in our lifetimes, vim allows me to make them count :D. Then there's also the pride and joy of being very good at what you do.

Whether vim itself is better than a modern editor that's something that I haven't figured out yet. For me there's a couple of things I haven't been able to make work properly with vim yet: One thing is aesthetics and the other is statement completion to the level of TypeScript in VSCode.

There's a deeper thread in this article which transcends Vim. The thread is to master your tools and become proficient at whichever editor you use. Vim somewhat guides/forces you in that direction, because of its keyboard centered nature, its necessary configurability and its culture of extensibility.

Collapse
 
alancampora profile image
Alan Campora

It’s not about learning shortcuts, it’s about productivity and focus. But you can only understand this once you start using it.

Collapse
 
vintharas profile image
Jaime González García

Yep :) There's things you just need to try yourself before you can understand them.

They can tell you all the things about how it feels to have a child. But you won't truly get it until you have one yourself.

Collapse
 
biros profile image
Boris Jamot ✊ /

Your post is just awesome!
As a daily vim user, I always feel frustrated when reading such articles because I'm not using 1% of these features.
However, the only 10 commands I've been using for 18 years are enough for my needs. Your post is the best explanation of why I'll never learn more. It's too complicated.

Collapse
 
sudiukil profile image
Quentin Sonrel

That's the great thing with Vim: even using 1% of the features already makes you 100% more productive!

Collapse
 
vintharas profile image
Jaime González García

Hi Boris! Thank you and thank you for leaving a comment! :D

Don't feel bad for not using all the features. It is more practical to learn and use a little at a time in a way that makes sense with your workflow and needs. If you one day start doing something and start feeling pain, then that's the perfect motivator to find out whether there's a better way of doing that something. I've been using vim for ~5 years and I think there's more stuff I've learned over the past two months that I ever knew existed those past 5 years :D.

Collapse
 
j_mplourde profile image
Jean-Michel Plourde

Great article. Lots of new commands I will try. I started with vim in an internship 6 months ago. Actually I started with a vim plugin in Visual Studio. At first it was hard, I wasn't a typist (typed with 3 fingers on each hand for the last 15 years) and I was not very productive.

Then a friend of mine really convinced me. At the same time, I learned how vim works and how to type with all y fingers. It was a very painful moment but I am happy I learned all that. It significantly boosted my productivity.

Basically, I learned by searching for what I wanted to do then write it on a sheet. I made my own cheat sheet and it really helped me learn a lot of Vim syntax.

Now my laptop for college is fully running Linux, I use clion as my principal IDE and I use ideaVim plugin. For me, a vim plugin in a IDE is the best of both worlds. I have all the advantages of my IDE with an extra layer of power.

I've setup my default text editor in my shell and on git to be vim and I am actually quite decent using the real thing.

Collapse
 
vintharas profile image
Jaime González García

Hi Jim! Thank you for your comment! _^

Actually I started with a vim plugin in Visual Studio. At first it was hard, I wasn't a typist (typed with 3 fingers on each hand for the last 15 years) and I was not very productive.

I also started using VsVim with Visual Studio and also wasn't a typist. The first week was excruciatingly slow :D. Just switching to touch typing (without vim) took me at least a month of early mornings and late afternoons just practicing touch typing. I even overstrained my wrists and the pain lasted for months. But in the end it all worked out just like in your case :D

Basically, I learned by searching for what I wanted to do then write it on a sheet. I made my own cheat sheet and it really helped me learn a lot of Vim syntax.

Great idea! :D

Collapse
 
bokwoon95 profile image
bokwoon95

f'ci'MAN<ESC>

You don't need to f' by the way, vim will seek out the first '' pair travelling down the line. So ci'MAN is enough ✌️

Collapse
 
vintharas profile image
Jaime González García

Wooooooooot!!!! This is EPIC! I. Did. Not. Know. This. And if I knew it at some point in my life I had completely forgotten about it! Thank you for leaving a comment! :D 🙌

Collapse
 
vintharas profile image
Jaime González García

I've updated the article to add a note on that :D Thank you! It looks like this behavior only applies to the quotes text object and not the others though.

Thread Thread
 
bokwoon95 profile image
bokwoon95

Yup, I'm not really bothered by it because the awesome targets plugin extends that behavior to the rest of the text pairs as well as arbitrary separators: , . ; : + - = ~ _ * # / | \ & $. That's such a sane default, I wish it was in vim to begin with!

Thread Thread
 
vintharas profile image
Jaime González García

Oooooh that's so gooooood! Indeed that feels like it should be the default behavior. I had started a thread in my brain thinking about how I could implement that behavior for the rest of the operators but it is awesome there's already a plugin that does that! Thank you for sharing!!!! :D

Collapse
 
mrconst3llation profile image
Yanga Nkohla

"This is a very bad first impression and I've twice given up on learning vim just because of this. (Let's learn vim! Open vim! Ain't got time for this...)" That's me yesterday after I installed it 😅 thanks for the post, I'm gonna give it a try again today 🙏

Collapse
 
vintharas profile image
Jaime González García

hehe I know right :D Let me know how it goes :)

Collapse
 
theringleman profile image
Sam Ringleman

Love your article and I love how popular it appears to be! I have been a Come user for a couple years now and am so thankful kful I learned it. One neat little tricky I found in Gmail, if you have the keyboard shortcuts turned on, they simulate vim movements 😀

Collapse
 
vintharas profile image
Jaime González García

Thank you!

Yes! If you take a look at the shortcuts of a lot of popular services you'll see that they use common vim key bindings. One is gmail, another one is twitter, trello if I don't remember wrong and many more.

Collapse
 
theringleman profile image
Sam Ringleman

Awesome! Honestly I like to think that this is a programmers subtle way of vim evangelising 😁

Collapse
 
kungtotte profile image
Thomas Landin

There are other great resources for vim:

  1. vimtutor - a basic tutorial that ships with vim. This gets you comfortable with the basics of moving around and changing text.

  2. Your problem with vim is that you don't grok vi

  3. Learn vimscript the hard way

  4. After that the book already mentioned: Practical Vim

Collapse
 
vintharas profile image
Jaime González García

Than you for the comment! I do mention vimtutor in the article and thank you for sharing the other resources. You don't grok vi is really good and I'm looking forward to reading learn vimscript the hard way (it's on my kindle :D). I already have a plugin in mind I'd love to write.

Collapse
 
moopet profile image
Ben Sinclair

[Neovim] comes out of the box with more sensible defaults and an integrated terminal

People often pitch this as a reason to use neovim. Vim also comes with an integrated terminal (well, it depends which options your version was built with) and has for a while. When neovim evangelists say it has a terminal it's a bit like BMW fans saying that their car is better than your Ford because it comes with seats.

As far as sensible defaults go, that's a whole can of worms. An awful lot of people disagree with anyone else's idea of "sensible"...

Collapse
 
vintharas profile image
Jaime González García

Hi Ben! Than you for the comment!

I have to admit I don't have a strong opinion here but I do think that neovim defaults are sensible and provide a nicer first-time user experience to the alternative. Particularly:

  • Syntax highlighting is enabled by default
  • ":filetype plugin indent on" is enabled by default
  • 'autoindent' is set by default
  • 'autoread' is set by default
  • 'hlsearch' is set by default
  • 'incsearch' is set by default
  • 'nocompatible' is always set
  • 'showcmd' is set by default
  • 'smarttab' is set by default
  • 'wildmenu' is set by default

Also, their effort to allow other programming communities to write plugins using languages such as lua, python, ruby and JavaScript/TypeScript is also very interesting and cool.

In regards to the terminal, I'm using nvim/vim with tmux so I haven't found a strong use case yet for the integrated terminal (just haven't had the time to dive in there yet )

Collapse
 
moopet profile image
Ben Sinclair

Yeah, I used the built-in terminal out of curiosity a couple of times but stopped pretty quickly - I don't really see the point apart from for yanking lines out and I'm more likely to use r! to get shell content in anyway.

Collapse
 
kungtotte profile image
Thomas Landin

NeoVim does come with a sensible scripting language though :)

Collapse
 
liutkin profile image
Volodymyr Liutkin

There are another brilliant series for Vim beginners from Derek Wyatt.

Basically, if you manage to break through the first hard time learning Vim, I doubt you will ever drop it.

Collapse
 
vintharas profile image
Jaime González García

Cool! Thanks for sharing! :D

Collapse
 
gene profile image
Gene

Vim is a very powerful tool--that's for sure. But still, after reading this post I'll still only use VIM for quick edit on scripts. Not a full time editor for programming. I don't think it will raise my game either.

Thanks for sharing this wonderful article!

Collapse
 
vintharas profile image
Jaime González García

Thank you Gene! :D

Collapse
 
noblebe4st profile image
Jeff Hall

I've made a few casual threats to learn Vim before. The ubiquity argument is a good one, but it wasn't enough to get me to put in the effort. And then I needed a replacement editor at the office. I'm an Emacs user, I like Emacs, I'd prefer Emacs, but I can't use it at work for reasons that are dumb. Vim seems like a viable option I think. If it doesn't work out then I guess I'll have to give VS Code a try. Although that's going to leave me with many of the same problems I have now.

Collapse
 
vintharas profile image
Jaime González García

Try it out, have some patience and you may fall in love :D

Collapse
 
somedood profile image
Basti Ortiz • Edited

Although I don't see myself learning Vim anytime soon, this is without a doubt one of the best articles I've read about it. I especially like the playful tone you had when explaining the keystrokes. I'm keeping this article for future references. Thanks for this!

Collapse
 
vintharas profile image
Jaime González García

Thank you!!! :D

Collapse
 
tux0r profile image
tux0r

Vim is for programmers who want to raise their game.

This is too religious to be true. Why would you need to "raise your game" by using an application written for hardware that is long gone? We have graphical desktops, cursor keys and mice now - you'll probably click faster than you touch-type.

Editor wars are pointless - but if you're already sufficiently productive with your current text editor, there is no advantage of learning Vim instead. (This is also true for Emacs, to which I had moved from Vim.)

Just in case someone wonders why I hate Vim: I don't. In fact, I've been the maintainer of the tuxproject Windows 10 builds for a few years now. But I had Vim as my primary editor for three or four years because I thought that I also was so much more efficient with it.

I was wrong.

Collapse
 
vintharas profile image
Jaime González García

Hi! 😊 Thank you very much for leaving a comment! :D

My intent wasn't to be religious in any way but to share something I find useful, interesting and which I think has helped me become a more productive programmer.

I used this quote:

Vim is for programmers who want to raise their game.

Because it perfectly describes the feeling/intent that I had when I started learning vim. I love to continuously examine how I am doing things, see where I feel pain and try to improve. So you could say that I'm always for raising my game. At the time when I learned vim, I was super proficient with Visual Studio and ReSharper but I felt that my flow was often stopped or slowed down when doing small refactorings (like at the code block or code line level). It that context, vs(vim) was a great combination with ReSharper. And, even if it didn't improve my productivity measurably (I never went back or exhaustively quantified the difference between before and after adopting vim), it did make me feel like a coding wizard as I became a lot more fluent when coding (which I think is a good thing :D).

I certainly didn't mean it as exclusionary or demeaning of anyone using other editors.

Editor wars are pointless

Totally agreed

you'll probably click faster than you touch-type

No :) I can give you a lot of examples where keyboard is superior to mouse movement + click combination. The click is not the slow part of using a mouse. The slow part is lifting your hand from the keyboard, grabbing the mouse, moving the mouse where it needs to be, clicking and then moving your hand back to the keyboard. This is not only slower, it also breaks your flow.

  • select a word with the mouse, press delete, type again vs cw{insert}<ESC>
  • open a tab with a mouse vs type gt
  • go look for a file in the file explorer with the mouse vs C-p {start typing filename} <ENTER>
  • go open the menu -> File -> New -> click, type name, enter vs :e {filename}
  • etc... I don't think there is anything that you can do faster with a mouse that you can do with a keyboard (perhaps resizing a window? :D)

Note that keyboard superiority is not limited to vim. Any editor provides shortcuts because they're just faster than using the mouse. Learn your editor shortcuts and you're going to be infinitely more proficient than you were when you used the mouse.

I think that we just don't see things alike and we don't need to discuss it further. :D

Collapse
 
tux0r profile image
tux0r

Then again, "5 lines up, 83 columns right, select the next word" is still faster with the mouse because you can just click there. ;-)

Otherwise, I mostly agree.

Thread Thread
 
vintharas profile image
Jaime González García

hehe you are right. Using counts is not very efficient. It's ok for 2-3 items but beyond that is more time consuming (it's just hard to count words/characters by just looking at them).

For that particular use case, you can use pattern searches:

?{pattern}<Enter> and you're there. That in combination with n/N to repeat last search forward or backward and it's pretty much instant.

?{pattern} to search upward and /{pattern} to search downward

Collapse
 
ug02fast profile image
Arthur Zhuk

Great article Jaime. After making it past the learning curve, VIM is by FAR the most efficient and effective way to do development!

Collapse
 
vintharas profile image
Jaime González García

Thank you!! Indeed, it is hard to find something equal to vim :D

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
chenge profile image
chenge

I use vim a little. When I write a single file I use it because it's light,
else I use vscode.

I cannot memorize those vim command.

Collapse
 
vintharas profile image
Jaime González García

Visual Studio Code is an awesome editor too :D

Collapse
 
j_mplourde profile image
Jean-Michel Plourde

It has a vim plugin for all the shortcuts. I used vscode with the vim plugin and it was pure joy.

Thread Thread
 
vintharas profile image
Jaime González García

Indeed! It has improved a ton from the first versions _^

Collapse
 
jessachandler profile image
Jess Chandler

What a great and detailed post. I used to get so frustrated with terminal would auto open vim. :)

Collapse
 
vintharas profile image
Jaime González García

Thank you!! Yes, who hasn't experienced the being-trapped-in-vim at least once? :D

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Thanks for this awesome post!

I watched the WAT video, laughed so hard that I needed to share it with the collegues and almost forgot to read on the rest of your post... I carried on gladly :)

Collapse
 
vintharas profile image
Jaime González García

Thank you Robin!!! :D OMG that video is so awesome!! I can completely understand you got sidetracked by it xDDD

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Thank you for sharing it Jaime, totally made my Monday!! :)

Collapse
 
codingmindfully profile image
Daragh Byrne

I think I learned more from this article in 20 years of using vim (mostly because it wasn’t emacs).

Collapse
 
thejsizemore profile image
Jason Sizemore

I will say that if you are 'ssh' into any Linux or BSD servers knowing vim is a must. It is like a carpenter not knowing how to use a tape measure.

Collapse
 
vintharas profile image
Jaime González García

Thank you!

Collapse
 
avelino profile image
Thiago Avelino

Do you know the project vim-bootstrap vim-bootstrap.com ?

Is open source

avelino / vim-bootstrap

Vim Bootstrap is generator provides a simple method of generating a .vimrc configuration for vim

vim-bootstrap

Join the chat at https://gitter.im/avelino/vim-bootstrap Open Source Helpers

Vim Bootstrap is generator provides a simple method of generating a .vimrc configuration for vim, NeoVim, NeoVim-Qt, MacVim and GVim.

Pre-requisites

The distribution is designed to work with Vim >= 7.4.

Mac OSX

$ brew install git ctags

Linux

  • Ubuntu\Debian
$ sudo apt-get install git exuberant-ctags ncurses-term curl
  • Gentoo
$ sudo emerge --ask dev-util/ctags sys-libs/ncurses dev-vcs/git dev-python/pyflakes net-misc/curl
  • Arch Linux via pacman (recomend used pacaur)
$ sudo pacman -S git-core ctags ncurses curl
  • Fedora
$ sudo dnf install ncurses-devel git ctags-etags curl
  • openSUSE
$ sudo zypper in ncurses-devel git ctags curl

Python bundle (optionally)

  • pyflakes
  • jedi
  • neovim (neovim only)
$ pip install flake8 jedi
$ pip2 install --user --upgrade neovim
$ pip3 install --user --upgrade neovim

Elm bundle (optionally)

  • elm-test
  • elm-oracle
  • elm-format
$ npm install -g elm-test
$ npm install -g elm-oracle
$ npm install -g elm-format@exp

Installation

Collapse
 
vintharas profile image
Jaime González García

Wop! I did not! Thank you for sharing!!! This is really cool!