You don’t need tabs in Neovim

An article about alternatives to tabs in Neovim

Jose Garcia
4 min readApr 11, 2024
A serene landscape featuring two majestic mountains standing side by side, their peaks reaching high into a clear blue sky.
Image by Dall-E-3

Neovim is a terminal-based text editor. It has been around forever.

When I started using Neovim, I kept hearing the same over and over. You don’t need Visual Studio Code(VSC)-like tabs in Neovim.

My mind always was: How do you even code without tabs?

Recently, I tried Nvim without tabs. After several months of coding in such a manner, I haven’t returned to the old ways. Let me tell you, my ability to use other editors died after this.

In this article, I go over alternatives to tabs in Nvim.

Resume

Tabs are inefficient.

I use two plugins to replace tabs:

Telescope. A fuzzy finder that allows you to search either project-wide or the opened buffers.

Harpoon. Gives you fast navigation between key buffers.

Notes

  • Tabs differ in GUI editors like VSC and NVim. In the second, we refer to tabs as buffers. The visual representation of the opened buffers, we call it a buffer line. I will be referring to VSCode-like tabs in Neovim in this article.

I assume you:

  • Have a working Neovim install.
  • Have basic knowledge of Neovim.
  • Know how to install a plugin.

Why tabs?

Reasons to use tabs:

  • We need a visual representation of our open files.
  • They give you visual access to your open files. You can look at them and click on whichever you want to open next.
  • They come installed by default on GUI editors and Integrated Development Environments (IDE). This makes it easy to use them in NVim as well.

Why not tabs?

Reasons to not use tabs:

  • If you open seven or more files, you have to read each tab and even scroll in the tab line to see your files. At this point, you may choose to organize your tabs. An even bigger waste of time.
  • If you have three files or fewer, is efficient to use a tool for fast switching between the opened files. Why do I even need to look at the tabs? It’s better to fast toggle.
  • The best use case for tabs is when you open between four and six files. Even in that case, though, a fuzzy finder is a better fit.

Let’s begin with alternatives to tabs.

Fuzzy Finder: Telescope

Telescope is a plugin that helps you search files in your project.

Install Telescope with this snippet. (This snippet uses the Lazy package manager).

{
'nvim-telescope/telescope.nvim',
dependencies = { 'nvim-lua/plenary.nvim' }
},

With Telescope, you can do:

Project-wide search

With Telescope, you can search for every file in your project. You type in the prompt and you get the files that match your text.

Search query inside Telescope. Telescope shows the files that match.

This is equal to Ctrl + p in VSC. And Shift + Shift in JetBrains.

This is useful in the rare instances when you have to move around between 7 buffers or more.

A simple configuration for a Project-wide search:

local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})

Buffer search

What happens when you have six or fewer buffers? Arguably the best use case for tabs.

You can use Telescope to move around buffers.

Telescope is open searching every opened file (buffer).

This functionality is equal to Ctrl + Tab in VSCode.

The advantage of the buffer finder over tabs is that the buffer finder organizes the buffers by use.

Some basic configurations for buffer search.

local builtin = require('telescope.builtin')

vim.keymap.set('n', '<leader>fb', builtin.buffers, {})

What about 4 or fewer files, though? Oh, you can use the buffer finder for that, or you can use…

Harpoon

Harpoon is a plugin made by the sexiest man to ever live. ThePrimeagen:

ThePrimeagen making a weird face.
Image taken shamelessly from Youtube

ThePrimeagen built Harpoon for fast navigation between 4 or fewer files.

Some simple configurations

local mark = require("harpoon.mark")
local ui = require("harpoon.ui")

vim.keymap.set("n", "<leader>a", mark.add_file)
vim.keymap.set("n", "<C-e>", ui.toggle_quick_menu)

vim.keymap.set("n", "<leader>ha", function() ui.nav_file(1) end)
vim.keymap.set("n", "<leader>hs", function() ui.nav_file(2) end)
vim.keymap.set("n", "<leader>hd", function() ui.nav_file(3) end)
vim.keymap.set("n", "<leader>hf", function() ui.nav_file(4) end)

Check ThePrimeagen’s content or Harpoon’s repo (in the introduction) for more.

Conclusions

I went over the two best options for replacing tabs in Neovim.

  1. Fuzzy finder with Telescope.
  2. Harpoon for fast navigation.

--

--

Jose Garcia

Hello There! I am a fullstack developer, a fan of open source and crypto and an obssesive fella. Well met.