Nvim additions and fixes
This commit is contained in:
1 parent
cbd460d470
commit
bd598f5f0e
2 files changed
+765
-34
No files matched your search
+60
-14
@@ -4,6 +4,25 @@ A single-script Neovim configuration built around C/C++ development (CMake + cla
|
||||
|
||||
Supports **Fedora, Ubuntu, Debian, and Arch Linux** (and their common derivatives — Pop!_OS, Linux Mint, Manjaro, EndeavourOS, etc. — via `/etc/os-release`'s `ID_LIKE`) — the script detects which one you're on and uses the right package manager and package names automatically.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Installing](#installing)
|
||||
- [What gets installed](#what-gets-installed)
|
||||
- [Editor basics](#editor-basics)
|
||||
- [Look & feel](#look--feel)
|
||||
- [Buffers & tabs](#buffers--tabs-bufferline)
|
||||
- [Text search (Telescope)](#text-search-telescope)
|
||||
- [File explorer (nvim-tree)](#file-explorer-nvim-tree)
|
||||
- [LSP & code intelligence](#lsp--code-intelligence)
|
||||
- [Autocompletion & snippets](#autocompletion--snippets)
|
||||
- [Documentation generation](#documentation-generation)
|
||||
- [Debugging (nvim-dap)](#debugging-nvim-dap)
|
||||
- [Terminal](#terminal)
|
||||
- [Git](#git)
|
||||
- [Hex viewer](#hex-viewer)
|
||||
- [Formatting and linting](#formatting-and-linting)
|
||||
- [Known quirks](#known-quirks)
|
||||
|
||||
## Installing
|
||||
|
||||
```bash
|
||||
@@ -16,9 +35,9 @@ chmod +x setup_neovim.sh
|
||||
The script:
|
||||
1. Detects your distro and installs system packages via the right manager (`dnf`/`apt`/`pacman`), plus two Nerd Fonts (JetBrainsMono, Cascadia Code) for icon glyphs.
|
||||
2. Wipes and rewrites `~/.config/nvim`.
|
||||
3. Writes a personal `~/.clang-format` fallback (see [Formatting](#formatting)).
|
||||
3. Writes personal `~/.clang-format`/`~/.clang-tidy` fallbacks (see [Formatting and linting](#formatting-and-linting)).
|
||||
|
||||
First launch will take a minute or two: `lazy.nvim` bootstraps itself and installs all plugins, then Mason installs the language servers and `codelldb`.
|
||||
First launch takes a minute or two: `lazy.nvim` bootstraps itself and installs all plugins, then Mason installs the language servers and `codelldb`.
|
||||
|
||||
### Distro-specific notes
|
||||
|
||||
@@ -40,9 +59,11 @@ Package names vary by distro (see the script for the exact list per package mana
|
||||
|
||||
- Relative + absolute line numbers, system clipboard integration (`unnamedplus`), persistent undo, smart-case search, always-on sign column.
|
||||
- Tab width: **4**, using real tab characters — not expanded to spaces.
|
||||
- `c`/`cpp`/`javascript`/`typescript` indentation uses Neovim's own built-in per-filetype indent logic (`cindent` for c/cpp, the bundled JS/TS indent scripts for the rest) rather than treesitter's indent module — treesitter's indent is known to be unreliable for these specifically (inconsistent brace placement, phantom extra indent on nested blocks), more so since the `nvim-treesitter` branch this config uses is frozen upstream (see [Known quirks](#known-quirks)). `css`/`json` are also curly-brace languages that can hit the same issue — worth disabling there too if it comes up.
|
||||
- Comments don't auto-continue onto a new line when the current line has real code on it — pressing Enter or `o`/`O` there starts a plain new line. On a comment-*only* line, Enter continues it with the same marker (`//`, `#`, or `--`); pressing Enter a second time with nothing typed breaks out instead of continuing again, clearing that line — same convention Vim itself has always used for this.
|
||||
- Bracket/quote pairs auto-close as you type: `()`, `{}`, `[]`, `""`, `''`.
|
||||
- True color, rounded borders on floating windows (hover, LspInfo, Mason, etc. — Neovim 0.11+), styled window separators.
|
||||
- OSC 52 clipboard support, so yank/paste works correctly over SSH.
|
||||
- `c`/`cpp`/`javascript`/`typescript` indentation uses Neovim's own built-in per-filetype indent logic (`cindent` for c/cpp, the bundled JS/TS indent scripts for the rest) rather than treesitter's indent module — treesitter's indent is known to be unreliable for these specifically (inconsistent brace placement, phantom extra indent on nested blocks), more so since the `nvim-treesitter` branch this config uses is frozen upstream (see [Known quirks](#known-quirks)). `css`/`json` are also curly-brace languages that can hit the same issue — worth disabling there too if it comes up.
|
||||
|
||||
### General keymaps
|
||||
|
||||
@@ -52,6 +73,8 @@ Package names vary by distro (see the script for the exact list per package mana
|
||||
| `<leader>p` | Normal | Force inline paste (paste as characters at cursor, ignoring line-wise register type) |
|
||||
| `p` / `P` | Visual | Paste over selection without clobbering the unnamed register |
|
||||
| `J` / `K` | Visual | Move selected lines down / up |
|
||||
| `<A-j>` / `<A-k>` | Normal/Insert/Visual | Move current line (or selection) down / up |
|
||||
| `<leader>cb` | Normal | Clear the current line's content, leaving it blank in place (doesn't delete the line itself) |
|
||||
| `<C-s>` | Normal/Visual/Insert | Save file |
|
||||
| `<C-h/j/k/l>` | Normal | Move to left/lower/upper/right window |
|
||||
| `<leader>sv` / `<leader>sh` | Normal | Split vertically / horizontally |
|
||||
@@ -65,7 +88,7 @@ Package names vary by distro (see the script for the exact list per package mana
|
||||
- **Statusline**: `lualine`, themed to match, shows mode, git branch, diagnostics, filename, encoding/filetype, progress, and cursor location.
|
||||
- **Indent guides**: `indent-blankline` — colored guide per indent level, plus the current lexical scope (the block your cursor is inside) is highlighted with its own guide color. The underline that used to mark the scope's start/end line is disabled (`show_start`/`show_end = false`) — just the colored guide remains.
|
||||
- **Inline color previews**: `nvim-colorizer` shows hex/rgb color values with their actual color as a background.
|
||||
- **Notifications**: `nvim-notify` replaces the default notification popups with floating, styled ones.
|
||||
- **Notifications**: `nvim-notify` replaces the default notification popups with floating, styled ones, positioned bottom-right.
|
||||
- **Prompts**: `dressing.nvim` upgrades the rename prompt, breakpoint-condition prompt, and DAP path prompts to floating dialogs instead of plain command-line input.
|
||||
|
||||
## Buffers & tabs (`bufferline`)
|
||||
@@ -76,7 +99,7 @@ Each buffer tab shows its ordinal position number. Pinned buffers are always kep
|
||||
|---|---|
|
||||
| `<S-h>` / `<S-l>` | Previous / next buffer (follows the order shown on screen, including any reordering) |
|
||||
| `<A-1>` … `<A-9>` / `<F1>`–`<F9>` | Jump directly to the buffer at that position. `<F5>` and `<F10>` each pull double duty with the debugger (see [Debugging](#debugging-nvim-dap)) — they act as buffer jumps at rest, and hand themselves over to DAP for the duration of an active debug session. |
|
||||
| `<A-0>` / `<F10>` | Jump to the last buffer. |
|
||||
| `<A-0>` / `<F10>` | Jump to the last buffer |
|
||||
| `<A-,>` / `<A-.>` | Move current buffer left / right (blocked from crossing into the pinned block — wraps to the other end instead) |
|
||||
| `<leader>bp` | Toggle pin on current buffer |
|
||||
| `<leader>bx` | Close every **unpinned** buffer with **no unsaved changes** (pinned buffers and anything modified are left alone) |
|
||||
@@ -84,7 +107,7 @@ Each buffer tab shows its ordinal position number. Pinned buffers are always kep
|
||||
|
||||
Setting an explicit `<F1>` mapping here also overrides Neovim's built-in `<F1>`-opens-help default — any explicit keymap for a key always takes precedence over Neovim's default for it.
|
||||
|
||||
## File & text search (`telescope`)
|
||||
## Text search (`Telescope`)
|
||||
|
||||
| Key | Action |
|
||||
|---|---|
|
||||
@@ -93,7 +116,18 @@ Setting an explicit `<F1>` mapping here also overrides Neovim's built-in `<F1>`-
|
||||
| `<leader>fb` | List open buffers |
|
||||
| `<leader>fh` | Search help tags |
|
||||
| `<leader>fr` | Recent files |
|
||||
| `<leader>e` | Toggle the file explorer sidebar (`nvim-tree`, right side) |
|
||||
|
||||
## File explorer (`nvim-tree`)
|
||||
|
||||
`<leader>e` toggles the file explorer sidebar (right side). On top of nvim-tree's own defaults (`c`/`x`/`p` to copy/cut/paste, `m` to mark, `d` to delete, etc.), three custom commands:
|
||||
|
||||
| Key | Action |
|
||||
|---|---|
|
||||
| `gP` | Paste, resolving every naming **collision** in that paste with one `pattern/replacement` (Vim regex — same as `:s///`) instead of nvim-tree's normal one-at-a-time overwrite/rename prompt per conflicting file. Plain `p` is untouched. Only confirmed reliable for a **single** conflicting file at a time — see [Known quirks](#known-quirks). |
|
||||
| `gM` | Copy every **marked** file/folder (mark with `m`, shown as a star) into the directory under the cursor, applying that same `pattern/replacement` regex to **every** name unconditionally — not just on collision. Doesn't touch nvim-tree's clipboard at all; reads the mark list directly and shells out to `cp -r` to do the copying itself. Marks aren't auto-cleared afterward — toggle them off individually with `m` when done. |
|
||||
| `gC` | Clear the copy/cut clipboard outright. Useful if it's holding a stale entry (a file since renamed, moved, or deleted), which otherwise pastes as `ENOENT: no such file or directory` until cleared and re-copied fresh. |
|
||||
|
||||
`gP` and `gM` both fail safely rather than silently: a stale mark (pointing at a since-deleted path) is skipped and cleaned up automatically instead of attempted, and a rename that would produce a no-op copy-onto-itself is skipped with a clear reason instead of surfacing a raw `cp` error.
|
||||
|
||||
## LSP & code intelligence
|
||||
|
||||
@@ -105,11 +139,11 @@ Configured servers: **clangd** (C/C++), **gopls** (Go), **omnisharp** (C#), **ts
|
||||
| `gD` | Go to declaration. Same `#include`-awareness and fallback as `gd`. |
|
||||
| `gr` | Find all references, in a fuzzy picker with preview. |
|
||||
| `K` | Hover documentation (renders Doxygen comments if present). |
|
||||
| `<leader>lr` | Rename symbol (prompts for new name, safe against double-firing). |
|
||||
| `<leader>la` | Code actions. |
|
||||
| `<leader>lf` | Format file (via clangd/LSP formatting — see [Formatting](#formatting) for the style used). |
|
||||
| `<leader>li` | Show LSP client info. |
|
||||
| `<leader>cd` | Generate a Doxygen-style comment block (`@brief`/`@param`/`@return`) above the function under the cursor — see [Documentation generation](#documentation-generation). |
|
||||
| `<leader>lr` | Rename symbol (prompts for new name, safe against double-firing) |
|
||||
| `<leader>la` | Code actions |
|
||||
| `<leader>lf` | Format file (via clangd/LSP formatting — see [Formatting and linting](#formatting-and-linting) for the style used) |
|
||||
| `<leader>li` | Show LSP client info |
|
||||
| `<leader>cd` | Generate a Doxygen-style comment block — see [Documentation generation](#documentation-generation) |
|
||||
|
||||
## Autocompletion & snippets
|
||||
|
||||
@@ -161,11 +195,23 @@ Neovim's embedded terminal launches **fish** instead of your login shell, purely
|
||||
|
||||
`gitsigns` shows added/changed/removed lines in the sign column against the current git state.
|
||||
|
||||
## Formatting
|
||||
## Hex viewer
|
||||
|
||||
`~/.clang-format` is written on every run (LLVM-based, `BreakBeforeBraces: Attach` for K&R-style braces, 4-wide real tabs via `UseTab: Always`/`TabWidth: 4` to match the editor, 100-column limit). `clang-format` walks upward from the file being formatted looking for a `.clang-format`; since `$HOME` sits above every project, this acts as a personal default for any project that doesn't ship its own `.clang-format` — a project's own file always takes precedence.
|
||||
`<leader>h` toggles the current buffer between normal and hex-dump view (backed by `xxd`), rather than showing both simultaneously. That's deliberate: the hex dump is just ordinary buffer text under the hood, so editing it gets normal Neovim undo/redo for free, and nothing writes to disk until an explicit `:w` — same as any other file. A plugin doing a true live simultaneous hex+ASCII view was tried first, but it manages bytes with its own logic outside normal buffer editing, which is exactly why it had no undo at all.
|
||||
|
||||
The mapping also makes sure the buffer is actually loaded in binary mode before toggling (re-reading it with `++bin` if not) — opening a real binary file without that causes Neovim to misinterpret raw bytes as text before `xxd` even runs, surfacing as a `CONVERSION ERROR` instead of a clean hex dump.
|
||||
|
||||
## Formatting and linting
|
||||
|
||||
`~/.clang-format` and `~/.clang-tidy` are both written on every run, implementing a specific C/C++ coding style guide (naming conventions, Allman braces, real tabs, include ordering, and a curated set of modernize/cppcoreguidelines/bugprone clang-tidy checks — see the comments in each file for exactly which style guide section a given setting maps to). Both tools walk upward from the file being checked looking for their config file; since `$HOME` sits above every project, these act as your personal default for any project that doesn't ship its own `.clang-format`/`.clang-tidy` — a project's own file always takes precedence.
|
||||
|
||||
`<leader>lf` (LSP format) only consumes `.clang-format` — clangd's formatting is pure clang-format and has nothing to do with clang-tidy. `.clang-tidy` is picked up separately and automatically by clangd for live diagnostics, since clangd's clang-tidy integration is on by default.
|
||||
|
||||
## Known quirks
|
||||
|
||||
- **`nvim-treesitter` is pinned to its `master` branch**, not the current upstream default (`main`). `main` is an incompatible rewrite that removed the `nvim-treesitter.configs` API this config (and most existing configs/plugins) are built on. `master` is kept frozen upstream specifically for this kind of backward compatibility.
|
||||
- A **Neovim 0.12 compatibility shim** is included for `master`-branch treesitter: 0.12 changed query predicate/directive results to sometimes be a list of nodes instead of a single node, which `master`'s legacy predicate handlers don't expect — this caused a `"Decoration provider ... attempt to call method 'range'"` error (most visible on markdown files). The shim normalizes results back to a single node before those handlers run. Purely cosmetic when unpatched (highlighting still worked) but noisy.
|
||||
- **`nvim-cmp` absorbs the `<CR>` mapping used for smart comment continuation** as its own fallback, rather than it being called directly by Neovim. `cmp.setup()` runs after `init.lua`'s top-level code, and per its own keymap-composition system, it wraps whatever `<CR>` mapping already existed as the function it calls when its completion menu isn't visible, instead of simply discarding it. Worth knowing if you ever add or change an insert-mode `<CR>` mapping here: it will run through cmp's fallback chain rather than being invoked directly, which also means direct buffer edits from inside it (e.g. `nvim_set_current_line()`) fail with `E565` — express any change as keys to return instead.
|
||||
- **`gP`'s regex-on-paste only handles single-file conflicts reliably.** nvim-tree has a separate, differently-shaped dialog specifically for multi-file conflicts within one paste ("N file(s) already exist" / Rename (suffix) / Overwrite all / Skip all), which `gP` doesn't detect. `gM` (copying marked files with an unconditional regex) was built as the more reliable tool for renaming several files at once.
|
||||
- **`gM`'s stale-mark cleanup depends on `api.marks.toggle`**, a function name inferred from `m`'s own behavior rather than confirmed in nvim-tree's documentation directly, so it's wrapped defensively — if it's wrong on a given nvim-tree version, a stale mark just won't auto-clear (still requires manually pressing `m` on it), without otherwise breaking `gM`.
|
||||
- **Smart comment continuation (`<CR>`) only recognizes `//`, `#`, and `--`** (C-family/JS/TS/Go, Python/bash/YAML/CMake, and Lua/SQL respectively) rather than being fully comment-syntax-agnostic — it computes the marker to repeat directly rather than deferring to Neovim's own `'comments'`-option-driven logic, which would cover more comment styles but came with its own timing problems (see the `<CR>`/cmp entry above).
|
||||
Reference in new issue
Block a user