DEV Community

Cover image for Getting Productive with Vim in a Week without Hating It

Getting Productive with Vim in a Week without Hating It

Nick Janetakis on April 01, 2019

This article was originally posted on March 19th 2019 at: https://nickjanetakis.com/blog/getting-productive-with-vim-in-a-week-without-hating-it ...
Collapse
 
biros profile image
Boris Jamot ✊ /

Nice feedback, thanks!

Maybe some day...

But I'm a bit disappointed: I was expecting a developer feedback of Vim usage, not just typewriting.

How to navigate through files in a given project?
How browse the code like you ctrl+click in IDE?
How to lint your code?
How to pretty-print?
How to refactor?
...

Maybe in a next article? :)

Thanks again for your post!

Collapse
 
nickjj profile image
Nick Janetakis • Edited

How to navigate through files in a given project?

I use fzf and fzf.vim. It's like Ctrl+P in Sublime / VSCode but better (there's more ways to search your project than just by file name).

I also use nerdtree to occasionally explore a project when I just want to poke around or rename / create / remove files, but 99% of the time I'm using fzf with multiple split panes.

Everything is listed in my vimrc at github.com/nickjj/dotfiles.

How browse the code like you ctrl+click in IDE?

I never used this feature in VSCode because it didn't work properly since I run my apps in Docker. VSCode isn't aware of code running in Docker yet (not in a way that's seamless at least).

How to lint your code?

Due to the same reasons as above I lint my code running the raw lint command, such as flake8 for Python and shellcheck for Bash.

This could be improved upon by creating custom key binds for each language to run that specific tool inside of an existing container. Basically, have 1 bind I can press that calls different commands depending on what language I'm editing.

But Vim does have plugins to lint your code on the fly and show visual warnings near the line number. I just don't use them personally (and didn't with VSCode either because it slowed typing down a lot).

How to pretty-print?

What do you mean by that? Some type of auto-formatting tool? I never use these tools unless the language specifically supports it (such as Elixir and Go). It can be done with Vim plugins.

How to refactor?

The same as I did with VSCode. Find / replace with case sensitivity. I find this process a lot easier with Vim since it has world class support for finding and changing text in a selection, a single file or multiple files.


With that said, there's also the concept of LSPs microsoft.github.io/language-serve... and Vim has multiple servers and clients for popular languages.

For example there's Ale github.com/w0rp/ale and coc github.com/neoclide/coc.nvim.

This is a fairly new technology but when it's all set up you'll be able to get really really good auto-complete, jump to definition, linting and other IDE-like functionality.

At some point I'll check those out, but right now between what I have along with snippets I find things very pleasant to use on a day to day basis.

Collapse
 
biros profile image
Boris Jamot ✊ /

I agree that Vim is mostly a text editor and not an IDE, so I can't figure out how a developer can be as productive with Vim as with an IDE.
I would love being able to develop a real project with Vim, but the few tries I gave to it with PHP or Go projects have failed. When it comes to refactoring, find-and-replace is not enough.
I know about LSP and most of the IDE are using them as Vim does, but IMO it's not enough to have an acceptable developer experience. Or maybe, as you said, it's a new technology and it's not ready to use.
I also know about fzf plugin, because I use SpaceVim, but I never really tried it.
What I saw from SpaceVim sounds very, very exciting, so maybe some day it will be working great.

Thread Thread
 
nickjj profile image
Nick Janetakis • Edited

I highly recommend getting used to fzf, but also using the commands listed here: github.com/junegunn/fzf.vim. It makes it so easy to open files and find things across multiple files, especially if you bind them to a key.

I don't know if spacevim sets up binds for fzf, but open Vim in a directory with your project, then type :Files and then start fuzzy typing for a file you want to open. Normally you would map :Files to a key so it's only 1 key press away.

Also for find / replace, there's a few shortcuts you can do to make it really easy to replace things in the selection, the whole file or multiple files. This isn't related to fzf.

Like, all you do is select a phrase, hit a hotkey to find all the spots where it's used, then hit another hot key to initialize a replace and start typing your replacement term. Some of these binds are in my vimrc.

Collapse
 
skydevht profile image
Holy-Elie Scaïde

That's a little out of scope for vim. There's a lot of plugins for getting an IDE like experience, but the whole point of vim is text edition, not running other tools. I'm a primarily a web developer and my config is heavily geared towards that. It's a per user thing.

Collapse
 
biros profile image
Boris Jamot ✊ /

I totally agree.
IMO, each developer should build its own IDE.
I use tmux along with vim to build a kind of custom IDE. But nevertheless, there are a bunch of things that you can only do in the editor itself: refactoring, syntax highlighting, jump-to-definition, debugging. I found plugins for many of the features I need, but refactoring is poor. Or maybe I need time to understand how it works, and time is always running out !

Thread Thread
 
skydevht profile image
Holy-Elie Scaïde

There's languages (Statically typed ones : Java, Kotlin,...) and projects (big and legacy) I'll totally use an IDE for. But a lot of things can be done with just a text editor. Plugins I used not related to vim customizations itself are for linting, autocompletion, snippets, git and running various other tools... My basics for a pluging is fast editing. Any other tasks, I switch to a better tool.

Collapse
 
haruanm profile image
Haruan Justino

How browse the code like you ctrl+click in IDE?

andrew.stwrt.ca/posts/vim-ctags/

How to lint your code?
How to pretty-print?
github.com/w0rp/ale/

How to refactor?
I don't have much experience here to help with

Collapse
 
jeikabu profile image
jeikabu

I've never regretted learning vim/emacs. That said, I tend to use a "traditional" IDE (VS, VS Code, XCode) when programming.

Your "VIM is Comparable to a Video Game" comment caught my eye. I've been trying to slog through my Steam backlog and started playing "Epistory: Typing Chronicles". It's unusual in that it's a typing game, but also that you use JIFE for movement (i.e. instead of WASD). Makes me wish there was something like that for VIM. Someone recently posted here about games that are like programming, maybe that's why "gamification" is on my mind.

Collapse
 
defiance profile image
Defiance Black

Makes me wish there was something like that for VIM.

Hola, meet Vim Adventures.

First level had me for a minute, then I remembered the game is just VIM. So, tip: top far right land square, down over the water squares. Enjoy.

Collapse
 
jeikabu profile image
jeikabu

I should have guessed such a thing exists....

Thread Thread
 
adamspannbauer profile image
Adam Spannbauer

Another gamified Vim learner is PacVim

Collapse
 
jrtibbetts profile image
Jason R Tibbetts

How long did it take for you to get used to Vim?

Get used to it? A few months.

Use it well? 20+ years, and counting.

My mentor literally SCREAMED at me when pair programming because I couldn't get the hang of yanking words quickly enough. This was after maybe 2 weeks of learning vi, and only a few months after learning *nix.

Collapse
 
deusmxsabrina profile image
Sabrina

Nice post, I like how candid you were about your experience. 👍

Vimtutor over a few weekends got me productive enough with vim for me to switch over; the level of customizability and the power of modal text editing some things I just can't quite quit.

PacVim looks like it could be fun as well for a more gamified learning approach, but I've not tried it: github.com/jmoon018/PacVim.

Thanks for sharing!

Collapse
 
learnbyexample profile image
Sundeep

Well written article, inspiring to read even if I already know and use gvim as your learning process shows both initial struggles followed by rewards, etc

I've been using gvim for more than 10 years now, created a reference guide (github.com/learnbyexample/vim_refe...) but these days, I don't think I'm using it to the best of my abilities.

Just a few features like search, search and replace, open new line, context editing (especially in markdown to replace text between backticks, quotes, brackets, etc), complete word using Ctrl+P, complete line using Ctrl+l, shortcut to insert markdown code block and that's about it I think. Never used plugins.

Collapse
 
phlash profile image
Phil Ashby

I make a point of trying to learn something new every day. For the first 5 years using vi, it was vi commands :) Serious point - as you explain nicely above, you can get started and be productive with a dozen or so commands, then spend years learning tricks to hone your experience. Emacs is similar, but I never did like multi-key pressing, YMMV.

As for tuning, I've pretty much stuck with the default .vimrc I get with Debian's packaged version, a couple of adjustments for expanding tabs to 4 spaces (so shoot me tab fans!) and that's it. Probably 'cause vim is pretty new compared to the 25 years using plain old vi, I like the syntax colouring most of the time, but I also turn it off now and then as it can be distracting, especially when it messes up.

Collapse
 
tomasdrozdik profile image
drozt

Nice article!

Personally I find vim as really nice tool to edit text and code. But it can be rather tedious to use pure vim for programming in e.g. Java or C#. Especially when working on solutions created by some IDEs. That's why I really appreciated having a build in vim mode in IDEs e.g. form JetBrains like IDEA and PyCharm even Vim mode for VSCode.

Obviously it can be hard to tweak it like traditional vim but most of the things are set up out of the box and you can enjoy vim typing experience and when in insert mode even most of the IDE build-in shortcuts work as expected. So it's a win win :)

Collapse
 
mathtauathogen profile image
MathTauAthogen

I initially made my own vimrc, but after a time found that I preferred the Ultimate Vimrc to anything I could create.

Collapse
 
hyperhead profile image
Hyperhead

Use a 60% mechanical keyboard. That's the best way to wean you off those arrow keys.

Collapse
 
perigk profile image
Periklis Gkolias

How can you hate vim? :)