posts-go/docs/2023-05-03-neovim.html

439 lines
14 KiB
HTML
Raw Normal View History

2023-07-18 18:38:30 +00:00
<!doctype html>
2023-05-02 17:42:11 +00:00
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.6.1/github-markdown.min.css"
2023-05-02 17:42:11 +00:00
/>
<title>haunt98 posts</title>
</head>
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
2024-03-01 10:11:20 +00:00
font-family:
Shantell Sans Normal,
Rec Mono Casual,
SF Pro,
Inter,
sans-serif;
font-weight: 500;
}
.markdown-body pre {
font-family:
Berkeley Mono,
IBM Plex Mono,
SF Mono,
Jetbrains Mono,
monospace;
2023-05-02 17:42:11 +00:00
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
<body class="markdown-body">
2023-08-09 07:22:58 +00:00
<h2>
<a href="index.html"><code>~</code></a>
</h2>
2024-02-29 12:29:26 +00:00
<div class="markdown-heading">
<h1 class="heading-element">My neovim workflow</h1>
2023-11-19 15:59:21 +00:00
<a
id="user-content-my-neovim-workflow"
2024-03-08 08:12:41 +00:00
class="anchor"
2024-02-29 12:29:26 +00:00
aria-label="Permalink: My neovim workflow"
2023-11-19 15:59:21 +00:00
href="#my-neovim-workflow"
2024-02-29 12:29:26 +00:00
><span aria-hidden="true" class="octicon octicon-link"></span
></a>
</div>
2023-06-10 04:57:15 +00:00
<p>
<a
target="_blank"
rel="noopener noreferrer nofollow"
2024-05-12 16:22:38 +00:00
href="https://raw.githubusercontent.com/haunt98/posts-images/main/nvim-000.jxl"
2023-06-10 04:57:15 +00:00
><img
2024-05-12 16:22:38 +00:00
src="https://raw.githubusercontent.com/haunt98/posts-images/main/nvim-000.jxl"
2023-06-10 04:57:15 +00:00
alt="nvim-000"
style="max-width: 100%"
/></a>
</p>
2023-06-10 03:50:39 +00:00
<p>
All configs are in
<a href="https://github.com/haunt98/dotfiles">my dotfiles</a>.
</p>
2024-02-29 12:29:26 +00:00
<div class="markdown-heading">
<h2 class="heading-element">Trick or treat</h2>
2023-11-19 15:59:21 +00:00
<a
id="user-content-trick-or-treat"
2024-03-08 08:12:41 +00:00
class="anchor"
2024-02-29 12:29:26 +00:00
aria-label="Permalink: Trick or treat"
2023-11-19 15:59:21 +00:00
href="#trick-or-treat"
2024-02-29 12:29:26 +00:00
><span aria-hidden="true" class="octicon octicon-link"></span
></a>
</div>
2023-08-05 19:13:47 +00:00
<p>Search current word: <code>*</code></p>
2023-05-02 17:42:11 +00:00
<p>Search multiple words:</p>
2023-06-10 03:50:39 +00:00
<div class="highlight highlight-source-viml">
<pre>:/<span class="pl-cce">\v</span>word1|word2|word3</pre>
2023-05-02 17:42:11 +00:00
</div>
2023-06-10 03:50:39 +00:00
<p>Replace word:</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-k">%</span><span class="pl-c1">s</span><span class="pl-sr">/word1/</span>word2/<span class="pl-c1">g</span></pre>
</div>
2023-07-07 09:58:37 +00:00
<p>Delete all lines contain word:</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-c1">g</span><span class="pl-sr">/word/</span><span class="pl-c1">d</span></pre>
</div>
2023-08-09 09:53:49 +00:00
<p>Delete all lines <strong>not</strong> contain word:</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-c1">g</span><span class="pl-k">!</span><span class="pl-sr">/word/</span><span class="pl-c1">d</span>
:<span class="pl-c1">v</span><span class="pl-sr">/word/</span><span class="pl-c1">d</span></pre>
</div>
<p>Play macro <code>a</code> (after selecting lines):</p>
2023-09-10 14:32:49 +00:00
<div class="highlight highlight-source-viml">
<pre>:norm<span class="pl-k">!</span> <span class="pl-smi">@a</span></pre>
</div>
2023-07-19 08:31:38 +00:00
<p>Sort lines (after selecting lines):</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-c1">sort</span> <span class="pl-k">-</span><span class="pl-c1">u</span></pre>
</div>
<p>Reverse lines (after selcting lines):</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-k">!</span>tail <span class="pl-k">-</span><span class="pl-c1">r</span></pre>
</div>
2023-08-10 06:40:58 +00:00
<p>Column-ize lines:</p>
<div class="highlight highlight-source-viml">
<pre>:<span class="pl-k">!</span>column <span class="pl-k">-</span><span class="pl-c1">t</span></pre>
</div>
2024-02-29 12:29:26 +00:00
<div class="markdown-heading">
<h2 class="heading-element">Jumpo</h2>
2023-11-19 15:59:21 +00:00
<a
id="user-content-jumpo"
2024-03-08 08:12:41 +00:00
class="anchor"
2024-02-29 12:29:26 +00:00
aria-label="Permalink: Jumpo"
2023-11-19 15:59:21 +00:00
href="#jumpo"
2024-02-29 12:29:26 +00:00
><span aria-hidden="true" class="octicon octicon-link"></span
></a>
</div>
2023-07-19 08:31:38 +00:00
<p>Basic:</p>
2023-06-10 03:50:39 +00:00
<ul>
<li><code>gg</code>: first line</li>
<li><code>G</code>: last line</li>
<li><code>0</code>: first character of line</li>
<li><code>$</code>: last character of line</li>
<li><code>w</code>, <code>b</code>: word forward/backward</li>
2023-06-15 19:17:40 +00:00
<li><code>e</code>, <code>ge</code>: end of word current/before</li>
<li>
<code>W</code>, <code>B</code>: WORD (word with special char)
forward/backward
</li>
<li><code>E</code>, <code>gE</code>: end of WORD current/before</li>
2023-06-24 17:18:07 +00:00
<li>
<code>f{char}</code>, <code>F{char}</code>: find forward/backward
character
</li>
2024-03-20 18:45:57 +00:00
<li>
<code>%</code>: jump between matching pair of <code>()</code>,
<code>[]</code>, <code>{}</code>
</li>
2023-06-10 03:50:39 +00:00
</ul>
2023-07-19 08:31:38 +00:00
<p>Advance:</p>
2023-06-10 03:50:39 +00:00
<ul>
<li>
<code>CTRL-O</code>, <code>CTRL-I</code>: cursor position
backward/forward
</li>
<li><code>{</code>, <code>}</code>: paragraph backward/forward</li>
<li><code>H</code>: top of screen</li>
<li><code>M</code>: middle of screen</li>
<li><code>L</code>: bottom of screen</li>
<li>
<code>CTRL-]</code>, <code>CTRL-T</code>: jump to tag/jump back from tag
<ul>
<li>
2023-06-10 07:15:38 +00:00
Support jump to Go definition with
2023-06-10 03:50:39 +00:00
<a href="https://github.com/fatih/vim-go">fatih/vim-go</a>.
</li>
</ul>
</li>
</ul>
2024-02-29 12:29:26 +00:00
<div class="markdown-heading">
<h2 class="heading-element">Keymap</h2>
2023-11-19 15:59:21 +00:00
<a
id="user-content-keymap"
2024-03-08 08:12:41 +00:00
class="anchor"
2024-02-29 12:29:26 +00:00
aria-label="Permalink: Keymap"
2023-11-19 15:59:21 +00:00
href="#keymap"
2024-02-29 12:29:26 +00:00
><span aria-hidden="true" class="octicon octicon-link"></span
></a>
</div>
2023-07-04 06:24:03 +00:00
<p>Use both <code>\</code> and <code>;</code> as leader key:</p>
2023-06-10 03:50:39 +00:00
<div class="highlight highlight-source-lua">
2024-03-14 18:13:29 +00:00
<pre><span class="pl-smi">vim</span>.<span class="pl-e">keymap</span>.<span class="pl-c1">set</span>(<span class="pl-s"><span class="pl-pds">"</span>n<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>;<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>&lt;Leader&gt;<span class="pl-pds">"</span></span>, { <span class="pl-smi">remap</span> <span class="pl-k">=</span> <span class="pl-c1">true</span> })
<span class="pl-smi">vim</span>.<span class="pl-e">keymap</span>.<span class="pl-c1">set</span>(<span class="pl-s"><span class="pl-pds">"</span>n<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>'<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>&lt;Leader&gt;<span class="pl-pds">"</span></span>, { <span class="pl-smi">remap</span> <span class="pl-k">=</span> <span class="pl-c1">true</span> })</pre>
2023-07-07 06:49:38 +00:00
</div>
2023-09-23 05:34:27 +00:00
<p>Ground rules:</p>
2023-06-10 03:50:39 +00:00
<ul>
<li>
2023-07-04 06:24:03 +00:00
<p><code>&lt;Leader&gt;</code> prefix: prefer global keymap</p>
</li>
<li>
<p>
<code>&lt;Space&gt;</code> prefix: prefer lsp keymap, for coding of
course :D
</p>
</li>
2024-05-16 17:50:28 +00:00
<li>
<p>Native neovim:</p>
<ul>
2024-05-21 16:48:25 +00:00
<li><code>gcc</code>: comment/uncomment current line</li>
<li><code>gc</code>: comment/uncomment selected lines</li>
<li><code>gx</code>: open file/url under cursor</li>
<li><code>Q</code>, <code>@</code>: execute last macro</li>
2024-05-16 17:50:28 +00:00
<li><code>]d</code>, <code>[d</code>: next/previous diagnostic</li>
<li><code>K</code>: hover</li>
2024-05-16 17:50:28 +00:00
</ul>
</li>
2024-05-09 18:30:55 +00:00
<li>
<p>Black hole register:</p>
<ul>
<li><code>&lt;Leader&gt;d</code>: <code>d</code> without yank</li>
<li><code>&lt;Leader&gt;c</code>: <code>c</code> without yank</li>
<li><code>&lt;Leader&gt;x</code>: <code>x</code> without yank</li>
</ul>
</li>
2023-07-04 06:24:03 +00:00
<li>
<p>
With
<a href="https://github.com/ibhagwan/fzf-lua">ibhagwan/fzf-lua</a>:
</p>
<ul>
<li><code>&lt;Leader&gt;f</code>: find files</li>
2023-09-23 05:34:27 +00:00
<li><code>&lt;Leader&gt;l</code>: find lines</li>
2023-07-04 06:24:03 +00:00
<li><code>&lt;Leader&gt;rg</code>: grep files</li>
2024-05-09 18:30:55 +00:00
<li><code>&lt;Leader&gt;g</code>: git status</li>
2023-09-23 05:34:27 +00:00
<li>
With
<a href="https://github.com/neovim/nvim-lspconfig"
>neovim/nvim-lspconfig</a
>
helps:
<ul>
2024-05-09 18:30:55 +00:00
<li><code>&lt;Space&gt;s</code>: list lsp symbols</li>
<li>
<code>&lt;Space&gt;r</code>, <code>gr</code>: list references
</li>
<li>
<code>&lt;Space&gt;i</code>, <code>gi</code>: list
implementation
</li>
<li><code>&lt;Space&gt;ca</code>: list code action</li>
2023-09-23 05:34:27 +00:00
</ul>
</li>
2023-07-04 06:24:03 +00:00
</ul>
</li>
2024-05-09 18:30:55 +00:00
<li>
<p>
2024-05-21 16:48:25 +00:00
With
<a href="https://github.com/hrsh7th/nvim-cmp">hrsh7th/nvim-cmp</a>:
2024-05-09 18:30:55 +00:00
</p>
<ul>
<li><code>&lt;C-Space&gt;</code>: trigger completion</li>
</ul>
</li>
2023-07-04 06:24:03 +00:00
<li>
<p>
With
<a href="https://github.com/nvim-tree/nvim-tree.lua"
>nvim-tree/nvim-tree.lua</a
>, inside nvim-tree:
</p>
2023-06-23 07:40:04 +00:00
<ul>
2023-07-04 06:24:03 +00:00
<li><code>&lt;C-n&gt;</code>: toggle</li>
<li><code>&lt;Leader&gt;n</code>: locate file</li>
2023-06-24 14:57:22 +00:00
<li><code>a</code>: create</li>
2023-06-23 07:40:04 +00:00
<li><code>d</code>: delete</li>
<li><code>r</code>: rename</li>
<li><code>x</code>: cut</li>
<li><code>c</code>: copy</li>
<li><code>p</code>: paste</li>
2023-06-24 15:24:39 +00:00
<li><code>U</code>: toggle hidden</li>
2023-06-23 07:40:04 +00:00
</ul>
</li>
<li>
<p>
With
<a href="https://github.com/lewis6991/gitsigns.nvim"
>lewis6991/gitsigns.nvim</a
>:
</p>
<ul>
<li><code>]c</code>, <code>[c</code>: next/previous git change</li>
</ul>
</li>
2023-07-08 11:31:12 +00:00
<li>
<p>
With
<a href="https://github.com/tpope/vim-projectionist"
>tpope/vim-projectionist</a
>
</p>
<ul>
<li><code>:A</code>: open alternate file</li>
</ul>
</li>
2023-06-10 03:50:39 +00:00
<li>
2023-07-04 06:24:03 +00:00
<p>
With
<a href="https://github.com/echasnovski/mini.nvim"
>echasnovski/mini.nvim</a
>
</p>
2023-06-10 03:50:39 +00:00
<ul>
2023-06-23 07:40:04 +00:00
<li>
With mini-surround
<ul>
<li><code>sa</code>: add surround</li>
<li><code>sd</code>: delete surround</li>
<li><code>sr</code>: replace surround</li>
</ul>
</li>
2023-06-15 19:06:11 +00:00
</ul>
</li>
2024-05-09 18:30:55 +00:00
<li>
<p>
With
<a href="https://github.com/stevearc/conform.nvim"
>stevearc/conform.nvim</a
>:
</p>
<ul>
<li><code>&lt;Space&gt;f</code>: format code</li>
</ul>
</li>
2023-06-29 10:29:18 +00:00
<li>
2023-07-04 06:24:03 +00:00
<p>
With
<a href="https://github.com/neovim/nvim-lspconfig"
>neovim/nvim-lspconfig</a
2023-09-23 05:34:27 +00:00
>:
2023-07-04 06:24:03 +00:00
</p>
2023-06-29 10:29:18 +00:00
<ul>
2024-05-09 18:30:55 +00:00
<li><code>&lt;Space&gt;e</code>: current diagnostic</li>
<li><code>&lt;Space&gt;lr</code>: restart lsp server</li>
<li><code>gd</code>: go to definition</li>
<li><code>&lt;Space&gt;k</code>, <code>gk</code>: hover</li>
2023-06-29 10:29:18 +00:00
<li><code>&lt;F2&gt;</code>: rename</li>
2024-05-09 18:30:55 +00:00
</ul>
</li>
<li>
<p>
With
<a href="https://github.com/github/copilot.vim">github/copilot.vim</a
>:
</p>
<ul>
<li>
<code>&lt;M-Right&gt;</code>: completion, replace <code>Tab</code>
</li>
2023-10-03 05:50:32 +00:00
</ul>
</li>
2023-06-10 03:50:39 +00:00
</ul>
2024-02-29 12:29:26 +00:00
<div class="markdown-heading">
<h2 class="heading-element">References / Thanks</h2>
2023-11-19 15:59:21 +00:00
<a
id="user-content-references--thanks"
2024-03-08 08:12:41 +00:00
class="anchor"
2024-02-29 12:29:26 +00:00
aria-label="Permalink: References / Thanks"
2023-11-19 15:59:21 +00:00
href="#references--thanks"
2024-02-29 12:29:26 +00:00
><span aria-hidden="true" class="octicon octicon-link"></span
></a>
</div>
2023-06-10 03:50:39 +00:00
<ul>
2023-08-05 19:13:47 +00:00
<li>
vim docs:
<ul>
<li>
<a href="https://moolenaar.net/habits_2007.pdf" rel="nofollow"
>Seven habits of effective text editing 2.0</a
>
</li>
</ul>
</li>
2023-06-10 03:50:39 +00:00
<li>
2023-07-19 08:31:38 +00:00
neovim official docs:
<ul>
<li>
<a href="https://neovim.io/doc/user/motion.html" rel="nofollow"
>neovim Motion</a
>
</li>
<li>
<a href="http://neovim.io/doc/user/tagsrch.html" rel="nofollow"
>neovim Tagsrch</a
>
</li>
<li>
<a href="https://neovim.io/doc/user/lua-guide.html" rel="nofollow"
>neovim Lua-guide</a
>
</li>
</ul>
2023-07-01 09:06:30 +00:00
</li>
2023-07-07 09:58:37 +00:00
<li>
2023-07-19 08:31:38 +00:00
Hidden gem:
<ul>
<li>
<a
href="https://bluz71.github.io/2021/09/10/vim-tips-revisited.html"
rel="nofollow"
>Vim Tips (Revisited)</a
>
</li>
2024-04-15 06:52:03 +00:00
<li>
<a href="https://superuser.com/a/189956" rel="nofollow"
>How do I reverse selected lines order in Vim?</a
>
</li>
2023-07-19 08:31:38 +00:00
<li>
<a
2024-04-15 06:52:03 +00:00
href="https://www.redhat.com/sysadmin/use-vim-macros"
2023-07-19 08:31:38 +00:00
rel="nofollow"
2024-04-15 06:52:03 +00:00
>Use Vim macros to automate frequent tasks</a
2023-07-19 08:31:38 +00:00
>
</li>
2024-03-20 18:45:57 +00:00
<li>
<a
href="https://dev.to/m4xshen/3-vim-commands-for-blazingly-fast-navigation-between-brackets-55kc"
rel="nofollow"
>3 Vim commands for blazingly fast navigation between brackets
</a
>
</li>
2023-07-19 08:31:38 +00:00
</ul>
2023-07-07 09:58:37 +00:00
</li>
2023-06-10 03:50:39 +00:00
</ul>
2023-05-02 17:42:11 +00:00
<div>
Feel free to ask me via
<a href="mailto:hauvipapro+posts@gmail.com">email</a> or
2023-08-20 17:29:13 +00:00
<a rel="me" href="https://hachyderm.io/@haunguyen">Mastodon</a>.
<br />Source code is available on
2023-05-02 17:42:11 +00:00
<a href="https://github.com/haunt98/posts-go">GitHub</a>
2023-08-20 17:29:13 +00:00
<a href="https://codeberg.org/yoshie/posts-go">Codeberg</a>
<a href="https://git.sr.ht/~youngyoshie/posts-go">sourcehut</a>
<a href="https://gitea.treehouse.systems/yoshie/posts-go">Treehouse</a>
<a href="https://gitlab.com/youngyoshie/posts-go">GitLab</a>
2023-05-02 17:42:11 +00:00
</div>
</body>
</html>