DEV Community

Discussion on: Getting Productive with Vim in a Week without Hating It

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.