<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikibase.ronzz.org/index.php?action=history&amp;feed=atom&amp;title=Cheatsheet%3ANeovim</id>
	<title>Cheatsheet:Neovim - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikibase.ronzz.org/index.php?action=history&amp;feed=atom&amp;title=Cheatsheet%3ANeovim"/>
	<link rel="alternate" type="text/html" href="https://wikibase.ronzz.org/index.php?title=Cheatsheet:Neovim&amp;action=history"/>
	<updated>2026-11-24T03:57:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wikibase.ronzz.org/index.php?title=Cheatsheet:Neovim&amp;diff=10274&amp;oldid=prev</id>
		<title>RonzzWikiCowriterAI: new cheatsheet: Neovim (AI-assisted (RonzzWikiCowriter)) (via create-page on MediaWiki MCP Server)</title>
		<link rel="alternate" type="text/html" href="https://wikibase.ronzz.org/index.php?title=Cheatsheet:Neovim&amp;diff=10274&amp;oldid=prev"/>
		<updated>2026-10-17T18:45:31Z</updated>

		<summary type="html">&lt;p&gt;new cheatsheet: Neovim (AI-assisted (RonzzWikiCowriter)) (via create-page on MediaWiki MCP Server)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cheatsheet}}&lt;br /&gt;
&lt;br /&gt;
[[FOSS:Neovim|Neovim]] is a hyperextensible text editor that keeps Vim&amp;#039;s modal editing and Vimscript, and adds a Lua configuration API, a built-in LSP client, and treesitter.&lt;br /&gt;
&lt;br /&gt;
New to modal editing? &amp;lt;code&amp;gt;:Tutor&amp;lt;/code&amp;gt; is an interactive lesson that takes about half an hour.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Examples below assume Neovim 0.11 or newer. To find your config directory, run &amp;lt;code&amp;gt;:echo stdpath(&amp;quot;config&amp;quot;)&amp;lt;/code&amp;gt;: it is usually &amp;lt;code&amp;gt;~/.config/nvim&amp;lt;/code&amp;gt; on Linux and macOS, and &amp;lt;code&amp;gt;~/AppData/Local/nvim&amp;lt;/code&amp;gt; on Windows.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic example: init.lua ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
~/.config/nvim&lt;br /&gt;
├── init.lua&lt;br /&gt;
└── lua&lt;br /&gt;
    ├── config&lt;br /&gt;
    │   └── lazy.lua&lt;br /&gt;
    └── plugins&lt;br /&gt;
        └── comment.lua&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;2&amp;quot; copy&amp;gt;&lt;br /&gt;
-- ~/.config/nvim/init.lua&lt;br /&gt;
vim.g.mapleader = &amp;quot; &amp;quot;             -- &amp;lt;leader&amp;gt;; must be set before plugins load&lt;br /&gt;
vim.g.maplocalleader = &amp;quot;\\&amp;quot;&lt;br /&gt;
&lt;br /&gt;
vim.opt.number = true             -- absolute line numbers&lt;br /&gt;
vim.opt.relativenumber = true     -- distances from the cursor line&lt;br /&gt;
vim.opt.expandtab = true          -- Tab inserts spaces&lt;br /&gt;
vim.opt.shiftwidth = 2            -- one indent step&lt;br /&gt;
vim.opt.ignorecase = true         -- search is case-insensitive ...&lt;br /&gt;
vim.opt.smartcase = true          -- ... unless the pattern has capitals&lt;br /&gt;
vim.opt.scrolloff = 4             -- keep 4 lines above and below the cursor&lt;br /&gt;
&lt;br /&gt;
vim.keymap.set(&amp;quot;n&amp;quot;, &amp;quot;&amp;lt;leader&amp;gt;w&amp;quot;, &amp;quot;&amp;lt;cmd&amp;gt;w&amp;lt;cr&amp;gt;&amp;quot;, { desc = &amp;quot;Save file&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
require(&amp;quot;config.lazy&amp;quot;)            -- plugin manager, see #Plugins&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A config does four things: set options, map keys, define autocommands, and load plugins.&lt;br /&gt;
&lt;br /&gt;
== Modes ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Mode !! Enter with !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| Normal || &amp;lt;code&amp;gt;Esc&amp;lt;/code&amp;gt; || move around, run operators and commands&lt;br /&gt;
|-&lt;br /&gt;
| Insert || &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;I&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;A&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;o&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;O&amp;lt;/code&amp;gt; || type at the cursor, after it, at line start, at line end, in a new line below, in a new line above&lt;br /&gt;
|-&lt;br /&gt;
| Visual || &amp;lt;code&amp;gt;v&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;V&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;Ctrl-v&amp;lt;/code&amp;gt; || select by character, by line, by block&lt;br /&gt;
|-&lt;br /&gt;
| Replace || &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; || overwrite characters&lt;br /&gt;
|-&lt;br /&gt;
| Command-line || &amp;lt;code&amp;gt;:&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;?&amp;lt;/code&amp;gt; || Ex commands, search&lt;br /&gt;
|-&lt;br /&gt;
| Terminal || &amp;lt;code&amp;gt;:terminal&amp;lt;/code&amp;gt; || run a shell; &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; to type, &amp;lt;code&amp;gt;Ctrl-\ Ctrl-n&amp;lt;/code&amp;gt; back to Normal&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Operators, motions, text objects ==&lt;br /&gt;
&lt;br /&gt;
A Normal-mode command reads as &amp;lt;code&amp;gt;[count] operator motion&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;d2w&amp;lt;/code&amp;gt; deletes two words. A text object replaces the motion when prefixed with &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; (inner) or &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; (around).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Operator !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;d&amp;lt;/code&amp;gt; || delete (cut)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; || change: delete, then Insert mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; || yank (copy)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;P&amp;lt;/code&amp;gt; || paste after / before&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt; || indent / dedent&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gu&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;gU&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;g~&amp;lt;/code&amp;gt; || lowercase, uppercase, toggle case&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gq&amp;lt;/code&amp;gt; || format: rewrap text, or format through the LSP client&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; || reindent&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Motion !! Moves&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;w&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;e&amp;lt;/code&amp;gt; || word forward, back, to its end (&amp;lt;code&amp;gt;W&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;B&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;E&amp;lt;/code&amp;gt;: whitespace-delimited)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;$&amp;lt;/code&amp;gt; || column 0, first non-blank, end of line&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gg&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt; || first line, last line (&amp;lt;code&amp;gt;42G&amp;lt;/code&amp;gt;: line 42)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;f{c}&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;t{c}&amp;lt;/code&amp;gt; || to / until the next &amp;lt;code&amp;gt;{c}&amp;lt;/code&amp;gt; on the line; &amp;lt;code&amp;gt;F&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt; backward, &amp;lt;code&amp;gt;;&amp;lt;/code&amp;gt; repeats&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;%&amp;lt;/code&amp;gt; || the matching bracket&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;{ }&amp;lt;/code&amp;gt; || previous / next paragraph&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; || next / previous search match&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Text object !! Selects&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;iw&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;aw&amp;lt;/code&amp;gt; || a word / a word and its whitespace&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;i&amp;quot;&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;a&amp;quot;&amp;lt;/code&amp;gt; || inside / around quotes (&amp;lt;code&amp;gt;&amp;#039;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;`&amp;lt;/code&amp;gt; too)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;i(&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;a(&amp;lt;/code&amp;gt; || inside / around parentheses (&amp;lt;code&amp;gt;ib&amp;lt;/code&amp;gt;; also &amp;lt;code&amp;gt;[&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;{&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;it&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt; || inside / around an HTML or XML tag&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;ap&amp;lt;/code&amp;gt; || inside / around a paragraph&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
ciw     change the word under the cursor&lt;br /&gt;
di&amp;quot;     delete everything inside the double quotes&lt;br /&gt;
da(     delete the parentheses and their contents&lt;br /&gt;
yap     copy the paragraph&lt;br /&gt;
&amp;gt;i{     indent the inside of the braces&lt;br /&gt;
gUiw    uppercase the word&lt;br /&gt;
dG      delete to the end of the file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Everyday edits ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
u          undo;  Ctrl-r redo&lt;br /&gt;
.          repeat the last change&lt;br /&gt;
x          delete the character under the cursor&lt;br /&gt;
J          join the line below onto this one&lt;br /&gt;
yyp        duplicate the current line&lt;br /&gt;
gg=G       reindent the whole file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Registers and macros&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
&amp;quot;+y        yank to the system clipboard&lt;br /&gt;
&amp;quot;ayy       yank the line into register a&lt;br /&gt;
&amp;quot;ap        paste register a&lt;br /&gt;
qa         start recording a macro into register a&lt;br /&gt;
q          stop recording&lt;br /&gt;
@a         run macro a;  @@ repeats it;  3@a runs it three times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Search and replace&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
/pattern         search forward;  n and N jump to the next and previous match&lt;br /&gt;
?pattern         search backward&lt;br /&gt;
*                search the word under the cursor&lt;br /&gt;
:nohlsearch      clear the highlight until the next search&lt;br /&gt;
:s/old/new/      replace on the current line&lt;br /&gt;
:%s/old/new/g    replace in the whole file&lt;br /&gt;
:%s/old/new/gc   ... asking for confirmation each time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
In Visual mode press &amp;lt;code&amp;gt;:&amp;lt;/code&amp;gt; to get the range for free: select lines, then &amp;lt;code&amp;gt;:&amp;#039;&amp;amp;lt;,&amp;#039;&amp;amp;gt;s/old/new/g&amp;lt;/code&amp;gt; replaces inside the selection only.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Files, buffers, windows, tabs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
:e file         edit a file&lt;br /&gt;
:w / :wq        write / write and quit&lt;br /&gt;
:q / :q!        quit / quit and discard changes&lt;br /&gt;
:x              write if changed, then quit&lt;br /&gt;
:e!             reload the file, discarding changes&lt;br /&gt;
:bn / :bp       next / previous buffer&lt;br /&gt;
:bd             close the buffer&lt;br /&gt;
:ls             list open buffers&lt;br /&gt;
:sp file        split the window horizontally&lt;br /&gt;
:vs file        split the window vertically&lt;br /&gt;
Ctrl-w h/j/k/l  move to the window left, below, above, right&lt;br /&gt;
Ctrl-w q        close the window&lt;br /&gt;
:tabnew / gt    new tab / next tab (gT: previous)&lt;br /&gt;
:terminal       terminal in a buffer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A buffer is not a window.&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;:q&amp;lt;/code&amp;gt; closes a window and leaves the buffer loaded in memory; &amp;lt;code&amp;gt;:bd&amp;lt;/code&amp;gt; unloads the buffer. &amp;lt;code&amp;gt;Ctrl-o&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Ctrl-i&amp;lt;/code&amp;gt; walk the jump list backwards and forwards.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuring in Lua ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Options&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Form !! Reaches&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vim.opt.number = true&amp;lt;/code&amp;gt; || any option, converting Lua values to Vim types&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vim.o&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;vim.bo&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;vim.wo&amp;lt;/code&amp;gt; || global, buffer-local, window-local raw access&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vim.g.mapleader = &amp;quot; &amp;quot;&amp;lt;/code&amp;gt; || a global variable, here &amp;lt;code&amp;gt;g:mapleader&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vim.opt.listchars:append({ space = &amp;quot;·&amp;quot; })&amp;lt;/code&amp;gt; || add one entry to a comma-separated option&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
vim.opt.colorcolumn = &amp;quot;80&amp;quot;&lt;br /&gt;
vim.opt.wrap = false&lt;br /&gt;
vim.o.scrolloff = 4                       -- same as :set scrolloff=4&lt;br /&gt;
vim.wo.number = true                      -- window-local&lt;br /&gt;
vim.bo.commentstring = &amp;quot;// %s&amp;quot;            -- buffer-local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Keymaps&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
vim.keymap.set(&amp;quot;n&amp;quot;, &amp;quot;&amp;lt;leader&amp;gt;w&amp;quot;, &amp;quot;&amp;lt;cmd&amp;gt;w&amp;lt;cr&amp;gt;&amp;quot;, { desc = &amp;quot;Save file&amp;quot; })&lt;br /&gt;
vim.keymap.set({ &amp;quot;n&amp;quot;, &amp;quot;v&amp;quot; }, &amp;quot;&amp;lt;leader&amp;gt;y&amp;quot;, &amp;#039;&amp;quot;+y&amp;#039;, { desc = &amp;quot;Yank to clipboard&amp;quot; })&lt;br /&gt;
vim.keymap.set(&amp;quot;i&amp;quot;, &amp;quot;jk&amp;quot;, &amp;quot;&amp;lt;Esc&amp;gt;&amp;quot;, { desc = &amp;quot;Leave insert mode&amp;quot; })&lt;br /&gt;
vim.keymap.set(&amp;quot;n&amp;quot;, &amp;quot;]d&amp;quot;, function() vim.diagnostic.jump({ count = 1 }) end,&lt;br /&gt;
  { desc = &amp;quot;Next diagnostic&amp;quot; })&lt;br /&gt;
vim.keymap.set(&amp;quot;n&amp;quot;, &amp;quot;&amp;lt;leader&amp;gt;f&amp;quot;, vim.lsp.buf.format, { desc = &amp;quot;Format buffer&amp;quot; })&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Modes are &amp;lt;code&amp;gt;&amp;quot;n&amp;quot;&amp;lt;/code&amp;gt; normal, &amp;lt;code&amp;gt;&amp;quot;i&amp;quot;&amp;lt;/code&amp;gt; insert, &amp;lt;code&amp;gt;&amp;quot;v&amp;quot;&amp;lt;/code&amp;gt; visual and select, &amp;lt;code&amp;gt;&amp;quot;x&amp;quot;&amp;lt;/code&amp;gt; visual only, &amp;lt;code&amp;gt;&amp;quot;t&amp;quot;&amp;lt;/code&amp;gt; terminal, &amp;lt;code&amp;gt;&amp;quot;&amp;quot;&amp;lt;/code&amp;gt; all of them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;vim.keymap.set&amp;lt;/code&amp;gt; differs from Vim&amp;#039;s &amp;lt;code&amp;gt;:map&amp;lt;/code&amp;gt; in two ways:&amp;#039;&amp;#039;&amp;#039; the mapping is silent by default, and &amp;lt;code&amp;gt;{ remap = true }&amp;lt;/code&amp;gt; is needed for the right-hand side to expand other mappings. Prefer &amp;lt;code&amp;gt;&amp;amp;lt;cmd&amp;amp;gt;...&amp;amp;lt;cr&amp;amp;gt;&amp;lt;/code&amp;gt; over &amp;lt;code&amp;gt;:...&amp;amp;lt;cr&amp;amp;gt;&amp;lt;/code&amp;gt;: it does not switch modes and keeps the cursor put.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Autocommands and user commands&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
vim.api.nvim_create_autocmd(&amp;quot;BufWritePre&amp;quot;, {&lt;br /&gt;
  group = vim.api.nvim_create_augroup(&amp;quot;trim_whitespace&amp;quot;, { clear = true }),&lt;br /&gt;
  pattern = &amp;quot;*&amp;quot;,&lt;br /&gt;
  desc = &amp;quot;Strip trailing whitespace on save&amp;quot;,&lt;br /&gt;
  callback = function()&lt;br /&gt;
    local view = vim.fn.winsaveview()&lt;br /&gt;
    vim.cmd([[%s/\s\+$//e]])&lt;br /&gt;
    vim.fn.winrestview(view)              -- put the cursor back&lt;br /&gt;
  end,&lt;br /&gt;
})&lt;br /&gt;
&lt;br /&gt;
vim.api.nvim_create_user_command(&amp;quot;Reload&amp;quot;, function()&lt;br /&gt;
  vim.cmd.source(vim.fn.stdpath(&amp;quot;config&amp;quot;) .. &amp;quot;/init.lua&amp;quot;)&lt;br /&gt;
end, { desc = &amp;quot;Re-run init.lua&amp;quot; })&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plugins ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/folke/lazy.nvim lazy.nvim] installs plugins, lazy-loads them by event, command or keymap, and keeps a lockfile of installed revisions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
-- ~/.config/nvim/lua/config/lazy.lua&lt;br /&gt;
local lazypath = vim.fn.stdpath(&amp;quot;data&amp;quot;) .. &amp;quot;/lazy/lazy.nvim&amp;quot;&lt;br /&gt;
if not (vim.uv or vim.loop).fs_stat(lazypath) then&lt;br /&gt;
  vim.fn.system({ &amp;quot;git&amp;quot;, &amp;quot;clone&amp;quot;, &amp;quot;--filter=blob:none&amp;quot;, &amp;quot;--branch=stable&amp;quot;,&lt;br /&gt;
    &amp;quot;https://github.com/folke/lazy.nvim.git&amp;quot;, lazypath })&lt;br /&gt;
end&lt;br /&gt;
vim.opt.rtp:prepend(lazypath)&lt;br /&gt;
&lt;br /&gt;
require(&amp;quot;lazy&amp;quot;).setup({ { import = &amp;quot;plugins&amp;quot; } })   -- every file under lua/plugins/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One file per plugin, each returning a spec:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
-- ~/.config/nvim/lua/plugins/comment.lua&lt;br /&gt;
return {&lt;br /&gt;
  &amp;quot;numToStr/Comment.nvim&amp;quot;,&lt;br /&gt;
  event = &amp;quot;VeryLazy&amp;quot;,      -- load after startup&lt;br /&gt;
  opts = {},               -- runs require(&amp;quot;Comment&amp;quot;).setup({})&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Spec field !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;opts = {}&amp;lt;/code&amp;gt; || passed to the plugin&amp;#039;s &amp;lt;code&amp;gt;setup()&amp;lt;/code&amp;gt;; the module name is guessed from the repository name&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;config = function() ... end&amp;lt;/code&amp;gt; || full control over setup; use instead of &amp;lt;code&amp;gt;opts&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;cmd = &amp;quot;Mason&amp;quot;&amp;lt;/code&amp;gt; || load when the command is first run&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;keys = { ... }&amp;lt;/code&amp;gt; || load when one of these mappings is first pressed&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;event = &amp;quot;BufReadPre&amp;quot;&amp;lt;/code&amp;gt; || load on an autocommand event, or on &amp;lt;code&amp;gt;&amp;quot;VeryLazy&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ft = &amp;quot;python&amp;quot;&amp;lt;/code&amp;gt; || load for a filetype&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;dependencies = { ... }&amp;lt;/code&amp;gt; || plugins to load with it&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;enabled = false&amp;lt;/code&amp;gt; || keep the spec, install nothing&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;version&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;branch&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;tag&amp;lt;/code&amp;gt; || pin a revision&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:Lazy&amp;lt;/code&amp;gt; || the UI: status, install, update, clean, log&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:Lazy update&amp;lt;/code&amp;gt; || update every plugin&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:Lazy sync&amp;lt;/code&amp;gt; || update, install missing plugins, clean removed ones&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:Lazy restore&amp;lt;/code&amp;gt; || go back to the revisions recorded in the lockfile&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:Lazy profile&amp;lt;/code&amp;gt; || startup time per plugin&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;:checkhealth lazy&amp;lt;/code&amp;gt; || diagnose the setup&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;lazy-lock.json&amp;lt;/code&amp;gt; records the installed revision of every plugin: commit it to make your setup reproducible. Plugins land in &amp;lt;code&amp;gt;stdpath(&amp;quot;data&amp;quot;)/lazy&amp;lt;/code&amp;gt;, which is why the bootstrap builds the path with &amp;lt;code&amp;gt;vim.fn.stdpath(&amp;quot;data&amp;quot;)&amp;lt;/code&amp;gt; instead of typing &amp;lt;code&amp;gt;~/.local/share/nvim&amp;lt;/code&amp;gt;: the tilde is shell shorthand, not something Lua expands.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With that spec installed, Comment.nvim toggles comments:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Key !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gcc&amp;lt;/code&amp;gt; || toggle the current line&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gc{motion}&amp;lt;/code&amp;gt; || toggle a motion: &amp;lt;code&amp;gt;gcap&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gcw&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gc5j&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gci{&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gc&amp;lt;/code&amp;gt; (Visual) || toggle the selection&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gco&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;gcO&amp;lt;/code&amp;gt; || add a comment below / above and enter Insert mode&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gcA&amp;lt;/code&amp;gt; || add a comment at the end of the line&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gbc&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;gb{motion}&amp;lt;/code&amp;gt; || the same with block comments&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Built-in LSP ==&lt;br /&gt;
&lt;br /&gt;
Neovim ships the LSP client; the servers themselves (&amp;lt;code&amp;gt;lua-language-server&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyright&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;clangd&amp;lt;/code&amp;gt;, ...) are installed separately and must be on &amp;lt;code&amp;gt;$PATH&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; copy&amp;gt;&lt;br /&gt;
-- ~/.config/nvim/lua/config/lsp.lua&lt;br /&gt;
vim.lsp.config(&amp;quot;luals&amp;quot;, {&lt;br /&gt;
  cmd = { &amp;quot;lua-language-server&amp;quot; },&lt;br /&gt;
  filetypes = { &amp;quot;lua&amp;quot; },&lt;br /&gt;
  root_markers = { &amp;quot;.luarc.json&amp;quot;, &amp;quot;.luarc.jsonc&amp;quot;, &amp;quot;.git&amp;quot; },&lt;br /&gt;
})&lt;br /&gt;
vim.lsp.enable(&amp;quot;luals&amp;quot;)            -- start it for matching buffers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Key !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;K&amp;lt;/code&amp;gt; || hover for the symbol under the cursor&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;grn&amp;lt;/code&amp;gt; || rename the symbol&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gra&amp;lt;/code&amp;gt; || code action (Normal and Visual)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;grr&amp;lt;/code&amp;gt; || references&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gri&amp;lt;/code&amp;gt; || implementations&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gO&amp;lt;/code&amp;gt; || document symbols&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Ctrl-s&amp;lt;/code&amp;gt; (Insert) || signature help&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Ctrl-x Ctrl-o&amp;lt;/code&amp;gt; (Insert) || LSP completion&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
:checkhealth vim.lsp          is a client attached to this buffer?&lt;br /&gt;
:lua =vim.lsp.get_clients()   list the active clients&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;These mappings are bound even when no server is attached:&amp;#039;&amp;#039;&amp;#039; pressing &amp;lt;code&amp;gt;grn&amp;lt;/code&amp;gt; in a buffer without a client reports that no matching language server was found. Diagnostics, on the other hand, have no default keys; bind &amp;lt;code&amp;gt;vim.diagnostic.open_float&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;vim.diagnostic.jump&amp;lt;/code&amp;gt; yourself, as in [[#Configuring in Lua|Configuring in Lua]].&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Built-in commands worth knowing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot; copy&amp;gt;&lt;br /&gt;
:Tutor                  interactive Vim lesson&lt;br /&gt;
:help topic             e.g. :help lua-guide, :help vim.keymap.set&lt;br /&gt;
:checkhealth            diagnose config, plugins, LSP, treesitter&lt;br /&gt;
:Inspect                highlight group and treesitter node under the cursor&lt;br /&gt;
:source $MYVIMRC        re-run init.lua&lt;br /&gt;
:luafile %              run the Lua file in the current buffer&lt;br /&gt;
:lua =vim.o.shiftwidth  print a value&lt;br /&gt;
:set shiftwidth?        print an option&lt;br /&gt;
:verbose set shiftwidth?    ... and which file set it&lt;br /&gt;
:messages               read past messages&lt;br /&gt;
:scriptnames            files loaded at startup&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== For more ==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;:help&amp;lt;/code&amp;gt;: the authoritative manual, available offline&lt;br /&gt;
* [https://neovim.io/doc/user/ Neovim user manual]: the same text online&lt;br /&gt;
* [https://neovim.io/doc/user/lua-guide.html Lua guide]: porting a vimrc to init.lua&lt;br /&gt;
* [https://neovim.io/doc/user/lsp.html LSP documentation]: configs, attach handlers, diagnostics&lt;br /&gt;
* [https://github.com/nvim-lua/kickstart.nvim kickstart.nvim]: a small, commented starting config to read&lt;br /&gt;
* [https://lazy.folke.io/ lazy.nvim documentation]: specs, lazy-loading, debugging&lt;br /&gt;
* [https://github.com/numToStr/Comment.nvim Comment.nvim]: the comment plugin used above&lt;/div&gt;</summary>
		<author><name>RonzzWikiCowriterAI</name></author>
	</entry>
</feed>