Skip to content

Vim as a general purpose project editor, and an IDE for Go and Terraform #5

@andykuszyk-form3

Description

@andykuszyk-form3

Introduction

I have used Vim on and off for several years, but have always thought I needed a fully fledged IDE for working professionally on large code bases. I have dabbled with using Vim as an IDE on smaller projects, but have always found myself reverting to using a trusted tool when the going got tough.

Whilst there was never anything wrong with this, I was frustrated by the fact that a single editor couldn't reliably be used across multiple languages (although I'm aware that the JetBrains suite and VS Code go along way to solving this problem), and that the tool itself required a lot of tool-specific learning--when you learn to be an expert in a JetBrains IDE, you don't develop skills in any other tool along the way.

At the beginning of this year (2021), I found myself in the position of pairing with several engineers who used Vim as their go-to editor. The experience and customisation they had in Vim was far beyond anything I had seen up until that point, and it made me realise that I had been using a very vanilla Vim setup for years, without exploring further the possibility of turning Vim into an editor-of-choice for all my projects.

Over the next few months, I tried to use Vim for all my development needs. I only deferred to an IDE when I was under time constraints, and couldn't find out how to do what I needed in Vim. As time went by, I found myself learning more and more about Vim and customising it into a far more powerful tool. Soon enough, I raised my first PR without missing my IDE. A few more weeks went by, and that was the last time I opened an IDE to edit code.

Since then, I have been using Vim exclusively to develop Go and Terraform projects, as well as using it occasionally to contribute changes to Python and Java codebases. I also use it to edit and explore any other type of plain text file, including Markdown, LaTeX, and log files.

I have come to realise that Vim is an excellent editor poised on the boundary between the terminal, Linux/Unix staples (such as grep and sed), and fully-fledged IDEs. With a little bit of extra learning about Vim itself, more experience of Linux tools, and a better awareness of what I actually need from an IDE on a daily basis, Vim has now become the only tool I feel I need on a regular basis to develop software.

In this post, I walk you through the plugins and customisations I've added to Vim to make it usable to this extent, as well as describing the Vim features and keyboard shortcuts that make it so powerful on a day-to-day basis.

If you are searching for ways to make your text editing experience more second-nature, or are dabbling with using Vim as your daily editor, I hope this post will give you some practical steps that will help you on your way.

Keyboard shortcuts

In the table below, I've listed some of the common keyboard shortcuts I use along with which plugin (if any) they rely on, and what they're used for. Below the table I've given some examples of use cases for these shortcuts.

Window management

Key combination Plugin Description
Ctrl-w w - Cycle through windows.
Ctrl-w c - Close window, but keep the buffer open.
Ctrl-w h/j/k/l - Move a window to the left/top/bottom/right.
Ctrl-w T - Move a window to a new tab.

Navigation

Key combination Plugin Description
Ctrl-p Ctrlp Open project files using fuzzy search.
Ctrl-p Ctrl-f Ctrlp Switch to an open buffer using fuzzy search.
Ctrl-] - Go to symbol.
Ctrl-t - Go to previous symbol.

Copy-and-paste

Key combination Plugin Description
Ctrl-r " - Paste yanked text in the command prompt.
Ctrl-w " " - Paste yanked text in a terminal buffer (in term mode).

Commands

Window management

Command Plugin Description
:vert res +50 - Increase the width of the current window by 50 pixels.
:res +50 - Increase the height of the current window by 50 pixels.

Navigation

Command Plugin Description
:grep -R 'foo' ./ - Search for 'foo' in files in ./--akin to a global search for files in a particular path. Uses the same command line args and regex as grep.
:grep -R 'foo' % - Search for 'foo' in files in the current file--akin to a local search in the current file. Uses the same command line args and regex as grep.
:cw - Show search results in a quick find window.
:Ggrep 'foo' vim-fugitive Greps all git files for 'foo' and shows them in a location window--akin to a global search in an IDE.
:%s/foo/bar/g - Replace all instances of 'foo' with 'bar' in the current file. This also works for text selections made in View mode, and uses the same syntax as sed.
:NERDTreeFind NERDTree Show the current file in the NERDTree file browser.

Go-specific

Command Plugin Description
:GoDebugTestFunc vim-go Starts a debugging session by running the test the cursor is currently in.

Plugins

Plugin URL Description
vim-fugitive
NERDTree

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions