<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>NvimonDocs</title><link>https://hiraethecho.github.io/docs/tags/nvim/</link><description>Recent contentinNvimonDocs</description><generator>Hugo --0.152.2</generator><language>en</language><managingEditor>wyz2016zxc@outlook.com(Hiraeth)</managingEditor><webMaster>wyz2016zxc@outlook.com(Hiraeth)</webMaster><lastBuildDate>Mon, 16 Mar 2026 15:39:39 +0800</lastBuildDate><atom:link href="https://hiraethecho.github.io/docs/tags/nvim/index.xml" rel="self" type="application/rss+xml"/><item><title>一些nvim的配置和使用技巧</title><link>https://hiraethecho.github.io/docs/software/nvim-trick/</link><pubDate>Wed, 06 Aug 2025 00:00:00 +0000</pubDate><author>wyz2016zxc@outlook.com(Hiraeth)</author><guid>https://hiraethecho.github.io/docs/software/nvim-trick/</guid><description>&lt;h1 id="一些nvim的配置和使用技巧"&gt;
&lt;a class="anchor inpage" href="#%e4%b8%80%e4%ba%9bnvim%e7%9a%84%e9%85%8d%e7%bd%ae%e5%92%8c%e4%bd%bf%e7%94%a8%e6%8a%80%e5%b7%a7"&gt;#&lt;/a&gt;一些nvim的配置和使用技巧&lt;/h1&gt;
&lt;h2 id="cmd"&gt;
&lt;a class="anchor inpage" href="#cmd"&gt;##&lt;/a&gt;cmd&lt;/h2&gt;
&lt;p&gt;Lua 输出：&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;nvim&lt;/summary&gt;&lt;pre
class="codeblock"
&gt;&lt;code class="language-nvim" data-lang="nvim"&gt;:lua =vim.opt.runtimepath:get()&lt;/code&gt;&lt;button onclick="copyCode(this)" class="copybtn"&gt;copy&lt;/button&gt;&lt;/pre&gt;&lt;/details&gt;
&lt;script&gt;
function copyCode(btn) {
const code = btn.previousElementSibling.textContent.trim();
navigator.clipboard.writeText(code).then(() =&gt; {
btn.innerText = "copied";
setTimeout(() =&gt; (btn.innerText = "copy"), 2000);
});
}
&lt;/script&gt;&lt;p&gt;&lt;code&gt;:setl ma! ma?&lt;/code&gt; 可以切换一个buffer的只读状态。
注意其他编辑器的只读一般是“你可以修改但不能保存“，这个是你根本不能修改，比如说根本就不能进入插入模式。
可以设一个顺手的keymap，比如说我是nnoremap &lt;silent&gt; ;m :setl ma! ma?&lt;cr&gt; 。&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="一些nvim的配置和使用技巧">
  <a class="anchor inpage" href="#%e4%b8%80%e4%ba%9bnvim%e7%9a%84%e9%85%8d%e7%bd%ae%e5%92%8c%e4%bd%bf%e7%94%a8%e6%8a%80%e5%b7%a7">#</a>一些nvim的配置和使用技巧</h1>
<h2 id="cmd">
  <a class="anchor inpage" href="#cmd">##</a>cmd</h2>
<p>Lua 输出：</p>
<details open>
    <summary>nvim</summary><pre
        class="codeblock"
      ><code class="language-nvim" data-lang="nvim">:lua =vim.opt.runtimepath:get()</code><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p><code>:setl ma! ma?</code> 可以切换一个buffer的只读状态。
注意其他编辑器的只读一般是“你可以修改但不能保存“，这个是你根本不能修改，比如说根本就不能进入插入模式。
可以设一个顺手的keymap，比如说我是nnoremap <silent> ;m :setl ma! ma?<cr> 。</p>
<p>另外，:setl xxx! xxx? 这个是一个常用切换option开关的模式，比如说:nnoremap <silent> <space>w<space> <CMD>setl wrap! wrap?<cr>设keymap来切换自动换行，并在状态栏显示当前实际状态。</p>
<details open>
    <summary>vimscript</summary><pre
        class="codeblock"
      ><code class="language-vimscript" data-lang="vimscript">xnoremap ,x &lt;ESC&gt;`.`gvp`P
abbrev ,f &lt;C-R&gt;=expand(&#34;%:&#34;)&lt;left&gt;&lt;left&gt;
abbrev ,c &lt;C-R&gt;=getcwd()&lt;cr&gt;</code><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p>下面的keymap可以直接执行一行vimscript或者lua （取决于当前文件类型）。用来调整或者测试vim配置非常方便，改完一行就执行一下，不需要source整个vimrc文件了。</p>
<details open>
    <summary>vimscript</summary><pre
        class="codeblock"
      ><code class="language-vimscript" data-lang="vimscript">command! -range ExecVimL call execute(getline(&lt;line1&gt;, &lt;line2&gt;), &#39;&#39;)
command! -range ExecLua call execute(&#39;lua &#39; . join(getline(&lt;line1&gt;, &lt;line2&gt;), &#34; \n &#34;), &#39;&#39;)
nnoremap &lt;silent&gt; &lt;expr&gt; ,r ((&amp;ft==&#39;lua&#39; ? &#39;:ExecLua&#39; : &#39;:ExecVimL&#39;) . &#39;&lt;cr&gt;:&lt;c-u&gt;echo &#34;Current line executed&#34;&lt;cr&gt;&#39;)
xnoremap &lt;silent&gt; &lt;expr&gt; ,r ((&amp;ft==&#39;lua&#39; ? &#39;:ExecLua&#39; : &#39;:ExecVimL&#39;) . &#39;&lt;cr&gt;:&lt;c-u&gt;echo &#34;Selected range executed&#34;&lt;cr&gt;&#39;)</code><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p>链接：https://www.zhihu.com/question/636018229/answer/3386613023
著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。</p>
<p>用<code>.!</code>（当前行），<code>%!</code>（整个buff），<code>'&lt;,'&gt;!</code> (选中）可以把文本作为stdin传给一个外部shell命令，并用其stdout输出内容替换相应文本，用来调外部的格式化命令很方便。另外，如果传给bash或zsh的话就相当于把文本作为shell命令执行。</p>
<p>「修改 1」→「撤销」→「修改 2」，这时如果想退回到「修改 1」，按 <code>u</code> 是回不去的。</p>
<p>可以按 <code>g-</code>（反方向是 <code>g+</code>）</p>
<p>实际上等同于 <code>:earlier</code> 和 <code>:later</code> 。这两个命令后边是可以跟「次数」而不是「时间」的顺便一说，不写默认是 1 次。</p>
<p>test 2</p>
<h2 id="start-up-of-nvim">
  <a class="anchor inpage" href="#start-up-of-nvim">##</a>start up of nvim</h2>
<p>
</p>
<h2 id="lazynvim">
  <a class="anchor inpage" href="#lazynvim">##</a>lazy.nvim</h2>
<p>
 <code>lazy.nvim</code> 配置的表合并情况。例如假设<code>treesitter</code>的默认配置为</p>
<details open>
    <summary>lua</summary><pre
        class="chroma codeblock"
      ><code class="language-lua" data-lang="lua"
          ><span style="display:flex;"><span><span style="color:#66d9ef">return</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;nvim-treesitter/nvim-treesitter&#34;</span>,
</span></span><span style="display:flex;"><span>  opts <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>    ensure_installed <span style="color:#f92672">=</span> { <span style="color:#e6db74">&#34;lua&#34;</span>, <span style="color:#e6db74">&#34;vim&#34;</span> },
</span></span><span style="display:flex;"><span>    highlight <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>      enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>}</span></span></code
        ><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p>手动配置</p>
<details open>
    <summary>lua</summary><pre
        class="chroma codeblock"
      ><code class="language-lua" data-lang="lua"
          ><span style="display:flex;"><span><span style="color:#66d9ef">return</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;nvim-treesitter/nvim-treesitter&#34;</span>,
</span></span><span style="display:flex;"><span>  opts <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>    ensure_installed <span style="color:#f92672">=</span> { <span style="color:#e6db74">&#34;python&#34;</span> },
</span></span><span style="display:flex;"><span>    highlight <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>      enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    indent <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>      enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>}</span></span></code
        ><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p>那么最后会得到<code>ensure_installed = { &quot;python&quot; }</code>。如何要拓展表，则要用</p>
<details open>
    <summary>lua</summary><pre
        class="chroma codeblock"
      ><code class="language-lua" data-lang="lua"
          ><span style="display:flex;"><span>table.insert(opts.ensure_installed, <span style="color:#e6db74">&#34;python&#34;</span>)</span></span></code
        ><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script>]]></content:encoded></item><item><title>Write latex with neovim</title><link>https://hiraethecho.github.io/docs/software/vimtex/</link><pubDate>Sun, 27 Apr 2025 00:00:00 +0000</pubDate><author>wyz2016zxc@outlook.com(Hiraeth)</author><guid>https://hiraethecho.github.io/docs/software/vimtex/</guid><description>&lt;h1 id="write-latex-with-neovim"&gt;
&lt;a class="anchor inpage" href="#write-latex-with-neovim"&gt;#&lt;/a&gt;Write latex with neovim&lt;/h1&gt;
&lt;p&gt;\(\latex\)&lt;/p&gt;
&lt;h2 id="vimtex"&gt;
&lt;a class="anchor inpage" href="#vimtex"&gt;##&lt;/a&gt;vimtex&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;vimtex&lt;/code&gt;基本上是提供了全套的功能，包括&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;目录，标签等&lt;/li&gt;
&lt;li&gt;各种环境，&lt;code&gt;insert&lt;/code&gt;模式下的各种snippets，&lt;code&gt;normal&lt;/code&gt;模式下的文本对象和命令&lt;/li&gt;
&lt;li&gt;编译，报错&lt;/li&gt;
&lt;li&gt;正向搜索（从tex定位到pdf）和反向搜索（从pdf定位到tex）&lt;/li&gt;
&lt;li&gt;conceal （有点影响性能）&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;而且帮助文档非常详尽，维护积极，而且&lt;code&gt;vim&lt;/code&gt;上也能用&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="write-latex-with-neovim">
  <a class="anchor inpage" href="#write-latex-with-neovim">#</a>Write latex with neovim</h1>
<p>\(\latex\)</p>
<h2 id="vimtex">
  <a class="anchor inpage" href="#vimtex">##</a>vimtex</h2>
<p><code>vimtex</code>基本上是提供了全套的功能，包括</p>
<ul>
<li>目录，标签等</li>
<li>各种环境，<code>insert</code>模式下的各种snippets，<code>normal</code>模式下的文本对象和命令</li>
<li>编译，报错</li>
<li>正向搜索（从tex定位到pdf）和反向搜索（从pdf定位到tex）</li>
<li>conceal （有点影响性能）</li>
</ul>
<p>而且帮助文档非常详尽，维护积极，而且<code>vim</code>上也能用</p>
<p>缺点几乎没有，除了对与某些信奉unix哲学<em>做一件事并做到最好</em>的人（比如说我）来说有些臃肿。另一个是预设置的快捷键很多，但不一定符合所有人习惯（又是我）。</p>
<h2 id="latex">
  <a class="anchor inpage" href="#latex">##</a>latex</h2>
<p>首先需要一个<code>latex</code>发行版，比如<code>texlive</code>或者<code>miktex</code>。实际编译过程很复杂，为了生成目录和参考文献需要多次编译。但是<code>latexmk</code>可以帮助完成复杂的顺序。最重要的是，<code>latexmk</code>可以监听文本变化，自动重新编译，以此实现“实时”预览。</p>
<blockquote class="alert alert-tip">
      <p class="alert-heading">实际上不是实时。会在每次保存文件时编译，所以<code>insert</code>模式下敲字时并不会更新。另一方面还取决于编译速度。</p></blockquote><p>在<code>archlinux</code>上，可以安装整个<code>texlive</code>，如果觉得太臃肿也可以安装其中部分包，例如我只安装了</p>
<details open>
    <summary>TEXT</summary><pre
        class="codeblock"
      ><code class="language-" data-lang="">texlive-bibtexextra
texlive-binextra
texlive-langchinese
texlive-latexextra
texlive-mathscience
texlive-pstricks
texlive-xetex</code><button onclick="copyCode(this)" class="copybtn">copy</button></pre></details>

  <script>
    function copyCode(btn) {
      const code = btn.previousElementSibling.textContent.trim();
      navigator.clipboard.writeText(code).then(() => {
        btn.innerText = "copied";
        setTimeout(() => (btn.innerText = "copy"), 2000);
      });
    }
  </script><p>除此之外还有<code>tectonic</code>等可用，但是难以实现实时预览。</p>
<blockquote class="alert alert-note">
      <p class="alert-heading">可以用texpresso</p></blockquote><h2 id="lsp">
  <a class="anchor inpage" href="#lsp">##</a>lsp</h2>
<p><code>texlab</code></p>
<p><code>tex-fmt</code></p>
<h2 id="compile">
  <a class="anchor inpage" href="#compile">##</a>compile</h2>
<p>原则上可以直接用命令行编译。但是既然在<code>neovim</code>里，可以用插件封装的命令。</p>
<p>用<code>vimtex</code>或<code>texlab</code></p>
<h2 id="inverse-and-reverse-search">
  <a class="anchor inpage" href="#inverse-and-reverse-search">##</a>inverse and reverse search</h2>
<h2 id="snippets">
  <a class="anchor inpage" href="#snippets">##</a>snippets</h2>
<h3 id="mathzone">
  <a class="anchor inpage" href="#mathzone">###</a>mathzone</h3>
<p>为了在文本和数学公式环境中使用不同的片段，例如<code>CC</code>只在数学公式中自动展开为<code>\mathbb{C}</code>，需要对能检测数学环境。</p>
<p>最简单的方法是调用<code>vimtex</code>的功能。</p>
<p>用<code>python</code>检测。</p>
<p>用treesitter检测。</p>
<h3 id="engine">
  <a class="anchor inpage" href="#engine">###</a>engine</h3>
<p>UltiSnip</p>
<p>LuaSnip</p>
]]></content:encoded></item><item><title>My Neovim Config</title><link>https://hiraethecho.github.io/docs/software/nvim-config/</link><pubDate>Mon, 18 Nov 2024 00:00:00 +0000</pubDate><author>wyz2016zxc@outlook.com(Hiraeth)</author><guid>https://hiraethecho.github.io/docs/software/nvim-config/</guid><description>&lt;h1 id="my-neovim"&gt;
&lt;a class="anchor inpage" href="#my-neovim"&gt;#&lt;/a&gt;My neovim&lt;/h1&gt;
&lt;p&gt;My
on github.&lt;/p&gt;
&lt;p&gt;There is a
of my config, for fun.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m using nvim as a code editor, mainly for latex and markdown.&lt;/p&gt;
&lt;h2 id="usage"&gt;
&lt;a class="anchor inpage" href="#usage"&gt;##&lt;/a&gt;Usage&lt;/h2&gt;
&lt;h3 id="latex"&gt;
&lt;a class="anchor inpage" href="#latex"&gt;###&lt;/a&gt;latex&lt;/h3&gt;
&lt;p&gt;using vimtex to detect math environment, and texlab lsp to complie.&lt;/p&gt;
&lt;p&gt;&lt;del&gt;cmp&lt;/del&gt; blink.cmp and &lt;del&gt;ultisnips&lt;/del&gt; luasnip to enhance editing.&lt;/p&gt;
&lt;p&gt;check
.&lt;/p&gt;
&lt;h3 id="markdown"&gt;
&lt;a class="anchor inpage" href="#markdown"&gt;###&lt;/a&gt;markdown&lt;/h3&gt;
&lt;p&gt;mkdnflow to enhance.&lt;/p&gt;
&lt;p&gt;&lt;del&gt;&lt;kbd&gt;leader&lt;/kbd&gt;&lt;kbd&gt;m&lt;/kbd&gt;&lt;kbd&gt;p&lt;/kbd&gt; to open markdown-preview&lt;/del&gt; This is not necessary. Just render it in the terminal.&lt;/p&gt;
&lt;h2 id="detail-configure"&gt;
&lt;a class="anchor inpage" href="#detail-configure"&gt;##&lt;/a&gt;Detail Configure&lt;/h2&gt;
&lt;h3 id="options"&gt;
&lt;a class="anchor inpage" href="#options"&gt;###&lt;/a&gt;options&lt;/h3&gt;
&lt;p&gt;in /lua/config/options.lua&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="my-neovim">
  <a class="anchor inpage" href="#my-neovim">#</a>My neovim</h1>
<p>My 
 on github.</p>
<p>There is a 
 of my config, for fun.</p>
<p>I&rsquo;m using nvim as a code editor, mainly for latex and markdown.</p>
<h2 id="usage">
  <a class="anchor inpage" href="#usage">##</a>Usage</h2>
<h3 id="latex">
  <a class="anchor inpage" href="#latex">###</a>latex</h3>
<p>using vimtex to detect math environment, and texlab lsp to complie.</p>
<p><del>cmp</del> blink.cmp and <del>ultisnips</del> luasnip to enhance editing.</p>
<p>check 
.</p>
<h3 id="markdown">
  <a class="anchor inpage" href="#markdown">###</a>markdown</h3>
<p>mkdnflow to enhance.</p>
<p><del><kbd>leader</kbd><kbd>m</kbd><kbd>p</kbd> to open markdown-preview</del> This is not necessary. Just render it in the terminal.</p>
<h2 id="detail-configure">
  <a class="anchor inpage" href="#detail-configure">##</a>Detail Configure</h2>
<h3 id="options">
  <a class="anchor inpage" href="#options">###</a>options</h3>
<p>in /lua/config/options.lua</p>
<h3 id="lsp">
  <a class="anchor inpage" href="#lsp">###</a>lsp</h3>
<p>Config lsp by native nvim. Steal serval functions from nvim-lspconfig.</p>
<h3 id="plugins">
  <a class="anchor inpage" href="#plugins">###</a>plugins</h3>
<p>I am using lazy.nvim as my plugins manager. Plugins are divided in serval
classes, and following are some of mostly used plugins:</p>
<ul>
<li>edit: enhance for editing
<ul>
<li><del>
,</del></li>
<li>
</li>
<li>
,</li>
<li>
, gJ and gK to split or joint</li>
<li>treej</li>
<li>
, 中文输入自动切换</li>
<li>
,</li>
<li><del>
</del> zen mode, focus on editing 
</li>
<li>
, like a temporary git</li>
<li>
, translate words</li>
<li>
, jump anywhere</li>
<li><del>
,</del></li>
<li><del>
, commute ultisnips with cmp</del></li>
<li><del>
, lsp source</del></li>
<li><del>
, source from other buffers</del></li>
<li><del>
, path source</del></li>
<li>
</li>
<li>
, snippets</li>
<li>
, copilot source</li>
</ul>
</li>
<li>editor: enhance for latex and markdown
<ul>
<li>
, for latex</li>
<li>
, preview md in browser</li>
<li>
</li>
<li><del>
,</del> render md in nvim</li>
<li>
, help edit list, table etc in nvim</li>
</ul>
</li>
<li>git: using git in nvim
<ul>
<li>
, show git status at left, jump by hunks</li>
<li>
, show diff with history files</li>
<li>neogit</li>
</ul>
</li>
<li>lsp:
<ul>
<li><del>
, Configure lsp</del></li>
<li><del>
, install lsp</del></li>
<li><del>
, jump by definitions, references etc</del></li>
<li>
, jump by symbols etc</li>
</ul>
</li>
<li>file explorer:
<ul>
<li><del>
, file tree</del></li>
<li>
, yazi (tui file manager) in float terminal</li>
<li>snacks.picker.explorer, part of 
</li>
<li>
</li>
</ul>
</li>
<li>fuzzy finder
<ul>
<li><del>
,</del></li>
<li>snacks.picker, part of 
</li>
</ul>
</li>
<li>ui:
<ul>
<li>
, my theme</li>
<li>
, show color like <code>#123dfe</code></li>
<li>
, modeline, bufferline etc</li>
<li>
, show indent line etc</li>
</ul>
</li>
<li>enhance native functions:
<ul>
<li>
, plugin manager</li>
<li>
, <code>:</code> cmd and <code>/</code> search</li>
<li>
, show leader key sequence</li>
<li>
, search and replace</li>
<li>
, show start up time</li>
<li>
, sudo write files</li>
</ul>
</li>
</ul>
<h2 id="miscellanea">
  <a class="anchor inpage" href="#miscellanea">##</a>miscellanea</h2>
]]></content:encoded></item></channel></rss>