DEV Community

Mauricio Voto
Mauricio Voto

Posted on

Vim basics(part 2): Navigation, Configuration and Plugins

Introduction

This post is the second one of this Vim basics series, if you haven't checked v1 yet
you can see some tips to start using this amazing editor.
After talking about Modes and Commands, things will get interesting, because the topics here will be navigation and configuration. With a few navigation tips you can feel the power and potential behind Vim
and in addition, configuration and plugins might show you comfort to put it at the same level as your current text editor and possibly even better - talking about productivity boost, yeah !

Advices

Same as part 1, there are some good advices when talking about navigation and configuration.

  • Navigation's 1st rule: don't use arrow keys, get used to hjkl.
  • Navigation's 2nd rule: practice, practice and practice. You can start here
  • Configuration's main rule: avoid using someone else's entire config file. If you decide using an existing config file, read it first and use only the things you understand and that will be a fit for your needs.
  • Configuration's advice: you'll keep improving it forever :)

Navigation

Navigation is one of the most important vim's skills that you must master in order to reach the best performance.
Moving around using your keyboard only. We can think about navigation by dividing into different topics, the ones that we want to cover here are: screen / file, line and word.
Let's see some (in my opinion) most useful navigation keys:

Screen / File Navigation

When talking about screen, we're aiming the piece of content you are currently viewing in your vim editor and when talking about file, we're aiming the full content.

  • G - go to the first line of the file
  • gg - go to the last line of the file
  • 5G or 5gg - go to the 5th line of the file
  • H - go to the first line of the screen
  • M - go to the middle line of the screen
  • L - go to the last line of the screen
  • zt - scroll the line with the cursor to the top of the screen
  • zz - scroll the line with the cursor to the center of the screen
  • zb - scroll the line with the cursor to the bottom of the screen

Line Navigation

This is about navigating between lines and also navigating to the start and end of the current line.

  • h - move one character left
  • j - move one line down
  • k - move one line up
  • l - move one character right
  • 3j / 3k - moves 3 lines down and 3 lines up respective
  • 0 - moves to the start of the current line
  • $ - moves to the end of the current line

Word Navigation

  • e – go to the end of the current word.
  • E – go to the end of the current WORD.
  • b – go to the previous (before) word.
  • B – go to the previous (before) WORD.
  • w – go to the next word.
  • W – go to the next WORD.

For a delightful preview on something we can get after some time of practice and mastering modes, we can easily do things like multi-line column editing ie:

Ctrl + V
5j
Shift + I
@ + Esc
Enter fullscreen mode Exit fullscreen mode

Configuration

Every person has its own story and it's okay to admire other people's stories. What about start writing your own story and maybe some day other people will admire your story.
That's a good example to follow on your config files.
I started using one from my friend Alan
And then after some time switched to the thoughtbot's one

Plugins

This topic definitely deserves its own post, but since this is a basics series and I am compromised to keep the posts short and simple, gonna try to handle it on a couple lines :)
My personal advice for trying plugins is do it yourself ! The first step is to check out some existing plugin managers and pick your favourite one(I am using Vundle), so here's a list for you:

To customize and manage plugins on vim, you can do it by editing a dotfile at your home folder.
Ie.: for Vundle I have a ~/.vimrc.bundles file and my config lives at ~/.vimrc.
Comments are good to keep them organized.
Here's a list of some popular and (imho) useful / essentials / powerful plugins:

  • NERDTree - tree explorer / sidebar
  • CtrlP - full path fuzzy finder
  • Ack - search in project
  • Fugitive - an awesome Git wrapper
  • Surround - simple quoting/parenthesizing
  • Numbers - better line numbers, that results into better navigation
  • Ctags - to navigate through the code(classes and methods definition)
  • NeoMake - Async linting(only for NeoVim)

I could build a huge list here by suggesting themes, syntax highlight and helpers for different languages, frameworks and same thing for linters, not doing it to keep this series as a starting guide for every developer that wants to start using Vim.

Conclusion

The most beautiful thing about vim, in my opinion, is how this editor pushes you forward and makes you think while using it. Feels like there's always a best or simplest way of doing your actual task.
So, every time you are doing some navigation, try to take some time and think about a better way on doing it, as mentioned in the part 1 post, it's supposed to take some time for you to be productive when using vim, but worth spending some time googling about something that you want to do but don't know or can't remember / figure out.
Same rule applies to configuration and plugins, every time that it's possible, take some time to improve it, customize it and leave the best way you can.
The results can be amazing and you will find yourself very happy about the progress you've done and your editor will be just like your son / daughter.
Stay tunned for more, still have lots of things to cover on future posts, like searching.
Some good references for you and for me:

Top comments (5)

Collapse
 
joshcheek profile image
Josh Cheek

Looks like the site is breaking the lines in ways you weren't intending. The link to v1 also hasn't been filled in with the real url. Anyway, good post, I'd forgotten about several of these, time to brush up :P

Collapse
 
mvoto profile image
Mauricio Voto

Hey Josh thanks for the feedback, did some adjustments and still working to make it better.
Glad that you enjoyed it, looking forward to next ones, hope you can get some cool tips from the next ones.
I am also opened for suggestions, let me know if there's something that you would like to read about for the next posts.

Cheers !

Collapse
 
stevensonmt profile image
stevensonmt

ALE is a great alternative for asynch linting if not using NeoVim.

Collapse
 
mvoto profile image
Mauricio Voto

Oh yeah, I've heard a few times about ALE, but never took some time to try it, since NeoMake always worked fine for me.
Do you have any comments around ALE ?

Collapse
 
stevensonmt profile image
stevensonmt

No big comments. It works seamlessly so you can use it at a low level without thinking about it at all after installation.