Going Forward With Neovim as a Daily Driver

Using Neovim as a daily driver — the power of a terminal-based text editor is beyond imagination

PRAKHAR KAUSHIK
Better Programming

--

close-up of the letters on a keyboard
Photo by Paul Zoetemeijer on Unsplash

First a question: Why do we need a terminal-based text editor when we have the whole power of VS Code and all its fancy formatting and modules?

The answer is simple.

  • VS Code uses Electron as its core, which means the amount of RAM it takes is huge.
  • Because Neovim is a terminal-based text editor, it enables you to code in any Linux, even without having a display manager or things like cloud or virtual machines or a Docker container, where all you get is just a terminal.
  • As it is terminal-based, all you need is a keyboard to do all the complex operations, which means once the shortcuts become habitual, you never have to lift a finger off your keyboard to use the mouse for any reason.

With this article, I will try to give a workflow in which I use Nvim as my daily driver and all the configurations that one can use to make life easier with Neovim.

First things first. Let's start with installation.

Installing Neovim

Taking it from the official Neovim installation guide, here I will mention just a few popular distros.

Ubuntu

Since 18.04 via the official repository, as in Debian, Neovim is in Ubuntu.

sudo apt install neovim

Python (:python) support seems to be automatically installed.

sudo apt install python-neovim
sudo apt install python3-neovim

macOS / OS X

Pre-built archives

The releases page provides pre-built binaries for macOS 10.11+.

curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz
tar xzf nvim-macos.tar.gz
./nvim-osx64/bin/nvim

Homebrew on macOS or Linux

brew install neovim

Or install the development version of Nvim:

brew install --HEAD luajit
brew install --HEAD neovim

Windows

Chocolatey

  • Release (v0.4): choco install neovim (use -y for automatically skipping confirmation messages)
  • Development (pre-release): choco install neovim --pre

Scoop

  • Release: scoop install neovim
  • Development (pre-release):
scoop bucket add versions
scoop install neovim-nightly

Basics

After we are done setting up Vim, let's just get some basics clear, like how to get started with Vim and do some basic things.

  • h moves the cursor one character to the left.
  • j moves the cursor down one line.
  • k moves the cursor up one line.
  • l moves the cursor one character to the right.
  • 0 moves the cursor to the beginning of the line.
  • $ moves the cursor to the end of the line.
  • w moves forward one word.
  • b moves backward one word.
  • G moves to the end of the file.
  • gg moves to the beginning of the file.
  • `. moves to the last edit.

Again, here’s a longer list of the commands you’ll definitely want to know starting out:

  • d starts the delete operation.
  • dw will delete a word.
  • d0 will delete to the beginning of a line.
  • d$ will delete to the end of a line.
  • dgg will delete to the beginning of the file.
  • dG will delete to the end of the file.
  • u will undo the last operation.
  • Ctrl-r will redo the last undo.

Here are the commands you most need to start out:

  • v highlights one character at a time.
  • V highlights one line at a time.
  • Ctrl-v highlights by columns.
  • p pastes text after the current line.
  • P pastes text on the current line.
  • y yanks text into the copy buffer.

So don't mug them up — once you start using them, this will be your muscle memory.

Customizing Vim

This is how my Neovim looks right now.

screenshot of author’s Neovim screen

It has a search bar, or file explorer, just like VS Code.

screenshot of Neovim screen showing file directory

Neovim also allows you to split your text editor.

screenshot of Neovim screen divided into three sections

Now I will share my Neovim config. Copy it to your Neovim config folder, generally at .config/nvim.

As you can see, the Plug lines indicate all the plugins I am using. Among them, the best is the NERD tree and google vim-codefmt,

The NERD tree allows you to have that dope side file explorer and codefmt autoformats code.

Apart from that, there are some custom shortcut mappings to key combinations. For example, ctrl+b opens a NERD Tree window.

How To Do the Switch

Believe me, the day I did the switch from VS Code to Nvim, it was tough. Even closing the Nvim window becomes a challenge. But once you start using it for a while, it becomes tough to code or write at any place apart from the Vim environment. I don't even know how many times I have typed :w here while typing on Medium :).

My take would be this: Don’t be too hard on yourself, but make it a habit that any small code change will be done using Vim. If a whole project is to be developed, only then switch to something like Sublime or VS Code.

Thanks for reading, do ping me in the comments if you need any help.

Good luck!

--

--

Python Developer interested in learning new languages, also an Active Open Source Contributor.