mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-02-07 06:19:03 +00:00
21 lines
11 KiB
HTML
21 lines
11 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Neovim text objects</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Neovim text objects</h1><section class="post-metadata"><span>Date: <!-- -->2022-04-01 16:06:02 +08:00</span><span>Date modified: <!-- -->2022-05-22 22:46:31 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"></ol></nav><p>(Neo)Vim has a bunch of text objects that are beyond simple boundaries other than a word (<code class="inline-verbatim">aw</code>, <code class="inline-verbatim">aW</code>).
|
|
You can find more of them with <code class="inline-verbatim">text-objects</code> section from <a href="/wiki/editor.neovim.help-system">Neovim help system</a>.
|
|
</p><table><thead><tr><th>Text object</th><th>Description</th></tr></thead><tbody><tr><td><code class="inline-verbatim">ap</code></td><td>A paragraph, equivalent to <code class="inline-verbatim">}</code>.</td></tr><tr><td><code class="inline-verbatim">as</code></td><td>A sentence, equivalent to <code class="inline-verbatim">)</code>.</td></tr><tr><td><code class="inline-verbatim">ab</code></td><td>A '( )' block.</td></tr><tr><td><code class="inline-verbatim">aB</code></td><td>A '{ }' block.</td></tr><tr><td><code class="inline-verbatim">a"</code></td><td>Content inside double-quotes (<code class="inline-verbatim">"</code>).</td></tr></tbody></table><p>There is also a variation for selecting only the inner content of the previous text objects (e.g., <code class="inline-verbatim">ip</code> for the inner paragraph, <code class="inline-verbatim">is</code> for inner sentence) with the whitespace removed.
|
|
</p><p>Note that selecting with text objects is different from selecting with <a href="roam:Neovim motions">roam:Neovim motions</a> where it refers to the current position up to the end of the next selection.
|
|
Meanwhile, text objects selection will select to the referred object as a whole no matter where the cursor position.
|
|
For example, selecting with the paragraph (i.e., <code class="inline-verbatim">vap</code>) will select the whole paragraph where the cursor rests.
|
|
</p><p>Aside from the built-in text objects, you can create your own.
|
|
Which also means others have created some custom text objects.
|
|
</p><ul><li><p><a href="https://github.com/nvim-treesitter/nvim-treesitter-textobjects">nvim-treesitter-textobjects</a> add text objects support for selecting (and swapping, moving, and peeking) tree-sitter nodes.
|
|
(Assuming you have tree-sitter support enabled for Neovim.)
|
|
</p></li></ul></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"2022-04-01 16:06:02 +08:00","date_modified":"2022-05-22 22:46:31 +08:00","language":"en","source":""},"title":"Neovim text objects","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"(Neo)Vim has a bunch of text objects that are beyond simple boundaries other than a word ("},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"aw"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"aW"}]},{"type":"text","value":").\nYou can find more of them with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"text-objects"}]},{"type":"text","value":" section from "},{"type":"element","tagName":"a","properties":{"href":"/editor.neovim.help-system"},"children":[{"type":"text","value":"Neovim help system"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"table","properties":{},"children":[{"type":"element","tagName":"thead","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Text object"}]},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Description"}]}]}]},{"type":"element","tagName":"tbody","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"ap"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"A paragraph, equivalent to "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"."}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"as"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"A sentence, equivalent to "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"."}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"ab"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"A '( )' block."}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"aB"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"A '{ }' block."}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"a\""}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Content inside double-quotes ("},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"\""}]},{"type":"text","value":")."}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"There is also a variation for selecting only the inner content of the previous text objects (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"ip"}]},{"type":"text","value":" for the inner paragraph, "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"is"}]},{"type":"text","value":" for inner sentence) with the whitespace removed.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Note that selecting with text objects is different from selecting with "},{"type":"element","tagName":"a","properties":{"href":"roam:Neovim motions"},"children":[{"type":"text","value":"roam:Neovim motions"}]},{"type":"text","value":" where it refers to the current position up to the end of the next selection.\nMeanwhile, text objects selection will select to the referred object as a whole no matter where the cursor position.\nFor example, selecting with the paragraph (i.e., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vap"}]},{"type":"text","value":") will select the whole paragraph where the cursor rests.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Aside from the built-in text objects, you can create your own.\nWhich also means others have created some custom text objects.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/nvim-treesitter/nvim-treesitter-textobjects"},"children":[{"type":"text","value":"nvim-treesitter-textobjects"}]},{"type":"text","value":" add text objects support for selecting (and swapping, moving, and peeking) tree-sitter nodes.\n (Assuming you have tree-sitter support enabled for Neovim.)\n"}]}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["editor.neovim.text-objects"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |