I finally started learning vim, or neovim to be specific, and while to be honest I’m still struggling to learn all the ins and outs of this stupidly extensible editor, I think I’ve found a strong starting setup for my needs. This is largely based on ThePrimeagen’s 0 to LSP video tutorial, where he walks you through the most basic starting setup with lsp, after which you can take it as far as you need, really.
Caution
Please note however, that ThePrimeagen’s 0 to LSP video is outdated as of my writing this article, and you will likely need some extra googling + research to figure out the changes in his current nvim dotfiles. Notably, there is lazy.nvim integration now and I’m not personally aware of the extent of remaining compatibility with packer as of today, although I am still using it as my package manager for this setup.
How to set-up
Pre-requisites:
- Neovim >= 0.9.0
- Node.js >= 16.x (for LSP servers)
- ripgrep (for telescope grep)
- A C compiler (for treesitter)
- packer.nvim
- [Optional] A Nerd font (for icons)
LSP Servers
The following LSP servers will be automatically installed via Mason:
- TypeScript (
ts_ls
) - Vue (
volar
) - ESLint
- Rust Analyzer
Platform-Specific Installation
Windows
- Install Neovim:
winget install Neovim.Neovim
# or
choco install neovim
- Create configuration directory:
mkdir ~\AppData\Local\nvim
- Clone repository:
git clone https://github.com/akashbagchi/dotfiles.git ~\AppData\Local\nvim
- Install Packer:
git clone https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\packer.nvim"
macOS/Linux
- Install Neovim:
# macOS
brew install neovim
# Linux
sudo apt install neovim # Debian/Ubuntu
sudo dnf install neovim # Fedora
- Create configuration directory:
mkdir -p ~/.config/nvim
- Clone repository:
git clone https://github.com/akashbagchi/dotfiles.git ~/.config/nvim
- Install Packer:
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
Platform-Specific Configuration Changes
For Windows Users
- In
lua/theprimeagen/remap.lua
, uncomment Windows keybindings and comment out Mac ones:
-- Uncomment these lines for Windows
vim.keymap.set('n', '<C-/>', 'gcc', { remap = true })
vim.keymap.set('v', '<C-/>', 'gc', { remap = true })
-- Comment out these lines on Windows
-- vim.keymap.set('n', '<D-/>', 'gcc', { remap = true })
-- vim.keymap.set('v', '<D-/>', 'gc', { remap = true })
- In
after/plugin/lsp.lua
, adjust completion keybindings:
local cmp_mappings = lsp.defaults.cmp_mappings({
-- Uncomment these for Windows
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
-- Comment these out for Windows
-- ['<D-p>'] = cmp.mapping.select_prev_item(cmp_select),
-- ['<D-n>'] = cmp.mapping.select_next_item(cmp_select),
-- ['<D-y>'] = cmp.mapping.confirm({ select = true }),
-- ["<D-Space>"] = cmp.mapping.complete(),
})
For macOS Users
- The configuration is already set up for macOS key bindings (
<D-/>
for comments, etc.) - Ensure your terminal emulator (iTerm2, Terminal.app, etc.) is set up to use your installed Nerd Font
- For Volar LSP to work correctly, update the TypeScript SDK path in
lsp.lua
:
lspconfig.volar.setup({
init_options = {
typescript = {
tsdk = vim.fn.expand('~/node_modules/typescript/lib')
-- or globally installed TypeScript:
-- tsdk = '/usr/local/lib/node_modules/typescript/lib'
}
}
})
Additional Platform-Specific Notes
Windows
- Some plugins (like
telescope.nvim
) might work better with PowerShell or Git Bash than CMD - If using WSL, consider installing Neovim inside WSL for a better Unix-like experience
- The
<C-f>
mapping fortmux-sessionizer
won’t work by default; you’ll need to adjust or remove it
macOS
- The Command key mappings (
<D->
) work in GUI Neovim (Neovide, VimR) but might need adjustments in terminal Neovim - For optimal performance, consider using a modern terminal emulator like Alacritty or Kitty
Key Features
File Navigation
- NvimTree: File explorer
- Telescope: Fuzzy finder
- Harpoon: Quick file navigation
Development
- LSP integration with zero-lsp
- Treesitter for syntax highlighting
- Auto-completion
- Git integration via Fugitive
- Comment.nvim for code commenting
- Refactoring tools
- Trouble for error diagnostics
Focus & Productivity
- Zen Mode
- Undotree
- Custom status line
Key Mappings
General
<Space>
- Leader key<leader>pf
- Find files<C-p>
- Git files<leader>ps
- Grep search<leader>e
- Toggle NvimTree<leader>fe
- Focus NvimTree
LSP
gd
- Go to definitionK
- Hover documentation<leader>vws
- Workspace symbol search<leader>vd
- Open diagnostic float[d
/]d
- Previous/Next diagnostic<leader>vca
- Code action<leader>vrr
- Show references<leader>vrn
- Rename
Git (Fugitive)
<leader>gs
- Git status<leader>p
- Git push (in fugitive buffer)<leader>P
- Git pull —rebase (in fugitive buffer)
Editing
J
/K
in visual mode - Move lines up/down<leader>y
- Yank to system clipboard<leader>d
- Delete to void register<D-/>
(Mac) - Toggle line comment<A-S-a>
- Toggle block comment
Navigation
<C-d>
/<C-u>
- Scroll down/up (centered)<C-h/t/n/s>
- Navigate to Harpoon marks 1-4<C-e>
- Toggle Harpoon quick menu
Focus Mode
<leader>zz
- Toggle Zen Mode (with numbers)<leader>zZ
- Toggle Zen Mode (minimal)
Important Notes
- LSP Setup:
- TypeScript/JavaScript LSP is configured for relative imports
- ESLint will auto-fix on save
- Vue support requires TypeScript in your project
- File Types:
- Special handling for
.env
files via Cloak plugin - Treesitter ensures syntax highlighting for major languages
- Special handling for
- Platform Specific:
- Some keybindings are Mac-specific (e.g.,
<D-/>
for comments) - Undo directory is set to Windows path (
%LOCALAPPDATA%
)
- Some keybindings are Mac-specific (e.g.,
- Performance:
- Auto-install of TreeSitter parsers is enabled
- Swap files are disabled, but persistent undo is enabled
- UpdateTime is set to 50ms for responsive git signs
Customization
Most configurations are modular and can be found in:
lua/theprimeagen/set.lua
- Basic Vim settingslua/theprimeagen/remap.lua
- Key mappingsafter/plugin/
- Plugin-specific configurations
Troubleshooting
If you encounter issues:
- Run
:checkhealth
to verify requirements - Ensure all prerequisites are installed
- Try
:PackerSync
to update plugins - Check LSP status with
:LspInfo