My Neovim Setup

10. June 2024
Timothy Djon

After a long and painful journey with VS Code and a few miserable attempts at setting up Neovim using all kind of different starter templates and setup scripts, I finally managed configure Neovim in a way that satisfies all of my cravings for a efficient and highly customizable IDE.

So to spare you the same struggle I went through, I wrote this article to walk you through on how to quickly get Neovim up and running using the config I fine tuned for my personal development needs, which is mostly web development.

I will not go into the details of every single plugin and configuration but overall what this config includes is:

  • Auto-completion
  • Linting
  • Code actions
  • File Explorer
  • Startup Page
  • Fuzzy finder for String and File search
  • Vertical and Horizontal Tiling
  • Vim Key suggestions
  • Syntax Highlighting
  • and To-Do Comments

At the end of the article I will have a cheat sheet for all the custom keybindings I added.

Prerequisites

Make sure you have at least Neovim version v0.08.0 installed, because a few of the plugins require that as minimum version. Personally, at the moment of writing this, I use version v0.11.0-dev which is the current unstable release, which works just fine for me but your mileage may differ.

you can install the version I have using:

1sudo apt remove neovim 2sudo add-apt-repository ppa:neovim-ppa/unstable 3sudo apt update 4sudo apt install neovim

Setup

clone my config repository so it sits in home/timy/.config/nvim after that you can either go through all folder and rename timy to your own name or accept that I am immortalized inside of your computer.

Anyways you will end up with this folder structure:

/home/timy/.config/nvim

1. 2├── cheatsheet.md 3├── init.lua 4├── lazy-lock.json 5├── lua 6│   └── timy 7│   ├── core 8│   │   ├── init.lua 9│   │   ├── keymaps.lua 10│   │   └── options.lua 11│   ├── lazy.lua 12│   └── plugins 13│   ├── alpha.lua 14│   ├── autopairs.lua 15│   ├── auto-session.lua 16│   ├── bufferline.lua 17│   ├── colorscheme.lua 18│   ├── comment.lua 19│   ├── dressing.lua 20│   ├── formatting.lua 21│   ├── indent-blankline.lua 22│   ├── init.lua 23│   ├── linting.lua 24│   ├── lsp 25│   │   ├── lspconfig.lua 26│   │   └── mason.lua 27│   ├── lualine.lua 28│   ├── nvim-cmp.lua 29│   ├── nvim-tree.lua 30│   ├── substitute.lua 31│   ├── surround.lua 32│   ├── telescope.lua 33│   ├── todo-comments.lua 34│   ├── treesitter.lua 35│   ├── trouble.lua 36│   ├── vim-maximizer.lua 37│   └── which-key.lua 38└── README.md

You can find a lot of the custom keymappings inside of the keymaps.lua file but everything that's plugin specific is kept inside its respective .lua file inside of the plugins directory.

So now if you have everything setup correctly you can open Neovim inside of the terminal using either neovim or neovim ${path}. The former will open the custom welcome and the latter just open directory you specified inside of the nerd-tree file explorer.

I highly reccomend skimming over the cheat sheet, as you will probably need it to navigate the file explorer if this is your first time using nerd-tree.

If some part of the configuration is not working for you or you simply have suggestions for improving the current configuration, consider creating a Issue on Github to let me know. I would highly appreciate it.

Troubleshooting

  • If neovim is extremely slow and laggy double and triple check if battery saver is activated on your laptop.

  • If <leader>fs string fuzzyfinder is not working, try installing ripgrep . Thanks David for pointing that one out.


Cheatsheet for new commands

Exit Insert Mode

  • jk: Exit insert mode with jk.

Search Highlighting

  • <leader>nh: Clear search highlights.

Increment/Decrement Numbers

  • <leader>+: Increment number.
  • <leader>-: Decrement number.

Window Management

  • <leader>sv: Split window vertically.
  • <leader>sh: Split window horizontally.
  • <leader>se: Make split windows equal size.
  • <leader>sx: Close current split window.
  • <leader>sm: Maximize/minimize a split.

Tab Management

  • <leader>to: Open new tab.
  • <leader>tx: Close current tab.
  • <leader>tn: Go to next tab.
  • <leader>tp: Go to previous tab.
  • <leader>tf: Open current buffer in new tab.

Session Management

  • <leader>wr: Restore session for current working directory.
  • <leader>ws: Save session for current working directory.

Formatting and Linting

  • <leader>mp: Format file or range (in visual mode).
  • <leader>l: Trigger linting for current file.

File Explorer (NvimTree)

  • <leader>ee: Toggle file explorer.
  • <leader>ef: Toggle file explorer on current file.
  • <leader>ec: Collapse file explorer.
  • <leader>er: Refresh file explorer.

Substitution

  • s: Substitute with motion.
  • ss: Substitute line.
  • S: Substitute to end of line.
  • s (visual mode): Substitute in visual mode.

Telescope (Fuzzy Finder)

  • <leader>ff: Fuzzy find files in current directory.
  • <leader>fr: Fuzzy find recent files.
  • <leader>fs: Find string in current directory.
  • <leader>fc: Find string under cursor in current directory.
  • <leader>ft: Find todos.

Todo Comments Navigation

  • ]t: Next todo comment.
  • [t: Previous todo comment.

Trouble (Diagnostics and Todo List)

  • <leader>xx: Open/close trouble list.
  • <leader>xw: Open trouble workspace diagnostics.
  • <leader>xd: Open trouble document diagnostics.
  • <leader>xq: Open trouble quickfix list.
  • <leader>xl: Open trouble location list.
  • <leader>xt: Open todos in trouble.

Nvim-cmp (Completion)

  • <C-k>: Previous suggestion.
  • <C-j>: Next suggestion.
  • <C-b>: Scroll docs up.
  • <C-f>: Scroll docs down.
  • <C-Space>: Show completion suggestions.
  • <C-e>: Close completion window.
  • <CR>: Confirm completion.

Nvim-Treesitter

  • <C-space>: Initiate selection or node incremental selection.
  • <bs>: Node decremental selection.