magidc/nvim-config

github github
dotfilesdotfiles-linuxideluaneovimneovim-configneovim-configurationneovim-dotfilesnvimrustrust-idevimvimrc
stars 123
issues 0
subscribers 3
forks 19
CREATED

UPDATED


Neovim configuration for Java, Python, Rust and Lua

This is my personal LUA based configuration for Neovim that I use on a daily basis as Java, Python and RUST IDE. This setup is the product of continuous enhancements based in what I have found in configurations shared by other users. It is an ongoing project that may evolve with time as I come accross with new plugins, refine mappings or refactor configuration files.Feel free to fork this repository and adapt it to your own needs.

Autocompletion lsp autocompletion

Compilation errors lsp errors

Debug dap debugging

Launching Java application java launch

Telescope fuzzy finder telescope usage

Installation

Automatic setup (APT based distributions: Debian, Ubuntu, Pop!_OS...)

install_nvim.sh installs Neovim and everything this configuration needs. Run it as your normal user (it asks for sudo for system packages and to install Neovim into /usr/local):

sudo apt install -y git
git clone --depth 1 https://github.com/magidc/nvim-config.git ~/.config/nvim
bash ~/.config/nvim/install_nvim.sh

It is safe to re-run: what is already installed is skipped, Neovim is rebuilt when a new stable release is out and plugins are updated. Steps:

  1. System packages: build tools, ripgrep, fd-find, zoxide, xclip/wl-clipboard, zsh, tidy, xmllint, python3-venv, unzip...
  2. Latest stable Neovim built from source into /usr/local (NVIM_REF=<tag or branch> builds another one).
  3. Node.js LTS with nvm unless node >= 22 is already there, Rust with rustup and the tree-sitter CLI with cargo.
  4. FiraCode Nerd Font into ~/.local/share/fonts.
  5. This repository into ~/.config/nvim if there is no config yet (CONFIG_REPO=<url> clones a fork).
  6. Plugins (:Lazy! sync), treesitter parsers and Mason packages (LSP servers, debug adapters, formatters), all headless. The lists are the ensure_installed options in lua/plugins/configs/treesitter.lua and lua/plugins/configs/mason.lua (name@version pins a version), plus shellcheck (bashls lints with it) and the formatters in lua/plugins/configs/conform.lua that are not installed yet. Missing Mason packages are installed; update them with :Mason. The prebuilt fuzzy matcher library of blink.cmp is downloaded too.
  7. A Temurin JDK from the Adoptium APT repository if the java on PATH is older than the installed jdtls requires (Java 25 for jdtls 1.63).

Then open a new terminal, set its font to FiraCode Nerd Font and start nvim. LSP servers are installed but not started automatically: use :lsp enable <name> (jdtls starts by itself on Java files), see Language servers and debugging.

Manual setup

Requirements: Neovim >= 0.12, git, curl, tar, unzip, a C compiler and make, tree-sitter CLI >= 0.26.1 (from your package manager, cargo or its GitHub releases, not from npm), ripgrep, fd, zoxide, a clipboard tool (xclip or wl-clipboard), zsh (terminal), tidy and xmllint (formatters), Node.js >= 22 and npm, python3 with venv, Rust with rustup (rust-analyzer needs the rust-src component, Rust code is formatted with rustfmt), a JDK for jdtls (Java 25 for jdtls 1.63) and a Nerd Font. Clone this repository into ~/.config/nvim and start nvim: plugins, treesitter parsers, LSP servers and debug adapters are installed on the first start. Install the formatters and shellcheck (used by bashls) with :MasonInstall stylua beautysh jq prettierd prettier ruff shellcheck.

Language servers and debugging

The language servers listed in lua/plugins/configs/mason.lua (pyright, rust_analyzer, lua_ls, bashls, html, jsonls, clangd...) are installed by mason.nvim and configured with vim.lsp.config() in lua/lsp/init.lua, but they are not started automatically:

  • :lsp enable <name> (e.g. :lsp enable pyright) starts a server for the current buffer and for the next buffers of its filetypes; :lsp disable <name> and :lsp stop stop it.
  • :checkhealth vim.lsp shows the enabled servers and the running clients.
  • Java is the exception: nvim-jdtls starts jdtls when a Java file is opened.

Debugging uses nvim-dap and nvim-dap-ui. The debug adapters are installed by mason-nvim-dap (lua/plugins/configs/mason.lua):

  • Java: java-debug and java-test, loaded into jdtls by nvim-jdtls (lua/lsp/configs/java.lua).
  • Python: debugpy. Programs run with the python of the active virtualenv or conda environment ($VIRTUAL_ENV, $CONDA_PREFIX), otherwise with python3 from PATH.
  • Rust, C and C++: codelldb.

Code is formatted with conform.nvim (<leader>rf); the formatters of each filetype are set in lua/plugins/configs/conform.lua.

Completion

Completion uses blink.cmp (lua/plugins/configs/blink.lua) with LSP, path, buffer and snippet sources; snippets come from LuaSnip and friendly-snippets. No item is preselected and completion is off inside comments. Keys in Insert mode:

  • <C-n>/<C-p> (or <Down>/<Up>) select the next/previous item.
  • <Tab> accepts the item only if one was selected, otherwise it jumps to the next snippet placeholder or inserts a Tab; <S-Tab> jumps to the previous placeholder.
  • <CR> accepts the selected item or, if none is selected, the first one.
  • <C-q> cancels the completion, <C-Space> opens the menu or toggles the documentation window, <C-b>/<C-f> scroll the documentation.
  • <C-k> shows/hides the function signature help, which is also shown while typing the arguments.

In the command line the completion menu opens as you type.

UI theme

Several UI themes are preconfigured in this setup (lua/theme.lua). Active theme is set by editing file lua/settings.lua. Default active theme is Tokyonight, which is also used when the theme name is unknown. Inside tmux the editor background is left transparent, so that the pane colors of tmux show through.

Custom mappings

Most of mappings are defined in file lua/mappings.lua. WhichKey plugin is used in order to provide a description for each one of them: press the leader key (Space) and wait for its popup. Other mappings can be found in specific plugin configuration files in lua/plugins/configs directory. Java-specific mappings are defined in lua/lsp/configs/java.lua and are only available once jdtls is attached. Some features rely on Neovim built-ins: <leader>vu opens :Undotree, <leader>vi opens :InspectTree, and +/_ (Neovim's an/in) expand/shrink the selection to the surrounding syntax node; in Normal mode + starts the selection. In files without a treesitter parser, vim-expand-region expands through words, quotes, brackets, tags and paragraphs instead. m sets marks as in plain Vim, and the leader of vim-visual-multi is <leader>m.

Equivalent mapping configurations for other IDEs VIM integrations

I have created configuration files with (almost) equivalent mappings for Eclipse IDE vim plugin (vrapper), IntelliJ vim plugin (ideaVim) and VSCode vim plugin (vscodevim). These configurations will allow users who are used to these key combinations to remain confortable and efficient while working with other IDEs.

Featured plugins

  • Telescope

    Highly extendable fuzzy finder over lists

  • Neotree

    Tree file explorer

  • Aerial

    Code outline window for skimming and quick navigation

  • WhichKey

    Displays a popup with possible key bindings of the command you started typing

  • Nvim-jdtls

    Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls

  • Nvim-dap

    Debug Adapter Protocol client implementation for Neovim

  • Others...

Troubleshooting

:checkhealth reports missing tools and plugin problems. If you have problems while installing or using this setup, please report an issue.

Feedback and suggestions

I would appreciate suggestions and feedback regarding this Neovim configuration. As it is an ongoing project I will be changing over the time to become more useful and easy to use. Please do not hesitate to contact me if you have any comments