DEV Community

Cover image for Exploring Vim
Jaime González García
Jaime González García

Posted on • Updated on • Originally published at barbarianmeetscoding.com

Exploring Vim

This article was originally posted in barbarianmeetscoding.com. 😊

Since I became a programmer I've been quite fixated with the idea of making more with less. From how to live a fulfilling, purposeful and thoughtful life to how to refactor this line of code in the most efficient way possible. In the ambit of coding, I've been obsessed with learning new skills and tools that can unlock and unleash unlimited power and enable me to achieve more with every keystroke and with every hour I invest into developing something.

Tidy desktop setup with and iMAC that has a wallpaper prompting you to do more

Photo by Carl Heyerdahl on Unsplash

One of such tools is vim. Vim is a text editor whose centric keyboard design, modal philosophy, and command composable nature, promises unlimited productivity and masterful text editing to those who dare confront its steep learning curve and survive to tell the tale.

It's been 5 years since I decided to bite the bullet and learn to vim. It was tough, particularly because I wasn't a touch typist, but I managed to learn and glean some of the power promised on the other side. However, I never made a complete jump to vim. Instead, I stayed within the cozier confines of Visual Studio, Atom, and lately Visual Studio Code using a vim layer (most editors have a vim mode that supports vim to a higher or lesser degree). Vim would remain my second editor, mostly used for hobby projects or writing. So I never got to get really good at vim. Don't get me wrong, learning to be comfortable with the basic commands and motions helped me be more proficient in writing and editing code. Even better, it resulted in a thinner interface between my brain and the keyboard which allows me to put my thoughts into code that much easier.

Nonetheless, I've always felt a slight pang of remorse about not going the full way, a nagging feeling that emulated vim within the confines of another editor can't be as good as the real thing, a feeling that I must be missing out on something.

So here we are! Today, I pledge to re-take my quest of text editing enlightenment, tread the treacherous paths of learning vim and arrive to the holy shrine of coding awesomeness. Care to join?

What is Vim?

Vi is an ancient text editor (as ancient as 1976) designed to work on terminals and with the very uncommon characteristic of working in a modal fashion (as in, a mode for inserting text, a mode for editing text, a mode for selecting text, and so on). Its latest and most celebrated incarnation is vim (Vi IMproved) which supports both text and graphical interfaces, comes with a pletora of improvements over vi and it's supported on every platform known to humankind.

What About Neovim?


Over the past couple of years you may have heard people talking about Neovim and wondered wat!?. Neovim is a modern fork of Vim that aims to refactor Vim to make it more maintainable, extensible and easier to contribute to by a wider community. It comes out of the box with more sensible defaults and an integrated terminal. You can find out more information about Neovim at neovim.io.

Why Vim?

Why should you care about learning an ancient editor in 2018? Great question! Vim provides a different way of interacting with text from anything I've ever seen, a way that gives you a completely different level of control and fluency when editing code.

With vim, the main way in which you interact with your code is not through inserting characters or using the mouse to move around. Instead you'll be like a code surgeon that makes expert incisions with surgical precision whenever and wherever it is required, navigating through your code and codebase with the lightning speed and accuracy of a entirely keyboard driven workflow.

Vim is designed to provide the touch typist with the highest degree of productivity, with the most common commands comfortably laid out in the home row and its neighbouring keys. Vim is a modal editor with the so-called normal mode at the forefront. A mode devised to read, navigate and transform code at will. The fact that vim has modes allows keys near the home row to be reused in each separate mode, minimizing the need for slow and contorted key combinations, and heightening your speed and the longevity of your fingers and wrists.

Vim is extremely customizable and you can adapt it to your way of coding and your way of doing things. Part of the beauty, and the complexity of learning vim, is how you can slowly but surely make it work in the way that you work, in your project, alone or with your team.

In any case, even if you don't jump straight into the vim editor, you will reap the rewards by bringing all the commands and motions that you learn with vim to your favorite editor. That's it! Vim is so good that most other editors today support some sort of vim mode which brings all the basic commands and motions right into the comfort of your well known editor.

So Why would you want to learn Vim in 2018? Paraphrasing Drew Neil in Practical Vim1:

Vim is for programmers who want to raise their game. In the hands of an expert, Vim shreds text at the speed of thought.

And who wouldn't want that, right?

A Taste of Vim

Unlike any other traditional editor, when using vim you'll spend most of your time in normal mode. Within this mode you don't explicitly write code, instead it is optimized for navigation and precise text changes. Your right hand rests firmly on2 the core motion (as in movement) keys hjkl. These keys move the cursor around to left, down, up, and right respectively. You can also move left to right word by word using w (go to the beginning of next word) or e (go to the end of the next word), or use b/ge to do the same but right to left.

Taking advantage of these keys you can navigate a file with fine granularity and strike with great vengeance and spite: daw and bang! You delete a word! das and you remove a sentence! dap and you obliterate a paragraph! Fierce!

Or you can be less menacing and more nurturing and fix stuff instead. Using caw,cas,cap to change a word, a sentence or a paragraph. But it doesn't end there. You can ctx to change until the first x in the current line, or c$ to change everything until the end of line, or event better ci( to change the content between parentheses or ci" to do the same to the content inside quotes.

Imagine a simple string:

const msg = 'Hello vim'
Enter fullscreen mode Exit fullscreen mode

You can change the string by typing: f'ci'WAT<ESC>

const msg = 'WAT'
Enter fullscreen mode Exit fullscreen mode

Which means find the next ' then change everything inside ' for WAT, then <ESC> to leave insert mode back to normal mode.

wat

You can then yank the line with yy (which is vim jargon for copy) and put it below with p (again vim jargon for paste):

Yes, you got it! yank is another operator like delete and change. You can use y just like d or c to yank a word yaw or yas yank a sentence. Moreover doubling a command like so yy makes the command operate on the entire line. Nifty cc changes a line and dd deletes one.

const msg = 'WAT'
const msg = 'WAT'
Enter fullscreen mode Exit fullscreen mode

Again f'ci'MAN<ESC>:

const msg = 'WAT'
const msg = 'MAN'
Enter fullscreen mode Exit fullscreen mode

Then go crazy join the lines with kJ (k to go up and J to join lines):

const msg = 'WAT' const msg = 'MAN'
Enter fullscreen mode Exit fullscreen mode

Rinse with c3w+<ESC> and we've got ourselves:

const msg = 'WAT' + 'MAN'
Enter fullscreen mode Exit fullscreen mode

All kudos to wat

From the super great wat

Which is a completely nonsensical exercise of using vim but which stills manages to show you part of its magic.

For longer motions you can use counts in combination with motions and, for instance, go down 5 lines by typing 5j (as in {count}{motion}). Likewise you can use these together with the operators you saw above (d, c, etc) and d2w delete two words, or c2s change 2 sentences. There's longer motions too, you can H to move to the top of the visible area in the editor, or gg to go to the top of the file, L and G to achieve the same but downwards. Use { to move up a whole paragraph or } to do the same but down. While % helps you find matching parentheses.

You can start a new line below with o (drops into insert mode so you can start typing) or above with O. You can find patterns (of text) forward within a file using /{pattern} and navigate between patterns using n (next) and N (previous) or backwards using ?{pattern}.

You can repeat previous changes using the . command. Just type . and vim will repeat your last change. Likewise you can repeat motions. Type ; and you'll repeat a motion started with t,f,T,F or type n to repeat a search. You can record a collection of commands using macros and replay them at your will. And there's so much more...

So much power at your fingertips and we've barely left normal mode or the confines of a single file. There's splits, there's tabs, there's regex, there's access to external tools, there's spell checking, word count, there's 6 basic modes more with 6 additional variant modes and infinite extensibility and customization possibilities! (who's excited!?)

The Vim Way

Let's back down a little bit, reflect and try to draw some wisdom from what we've seen thus far.

Keyboard centeredness is at the core of vim. Important and useful commands lie underneath your fingertips and their location is very thoughtful and conductive to efficient use and learning. For instance:

  • basic motions in the home row under your right hand hjkl
  • common repeaters ; and . one beneath the other
  • another basic and powerful motion f is in your left index finger
  • basic operators are easily reachable with your left hand: s, x, d, c, r
  • s synonym for cl and x synonym for dl are one finger away from d and c
  • * and # motions used to find current word forward and backward. They are triggered by the middle finger of each hand.

The operators and motions make incredible sense, and are easy to remember through the use of mnemonics c means change, cl means change letter, caw means change a word, ciw means change inner word (as without the surrounding whitespace), ct. means change till you find ., and so on. This makes vim extremely conductive to learning as you'll have less need to memorize arcane commands: The commands just make sense.

Moreover all these operators, counts and motions make up a (programming) language of sorts. You can think of operators as functions and counts and motions as arguments, or using an even simpler analogy... you can think of operators as verbs, counts as adjetives and motions as objects. The true magic of vim is composition. As you go building up this vocabulary of operators and motions you'll find that you can combine them to your heart's content. So that, once you know all the c, cl, caw, ciw, ct. from the previous paragraph and you learn how dl works, you'll not only be able to use dl, you'll know that you can also combine it with all the motions you already have at your disposal and daw, diw, dt, etc.

This is very cool. When using Vim you'll feel you are navigating a meta-universe of text editing, it's like programming or controlling the very mechanism of editing and writing text. If you're familiar with git and how it feels to use the git command line to work with source control, you can think of vim as the git of text editing. (Putting aside the fact that vim predates git by almost 30 years). With vim, you'll look at a piece of text and you'll no longer see just words or text, you'll see the possibilities of an infinite number of operators and motions being applied. Like Neo awakening to the matrix.

Ok... Who let himself get carried away a liiiiittle too far? (me raises hand)

Why is Vim So Hard?

Now to the darker sides of vim... Namely. this.

Classic image with representations of the learning curve of different text editors

Source unknown

And this.

Classic joke about not being able to leave vim

The steep learning curve is somewhat exagerated and the quitting vim joke is getting VERY old. The reality is that there's at least 3 things that contribute to this fame of a steep learning curve and making vim not very approachable to the unwary traveller.

  1. Touch typing is a must
  2. It is keyboard driven and it takes some time to get accustomed to NORMAL mode as default
  3. Horrible first impression

Touch Typing is a MUST

Touch typing is a pre-requisite to vim. If you can't touch type you'll have a hard time performing the most basic operations within vim. As a self-taught typist this was a huge obstacle for me at the beginning, going from typing 100 WPM to about 10 WPM and making it excruciatingly slow to type anything let alone write code. This huge drop in productivity alone can have you abandon the quest for vim in the first hours. So if you consider learning vim a worthy pursuit do yourself a favor and learn to touch type first.

Here are some resources you can use to learn how to touch type:

  • typing.com. I spent a ton of time in this website to kill all my bad habits and learn touch typing the proper way. I still use it today to practice typing katas when I feel my touch typing is getting rusty. It's amazing how this site has improved over the years.
  • keyzen.io. This is a nice touch typing trainer that focuses on helping you improve your typing skills with uncommon characters which are common in programming such as ;, {, (, /
  • zType is a typing game where you take the role of a ship that fires at an alien swarm through typing. A really fun way to practice touch typing. WARNING: Very addictive and exciting. Don't use before going to bed.

The Keyboard and Normal Mode Wall

Having spent most of your life in a normal editor whose main mode is that of inserting text, moving to vim will prove challenging. Up to this point, you are accostumed to switching editors and get up to speed rather quickly since they all share an insert mode first approach and are friendly to exploration using the mouse within a GUI. Using a mouse with any modern editor you'll be able to explore the options available in the menus and right-clicking on panes, windows, tabs and text. Using this exploratory approach you will slowly make sense of things and learn to use the new editor.

Vim however is entirely keyboard driven and oftentimes is used from within a terminal (so there may be no mouse support enabled nor any options to explore with a mouse). And even though you'll be received with a prompt to use the help available via the :h command you will rarely heed that advice. It just feels too weird, too unfamiliar. Couple that with being greeted by a non-insert mode first editor where you can't even type text (and at first move or even leave the editor) and you will feel completely lost.

The best advice here is to learn the very basics first and slowly go expanding your vocabulary. The very basics are:

  • Get help with :help {whatever} (or the shorter version :h {whatever}). Vim's help is insanely good.
  • Move around with hjkl (:h motion or :h movement)
  • Go into insert mode with i (:h insert)
  • Go back to normal mode with <ESC> (:h mode-switching)
  • Save a file with :w (:h write)
  • Leave the editor with :q (:h quit)
  • Open a file with :e {filepath} (as in :e src/main.js) (:h edit)

Notice the : before all these commands? The colon triggers command mode also known as ex mode. When you type a colon and a command, the command will be displayed in the lower-left part of the screen.

That's really all you need to know to survive. Notice how I added the :help command you need to type to find information about each one of these commands and how easy to guess they are. You could have easily figured out by yourself how to quit vim by just asking for help. Vim :help quit please. This is a very approachable goal and the first day you'll probably will be able to start using a lot more commands than these ones: w, e, c, d are all very learnable because they just make sense.

Being able to survive is not the goal when switching editors. It is enough not to send you packing right away but what you really want is to be more productive and effective than in your current editor. I think that with just a handful of commands you'll discover that you can be more productive than with your current setup. And by far the easiest way to achieve this goal will be to use a vim mode on top of your current editor. That way you'll minimize the amount of things you need to learn to be proficient with vim and get to reap some benefits (almost) right away.

In any case, the hardest part here won't be learning the commands themselves but feeling comfortable executing them. That's where practice comes in, particularly for the most basic motions hjkl. Some tips that can help you along the way:

  • Practice makes perfect. Start small and persevere. Learn at least one new trick every day and practice. Be mindful of how you use your current editor and try to find ways in which you can make the same things faster with the use of new commands or a different combination of the commands you already know.
  • Try vimtutor. Just type vimtutor in your terminal (in a machine where you have vim installed) and you'll get access to a 30 min tutorial that will help you get started with vim and learn the more basic commands. (In neovim youcan use the :Tutor command to start vimtutor from within vim). You don't need to finish this tutorial in one sitting but I really recommend you to go through it. You'll learn a lot.
  • Play a roguelike to learn hjkl. Classic roguelikes are text-based RPGs where you play in a 2D environment drawn in characters (the player is typically represented as an @). Roguelikes, which have their origins in terminals are very vi friendly and typically allow you to move your character around with hjkl and control the game solely via your keyboard
  • Try Vim Adventures. It is a nice game that helps you learn one vim skill at a time and lets you unlock new keys (and new abilities) after you've proved your worth with the previous ones. A really nice step by step way to learn vim.

Bad First Impressions

The last thing that makes vim hard to learn is the fact that vim gives you a HORRIBLE first impression. You type vim (or mvim for the Mac GUI, gvim for the Windows and UNIX GUI) and welcome to vim!

The white screen of paleness that greets you the first time you open vim

That is what you have to start with (if you open it on a terminal it may be white text on black background). Open a file (like my .vimrc for instance) and there's no syntax highlighting:

The white screen of paleness that greets you the first time you open vim. This time showing a file with no syntax highlighting

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...)

You may be tempted to use a vim distribution - a pre-configured version of vim distributed as a binary or plugin. This will surely give you a better first impression and an editor more in the line to what you're accustomed to in modern editors but it has an enormous drawback: You won't understand how your vim is setup. It will just be a black box of obscurity. This will make you miss part of the essence of vim and one of its core features which is its extensibility and customizability. Instead follow these steps aimed at giving you small wins along the way and designed not to overwhelm you:

Neovim Is Much Nicer To Beginners

Consider following the steps below using neovim instead of vim. Neovim has two things that make it more approachable to newcomers. One, Neovim comes with far better defaults than vim (like syntax highlighting, auto indent, etc), very basic stuff that is not turned on in vim. Two, it has a nicer vimtutor which can be started from within neovim by running the :Tutor and which gives you feedback when you complete the exercises.

  1. Learn the very basics inside vim starting with vimtutor (:Tutor on neovim)
  2. Apply what you learn using a plugin in your editor of choice. Using your current editor will minimize the amount of things you need to learn and allow you to enrich your current editing skills with lots of microediting vim techniques. Depending on how good the vim mode of your editor is, you'll have a more or less pleasant experience.
  3. When you're comfortable with basic vim commands then setup your vim configuration in .vimrc (or init.vim for neovim). Take a look at vim-sensible or at my vim wiki for a minimal and pluginless configuration explained step by step. If you're using Neovim you can just jump over this.
  4. Use a vim plugin manager to enrich the functionality of vim tailored to your workflow (the most established ones are vundle, vim-plug and pathogen, the Modern vim book recommends minpac). The way these plugin managers work most of the time is that they'll clone a git repo containing a series of vim scripts that represent the plugin you need. Vim will pick up those scripts on startup and run them in the context of vim. The Modern Vim book offers great advice into making vim work as a modern IDE.
  5. Check vim awesome for plugins that interest you and the type of applications that you develop
  6. Practice and improve your vim setup and vim configuration over time

And That's All For Now

Wop! This ended up being somewhat longer than I had expected (blushes). Hope you've learned something, found it interesting and that you are feeling a little curious about vim. Have a wonderful day!

Can't Wait To Find out More?

Then here's some more resources:

And a video from the Barbarian Meets Coding Vlog:

ci' is kind of special

In the previous examples I used the f'ci' combination to change the content of a quoted text but ci' would have achieved the same result.

Unlike other text-objects (what we call aw, as, ap i' in previous examples), when you use i' you don't even need to have the cursor over the quoted text. Type ci' at the beginning of a line and it will change the contents of the first quoted text it finds in that line. That is awesome as it saves you from typing f'. I kept the f' because this behavior only applies to the quotes text-object and not the rest. If you want to change the content of parens, brackets, tags, etc you still would need to have the cursor positioned within the area they delimit.

Thank you to

for sharing this in a comment! :D He also recommends the targets plugin that extends this awesome behavior to the rest of the text-objects.


Want to Learn More About Vim?


Then go to read the next article on this series. Enjoy!


  1. Practical Vim is an insanely awesome book on Vim. It follows a tips format from beginner's tips to more advanced ones. In each one of these tips, it provides great background information and context that help you understand not only how to improve your vim skills with new commands and features, but also wider patterns and ideas to help you think like a vim master. All of it with great examples and exercises to help you practice your muscle memory. The original quote reads: Practical Vim is for programmers who want to raise their game. In the hands of an expert, Vim shreds text at the speed of thought. Reading this book is your next step towards that end. 

  2. The h key is beside your index finger readily available. 

Top comments (58)

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