This repo is a minimalistic yet capable configuration for Neovim.
If you are updating from an earlier version of this config, reinstall
treesitterin case it gives an error! Type:Lazy, press x onnvim-treesitterto remove it, and then press I to install it again.
If you program in C++ or Python, you are going to enjoy the advanced debugging support provided by this configuration. Especially if you do competitive programming.
However, this configuration provides LSP support for many languages.
- Install one of these fonts: https://www.nerdfonts.com/font-downloads. That
is, put the font files into a new subdirectory of
/usr/share/fonts/truetype/and runfc-cache. - Install
ripgrep,xclip,tar,curl,python3-venv, andunzip. - Install
tree-sitter-cliof version 0.26.1 or later. If you use Ubuntu or another distro where this package is outdated, install it withcargo:
# Install Rust - skip next 2 lines if already installed
wget --timeout=5 https://sh.rustup.rs -O rustup.sh # get the rust installer
sh rustup.sh # install Rust
cargo install tree-sitter-cli- Change directory into
~/.config/nvim. Clear the directory if it contains files or subdirectories. - Clone this repo:
git clone https://github.com/Error10556/nvim-config.git . --depth=1 - Optionally, install language servers, formatters, linters, or debug adapters:
open up
nvim, type:Mason, and pick what you like. For a smooth experience, useclangdfor C/C++ (installed by default)debugpyfor Python debugging (but installed as a system-wide packagepython3-debugpy)codelldbfor C/C++ debugginglua-language-serverfor Luabasedpyrightfor Python (installed by default)goplsfor Golang
The configuration makes several remaps (custom bindings) and creates a few user commands.
- Ctrl + E: open Neovim's default file explorer,
netrw. - Space, S: replace all occurrences of the word under the caret.
- Space, O: when used on an empty line, insert two empty lines (one above, one below) and start editing the middle one.
- Space, [: insert a pair of square brackets and start editing an empty line between them.
- Space, { (which is Space, Shift + [): insert a pair of curly braces and start editing an empty line between them.
- Space, Space, [: insert a pair of square brackets with a space before the left bracket and start editing an empty line between them.
- Space, Space, { (which is Space, Space, Shift + [): insert a pair of curly braces with a space before the left brace and start editing an empty line between them.
- Space, A: copy all the text in the file into the clipboard.
- (In visual mode) Shift + J: move the selected lines down.
- (In visual mode) Shift + K: move the selected lines up.
- (In visual mode) Space, D: delete the selected text without copying it into the default buffer.
:Theme: quickly switch between light and dark themes.
- Shift + K: see information about the object under the caret.
- G, D: go to the definition.
- G, Shift + D: go to the declaration.
- G, I: go to the implementation.
- G, O: go to the type definition.
- G, R: see all references.
- G, S: get help on the function signature.
- G, L: see the diagnostic messages (errors, warnings, hints, and information) on this line.
- F2: rename the object under the caret.
- F4: choose one of the suggested code actions (e.g. to resolve an error).
- [, d: go to the previous problematic line.
- ], d: go to the next problematic line.
- Space, =: format the file using the LSP.
:Clangfmt: add a.clang-formatfile to the current working directory that contains Microsoft-style C++ formatting settings.- Ctrl + Space: bring up the autocompletion menu if it is not already open.
In the autocompletion menu:
- ↑: select the previous option.
- ↓: select the next option.
- Ctrl + U: scroll the documentation upwards.
- Ctrl + D: scroll the documentation downwards.
- Tab or Enter: select the current option. If no option is selected, Tab selects the first one, and Enter inserts a newline.
After selecting a snippet:
- Ctrl + L: edit the next placeholder.
- Ctrl + K: edit the previous placeholder.
- Space, Z: execute
./run-current-program.sh "(your file)"in Neovim's terminal
My quick-and-dirty run-current-program.sh for Haskell:
#!/bin/env bash
set -e
if [ ! -f prog ] || [ "$(date --reference=prog +%s)" -lt "$(date --reference="$1" +%s)" ]; then
ghc -o prog "$1"
fi
echo
./progFor C++ you could have:
#!/bin/env bash
set -e
if [ ! -f prog ] || [ "$(date --reference=prog +%s)" -lt "$(date --reference="$1" +%s)" ]; then
g++ "$1" -o prog
fi
echo
./progFor Python:
#!/bin/env bash
echo
python "$1"- Space, D: open or close the debugging interface.
- Space, T: open or close the task log (possible tasks
are
Build,Build with a different compiler,Clean, etc.). - Space, R: run a task (possible tasks
are
Build,Build with a different compiler,Clean, etc.). - F5: compile and launch the program.
- F9: add or remove a breakpoint.
- Shift + F9: add a conditional breakpoint.
:Codeforces: add a.vscodesettings directory to the current working directory with debugger settings convenient to use with competitive programming problems.
When a program is running:
- F1: see the value of a variable under the caret.
- F5: resume running.
- F6: run the program to the cursor.
- F7: terminate the program execution.
- F10: step over (execute the current line and move to the next one).
- F11: step into (descend into the function called on this line).
- F12: step out (run the program until the current function returns).
- Space, P, S: see all variables in all scopes.
- Space, F, F: search file names.
- Space, F, G: search file names in the Git repository, if it is initialized.
:RG: search file contents.
Do not like melange? Want to add custom keybindings? Write your own options
to ~/.config/nvim/lua/conf/custom.lua. This file will be loaded last. If it
does not exist, the melange colorscheme gets applied.
Example of custom.lua:
vim.cmd[[colorscheme koehler]]
- ThePrimeagen for the video 0 to LSP;
- IgorLFS for an awesome article that explains setting up a debugger;
- VonHeikemen for another amazing article that explains LSP server integration.