Embracing Neovim

October 28, 2024

Up until now, the terminal has been one of the most powerful tools on a computer. From chatting on IRC to performing complex security analysis, developers leverage its versatility across many use cases. However, terminal-based coding has often seemed less approachable compared to modern GUI editors.

Personally, I never liked Vim. Writing code in a terminal felt outdated, and I was very comfortable in my VS Code setup. The thought of switching editors felt unnecessary. I even tried using Vim for a day but quickly gave up—it just wasn’t working for me.

But then, something changed. Recently, Lee Robinson shared a tutorial called Vim for React Devs, which piqued my curiosity. Around the same time, I came across videos featuring developers like ThePrimeagen using Neovim—a modern, more flexible version of Vim—as their go-to editor. Unlike Vim, Neovim offers a suite of advanced features, like plugins, which can be customized to meet a developer’s unique workflow.

So, I decided to give it another shot. I spent some time learning basic Vim motions, and once I was comfortable, I took the plunge into Neovim. With plugins installed, I was hooked! Suddenly, I had an editor tailored to my preferences, where I could navigate seamlessly without relying on a mouse or touchpad. The productivity boost was tangible, and I knew this setup had the potential to become my default editor.

In this post, I aim to share my story, how I overcame my initial reluctance, and how you too can transform your coding experience with Neovim. Whether you’re a loyal GUI user or just starting to dip your toes into terminal-based coding, I hope this guide inspires you to take the leap.

Why Neovim?

Initially, I resisted the idea of switching to a terminal-based editor because it felt like a step back. Why trade the convenience of point-and-click interfaces for a tool that requires memorizing commands? However, after making the transition, I discovered that it was not about regressing—it was about taking control of my coding environment.

Here’s why I finally moved to Neovim:

  • Customization: Everything is customizable, from themes and plugins to keybindings and workflows. I could tailor the editor to fit my needs perfectly.
  • Keyboard Efficiency: While using the mouse is familiar, it slows down productivity. Neovim allows almost every action to be performed through keyboard shortcuts, significantly speeding up my workflow.
  • Lightweight and Fast: No bloat, just the essentials. Neovim starts up instantly, even with numerous plugins.
  • Robust Plugin Ecosystem: I was pleasantly surprised by the wealth of plugins available, rivaling the features I loved in GUI editors.

Getting Started with Neovim

You don’t need to abandon your current editor immediately. I didn’t either. I recommend starting slowly by setting up Neovim alongside your existing editor and gradually transitioning as you grow more comfortable. And don’t worry—you don’t need a fancy Linux machine to get started. Neovim can run on almost anything, including Android via Termux.

How to Set Up Neovim

On Linux or macOS, installing Neovim is straightforward:

# For Ubuntu/Debian
sudo apt install neovim

# For macOS using Homebrew
brew install neovim

On Windows, I used Chocolatey:

choco install neovim

And yes, I even experimented with it on Android using Termux:

pkg install neovim

Essential Plugins

One of Neovim’s strengths is its rich plugin ecosystem. Here are some useful plugins that will increase your productivity:

  1. Telescope: A fuzzy finder that revolutionized how I navigate files. Now, <Ctrl-p> opens files faster than I ever could with a mouse.
  2. nvim-tree: A file tree plugin that simplifies project navigation. I can toggle it on and off with <Ctrl-n>.
  3. lualine: A highly customizable status line that adds clarity to my workspace.
  4. Coc.nvim: An autocompletion engine that rivals IntelliSense in VS Code.
  5. vim-commentary and vim-surround: Tools for easily commenting out code and manipulating surrounding characters, making editing a breeze.

Getting the Plugins

I started by installing vim-plug, a plugin manager that makes managing plugins a cinch:

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Next, I created my configuration file at ~/.config/nvim/init.vim and added my preferred plugins:

call plug#begin('~/.config/nvim/plugged')

" Essentials
Plug 'nvim-telescope/telescope.nvim'
Plug 'kyazdani42/nvim-tree.lua'
Plug 'nvim-lualine/lualine.nvim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'

" Development Enhancements
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'preservim/nerdtree'
Plug 'junegunn/fzf.vim'
Plug 'vim-airline/vim-airline'

" Productivity
Plug 'jiangmiao/auto-pairs'
Plug 'mbbill/undotree'
Plug 'liuchengxu/vim-which-key'
Plug 'vimwiki/vimwiki'

call plug#end()

" Custom Keybindings
nnoremap <C-p> :Telescope find_files<CR>
nnoremap <leader>f :Telescope live_grep<CR>
nnoremap <C-n> :NvimTreeToggle<CR>
nnoremap <leader>b :Telescope buffers<CR>
nnoremap <leader>q :q!<CR>
nnoremap <leader>s :w<CR>
nnoremap <leader>c :Commentary<CR>
nnoremap <leader>u :UndotreeToggle<CR>
nnoremap <leader>g :Gstatus<CR>
nnoremap <leader>w :VimwikiIndex<CR>

Once my init.vim file was ready, I launched Neovim and ran :PlugInstall to install all the plugins. The process was smoother than I anticipated, and soon I had an editor that felt distinctly mine.

Optimizing Your Workflow

One of the joys of using Neovim is crafting a workflow that feels natural. Getting familiar with Neovim’s modal editing and keybindings is key to productivity. Here are some essentials:

Basic Movements

h, j, k, l: Move left, down, up, and right.

w, e, b: Navigate words.

0, $: Go to the beginning or end of the line.

Editing Shortcuts

i: Insert mode.

:w: Save.

:q: Quit.

:wq: Save and quit.

:e filename: Open a file.

Other useful key bindings

  • File Navigation: <Ctrl-p> for quick file searches and <leader>f to search within the project.
  • File Tree: <Ctrl-n> to toggle the file tree—perfect for getting an overview of my projects.
  • Editing: <leader>s to save without taking my hands off the keyboard, and <leader>c for quick commenting.
  • Undo Visualization: <leader>u opens the undo tree, providing a visual representation of my changes—a game changer.
  • Buffers: <leader>b allows me to switch buffers effortlessly.

Cheat Sheet for Essential Vim Motions

Word-Based Navigation

w, e, b: Move by words.

Line Navigation

0, $: Beginning/end of the line.

Search and Replace

/text: Search for “text.”

:%s/old/new/g: Replace all occurrences of “old” with “new.”

Keeping Configurations in Sync

One of my biggest concerns was losing my configurations if I switched machines or encountered issues. Using Git turned out to be the perfect solution. I committed my setup to a GitHub repository, so my configuration is just a git clone away whenever I need to switch devices:

cd ~/.config/nvim
git init
git add .
git commit -m "Initial Neovim config"

Now, I can synchronize my setup across all devices, including Termux when coding on Android.

A Workflow That’s Uniquely Yours

Switching to Neovim wasn’t just about adopting a new tool—it was about discovering a different coding philosophy. It prompted me to rethink how I interact with my code, encouraged the creation of a streamlined, distraction-free workspace, and deepened my appreciation for keyboard-driven workflows.

This isn’t about abandoning GUI-based editors; it’s about choosing the tools that best fit your workflow. For me, that tool is Neovim. If you’ve read this far, perhaps it could be the right choice for you too. Give it a shot, customize it to your preferences, and you might be surprised by how natural it feels.