Welcome to Neovim! This guide aims to get you familiar with the Braintree Neovim config. Think of it as your roadmap from "I just opened Neovim" to "I'm coding like a pro."
Tip
This getting started guide assumes you have at least some familiarity with vim, so if you're an absolute beginner, check out ESSENTIAL_VIM for a first timer's guide! Feel free to also check out some youtube tutorials to learn the basics - The Primeagen has a pretty good intro series.
Some essential default vim commands are still called out below (marked with ^! like <foo>!), but if you're a total vim noob, you should spend some time learning the vim motion basics before diving into this guide about Braintree's customized Neovim config.
Start here! These tips and shortcuts will immediately make you productive:
- By default, this neovim config has
\! as its<Leader>key<Space>is another common leader key, and many devs using this config have it set up as an "alternate" leader key- If you'd like to see how to customize your leader key, check out LEADER_KEYS
Tip
Most of the keymaps mentioned in this guide start with the <Leader> key. When you see something like <Leader>ff, what that means is you'll first press <Leader> (meaning \, or space, if configured), then f and then f again.
-
This neovim config uses a plugin called
which-keythat acts as an on-demand cheatsheet for discovering or re-discovering keybinds AS you type them! -
Give it a try by hitting your
<Leader>key and it will show you all the available keybinds that could follow<Leader>.- For "groups" of keybinds that are nested under another key after
<Leader>, these group labels are displayed in the popup with a different color. - You cancel any "partial" keybind you've started with
<ESC>to close the menu - You can also navigate backward through this popup with
<BS>(backspace), so feel free to dive in and take a look around!- Pro tip: hitting
<Leader>and then<BS>will show you the available keybinds inNORMALmode in the which-key popup
- Pro tip: hitting
- For "groups" of keybinds that are nested under another key after
<Leader>ff/<Leader><Leader>- Find files by name- Just type part of a filename - try typing "read" to find README.md
<Leader>fb/<Leaedr>be- Switch between files (buffers) you have open- Much faster than clicking tabs!
<Leader>fr- Find files you've recently opened- Similar to
<Leader>fb, but also includes recent files you've already closed
- Similar to
<Leader>nt- Open/close the file tree on the left<Leader>nf- Find your current file in the tree- Useful when you're lost and want to see where you are
<Leader>bb- Back to previous file (buffer)<C-o>! - Back to an older position (previous location in jump list)<C-i>! - Forward to a newer position (next location in jump list)
<C-w>s! - Create a horizontal split (new window below)<C-w>v! - Create a vertical split (new window to right)<C-w>p! /<Leader>ww- Switch to your previous window<C-w>c! /<Leader>wd- Close your current window<C-w>h! - Move to the window to the left of the current one<C-w>j! - Move to the window below the current one<C-w>k! - Move to the window above the current one<C-w>l! - Move to the window to the right of the current one
Once you're comfortable with the basics:
<Leader>fg/<Leader>sg- Search for text across your entire project- Example: Search "login" to find all login-related code
<Leader>sr- Resume your last search- Search for something, scroll through results and pick one, then hit this keymap to get right back to your search results
<C-e>- Scope your search ([e]nter directory)- (hold down
control, then presse, WHILE a search picker is open, then fuzzy find a directory to scope to) - Example: Search for a method name only in
/appor only in/spec
- (hold down
<Leader>sb- Fuzzy find text in your current file- like a more typo-tolerant
/, with previews and line numbers!
- like a more typo-tolerant
<C-q>- Add any search's results to the quickfix list- Operate on your results with
:cdo, or just save your results for later!
- Operate on your results with
<Leader>cc/gcc- Comment/uncomment lines- Works on the current line or highlighted text
- You can also use
gcas an operator, trygc2j(comment this line and the next two down) orgcip(comment inside paragraph)!
y/yy- Copy (yank) to your computer's clipboard- Unlike basic vim, this actually copies to your system clipboard
<C-n>/<M-j>- Open/scroll down in the completion menu<C-p>/<M-k>- Scroll up in the completion menu<C-e>/<M-;>- Close the completion menu<Tab>/<M-l>- Accept a completion suggestion<M-h>- Show/hide documentation for completion suggestions
Tip
When a keymap starts with <C-, that means you should hold down control, then press the following key.
When a keymap starts with <M-, that means you should hold down option (or alt on some keyboards), then press the key.
These option-prefixed completion keymaps are very handy if you're used to the vim hjkl patterns already!
<Leader>cf- Make your code look pretty (auto-format)<Leader>cw- Remove extra spaces at the end of lines<Leader>cfdoes this too, but this one's handy if there isn't a formatter set up for your language
What's LSP? LSP stands for "Language Server Protocol" - it's what makes Neovim understand your programming language. It knows about functions, variables, and can catch errors.
For more information on getting started with LSPs, check out our LSP Guide!
These features work automatically once you open a code file:
Treesitter is a parser generator tool for source code. Unlike traditional vim syntax highlighting that relies on complex regular expressions, treesitter creates an actual parse tree of your code, enabling much more accurate and context-aware highlighting along with other features.
For more information on treesitter, check out our Treesitter Guide
gd- Jump to where something is defined- Click on a function name, press
gdto see the actual function
- Click on a function name, press
K- Show documentation about what your cursor is on- Like a tooltip that explains what a function does
gr- Find everywhere something is used- See all the places a function is called
When you see red squiggly lines (errors):
<Leader>fd- Find errors in the current file<Leader>fD- Find errors accross the entire project[d/]d- Jump between errors (diagnostics) in the current file<Leader>cd- Show diagnostic details for the current line (also displays in the bottom status line)<Leader>dt- Toggle diagnostics on/off- Sometimes LSPs just really don't like whatever you're doing, and you want the noise to go away
<Leader>ca- Show available fixes for a diagnostic- Often can auto-fix imports, typos, and common mistakes
<Leader>cr- Rename a variable/function everywhere- Changes the name in all files - safe refactoring, as long as the LSP supports it
- NOTE:
ruby-lspcan have trouble with this, so make sure to double check its work!
Perfect for when you're writing tests or want to run them:
<Leader>rf- Run the current test file<Leader>rl- Run the last test again<Leader>rb- Run all tests in your project
Once you're comfortable with the basics:
<Leader>bl- Toggle current line blame (on by default)- Great for finding who to ask about confusing code
<Leader>gb- Show full git blame for the current linegitsigns<Leader>gg- Open theLazygitTUI directly inside neovim!- If you're unfamiliar with Lazygit, check out this guide on freecodecamp or this video from Josean Martinez
:Gitsigns- Gitsigns provides lots of cool functionality- Check out the plugin repo to see what it can do! You can use it via command mode, or create your own custom keymaps
- We may include more
Gitsignskeymaps by default in the future
<Leader>al- Log into GitHub Copilot<Leader>aa- Open the copilot chat panel
<Leader>gw- Grep for the word under your cursor<Leader>cs- Show document outline (functions, classes, etc.)<Leader>ws- Search symbols across your whole project<Leader>sk- Search for keymaps by mapping or description<Leader>sh- Search vim help tags<Leader>s"- Search vim registers<Leader>sc- Search your vim command history<Leader>sC- Search for available vim commands
<Leader>wm- "Maximize" the current window<Leader>wh- "Maximize" the current window horizontally<Leader>wv- "Maximize" the current window vertically<Leader>we- "Equalize" window sizes (spread panes out evenly)<C-w>a/<Leader>wa- Toggle window auto-resize behavior
<Leader>e- Open the dotfiles updater to keep your neovim config up to date:Lazy- Open the plugin manager to see what plugins we've installed
<Leader>cm- Open Mason (add support for new languages)<Leader>ci- Show LSP information for current file
<Leader>qs- Save your session<Leader>ql- Load your session<Leader>qd- Delete your session
This Neovim config is totally hackable! Check out the neovim-dotfiles-personal.scaffold repo to see how you can tweak things to your liking.
- Take your time: Master vim basics and neovim navigation tools like
<Leader>ffbefore diving into advanced features - Use the help: Press just
<Leader>and explore available shortcuts in thewhich-keypopup - Don't memorize everything: Focus on the shortcuts you find most useful for your workflow
- Gradually add more: When you find yourself wanting to get around more efficiently, visit the CHEATSHEET to add new shortcuts to your repertoire
- Read the Neovim config: Visit your local configuration at
~/.config/nvimand take a look around to see how it works!
- Find a file:
<Leader>ff→ type filename - Understand the code: Use
gdto jump to definitions,Kfor documentation - Make your changes: Use
<Leader>ccfor comments,<Leader>cafor quick fixes - Test your work:
<Leader>rfto run tests - Clean up:
<Leader>cfto format,<Leader>cwto clean whitespace
- Forgot a shortcut? Press
<Leader>(space) and browse the menu or search for it with<Leader>sk - Code not working? Use
[d/]dto jump between errors, then<Leader>cafor fixes - Can't find something? Try
<Leader>fgto search for text - Lost in the code? Use
<Leader>nfto see where you are in the file tree
Remember: Everyone starts as a beginner! These shortcuts will feel awkward at first, but soon they'll become automatic. Give yourself a week of practice, and you'll be amazed at how much faster you code.