[
  {
    "path": ".gitattributes",
    "content": "scripts/* -linguist-detectable\n"
  },
  {
    "path": "README.ja.md",
    "content": ":arrow_upper_left: (迷子になった？ GitHub TOCを使いましょう！)\n\n**:warning: :warning: :warning: このガイドの最新版は、Neovimのドキュメントにあります。 [`:help lua-guide`](https://neovim.io/doc/user/lua-guide.html#lua-guide)を参照してください。 :warning: :warning: :warning:**\n\n日本語はこちら→https://github.com/willelz/neovimdoc-ja/blob/main/doc/lua-guide.jax\n\n# Getting started using Lua in Neovim\n\n## はじめに\n\nNeovimの[ファーストクラス言語](https://github.com/neovim/neovim/wiki/FAQ#why-embed-lua-instead-of-x)としての[Lua](https://www.youtube.com/watch?v=IP3J56sKtn0)はキラー機能の1つになりつつあります。\nしかし、Luaでプラグインを書くための教材はVim script程多くありません。これは、Luaを始めるための基本的な情報を提供する試みです。\n\nこのガイドは少なくともNeovim 0.5を使用していることを前提としています。\n\n### Luaを学ぶ\n\nまだLuaについて詳しくない場合、学ぶためのリソースはたくさんあります。:\n\n- [Learn X in Y minutes page about Lua](https://learnxinyminutes.com/docs/lua/)は基本的な概要を説明します。\n- [このガイド](https://github.com/medwatt/Notes/blob/main/Lua/Lua_Quick_Guide.ipynb)も素早く始めるのに良いチュートリアルです。\n- 動画が好きなら、Derek Banasの動画があります。[1-hour tutorial on the language](https://www.youtube.com/watch?v=iMacxZQMPXs)\n- 実行できるサンプルを使い、対話的に学びたいですか？[LuaScript tutorial](https://www.luascript.dev/learn)を試してみてください。\n- [lua-users wiki](http://lua-users.org/wiki/LuaDirectory)にはLua関連のトピックごとの便利な情報がたくさんあります。\n- [official reference manual for Lua](https://www.lua.org/manual/5.1/)には最も包括的な情報があります。(エディタで快適に読みたいなら、Vimdocプラグインがあります。:[milisims/nvim-luaref](https://github.com/milisims/nvim-luaref))\n\nLuaはとてもクリーンでシンプルな言語であることに注意してください。JavaScriptのようなスクリプト言語の経験があれば、学ぶことは簡単です。あなたはもう自分で思っているよりLuaについて知っているかもしれません！\n\nNote: Neovimに埋め込まれているLuaは[LuaJIT](https://staff.fnwi.uva.nl/h.vandermeer/docs/lua/luajit/luajit_intro.html) 2.1.0でLua 5.1と互換性を維持しています。\n\n### Luaを書くための既存のチュートリアル\n\nLuaでプラグインを書くためのチュートリアルが既にいくつかあります。それらはこのガイドを書くのに役に立ちました。筆者に感謝します。\n\n- [teukka.tech - init.vimからinit.luaへ](https://teukka.tech/luanvim.html)\n- [dev.to - プラグインをLuaで書く方法](https://dev.to/2nit/how-to-write-neovim-plugins-in-lua-5cca)\n- [dev.to - プラグインのUIをLuaで作る方法](https://dev.to/2nit/how-to-make-ui-for-neovim-plugins-in-lua-3b6e)\n- [ms-jpq - Neovim Async Tutorial](https://github.com/ms-jpq/neovim-async-tutorial)\n- [oroques.dev - Neovim 0.5の機能とinit.luaへの切り替え](https://oroques.dev/notes/neovim-init/)\n- [ゼロからステータスラインを作る - jdhao's blog](https://jdhao.github.io/2019/11/03/vim_custom_statusline/)\n- [LuaでNeovimを設定する](https://icyphox.sh/blog/nvim-lua/)\n- [Devlog | Luaで設定するために知る必要のあること](https://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/)\n\n### 関連するプラグイン\n\n- [Vimpeccable](https://github.com/svermeulen/vimpeccable) - .vimrc内でLuaを書くのに役に立つプラグイン\n- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) - 二度書きたくないLua関数のすべて\n- [popup.nvim](https://github.com/nvim-lua/popup.nvim) - vimのPopup APIのNeovimでの実装\n- [nvim_utils](https://github.com/norcalli/nvim_utils)\n- [nvim-luadev](https://github.com/bfredl/nvim-luadev) - REPL/debugコンソール\n- [nvim-luapad](https://github.com/rafcamlet/nvim-luapad) - 組込みLuaエンジンのインタラクティブなリアルタイムスクラッチパッド\n- [nlua.nvim](https://github.com/tjdevries/nlua.nvim) - NeovimのLua開発\n- [BetterLua.vim](https://github.com/euclidianAce/BetterLua.vim) - Vim/Neovimより良いシンタックスハイライト\n\n## Luaファイルを置く場所\n\n### init.lua\n\nNeovimは、`init.vim`の代わりに設定ファイルとして`init.lua`を読み込むことをサポートしています。\n\nNote: `init.lua`は _完全に_ オプションです。`init.vim`は廃止されず、設定として有効です。\nいくつかの機能は、まだ100%Luaに公開されていないので注意してください。\n\n参照:\n- [`:help config`](https://neovim.io/doc/user/starting.html#config)\n\n### モジュール\n\nLuaモジュールは、`runtimepath`内の`lua/`フォルダにあります(ほとんどの場合、\\*nixでは`~/.config/nvim/lua`、Windowsでは`~/AppData/Local/nvim/lua`を意味します)。\nこのフォルダにあるファイルをLuaモジュールとして`require()`できます。\n\n例として次のフォルダ構造を取り上げましょう。:\n\n```text\n📂 ~/.config/nvim\n├── 📁 after\n├── 📁 ftplugin\n├── 📂 lua\n│  ├── 🌑 myluamodule.lua\n│  └── 📂 other_modules\n│     ├── 🌑 anothermodule.lua\n│     └── 🌑 init.lua\n├── 📁 pack\n├── 📁 plugin\n├── 📁 syntax\n└── 🇻 init.vim\n```\n\n次のLuaコードは`myluamodule.lua`をロードします。:\n\n```lua\nrequire('myluamodule')\n```\n\n`.lua`拡張子がないことに注意してください。\n\n同様に、`other_modules/anothermodule.lua` のロードは次のように行います。:\n\n```lua\nrequire('other_modules.anothermodule')\n-- or\nrequire('other_modules/anothermodule')\n```\n\nパスの区切りはドット`.`またはスラッシュ`/`で示されます。\n\nフォルダに`init.lua`が含まれている場合、ファイル名を指定せずにロードできます。\n\n```lua\nrequire('other_modules') -- other_modules/init.luaをロード\n```\n\n存在しないモジュール、構文エラーを含むモジュールをrequireすると実行中のスクリプトは停止します。\nエラーを防ぐために、`pcall()`を使用できます。\n\n```lua\nlocal ok, _ = pcall(require, 'module_with_error')\nif not ok then\n  -- not loaded\nend\n```\n\n参照:\n- [`:help lua-require`](https://neovim.io/doc/user/lua.html#lua-require)\n\n#### Tips\n\nいくつかのLuaプラグインは`lua/`フォルダ内に同じ名前のファイルがあるかもしれません。これにより、名前空間の衝突を起こす可能性があります。\n\n異なる2つのプラグインに`lua/main.lua`がある場合、`require('main')`は曖昧です。: どのファイルを読み込みますか？\n\nトップレベルのフォルダで名前空間をつけることをお勧めします。: `lua/plugin_name/main.lua`\n\n#### Runtime files\n\nVim scriptと同様に、`runtimepath`内にある特定のフォルダからLuaファイルを自動的に読み込めます。\n現在、次のフォルダがサポートされています。:\n\n- `colors/`\n- `compiler/`\n- `ftplugin/`\n- `ftdetect/`\n- `indent/`\n- `plugin/`\n- `syntax/`\n\nNote: runtimeデイレクトリでは、すべての`*.vim`ファイルは`*.lua`ファイルの前に読み込まれます。\n\n\n参照:\n- [`:help 'runtimepath'`](https://neovim.io/doc/user/options.html#'runtimepath')\n- [`:help load-plugins`](https://neovim.io/doc/user/starting.html#load-plugins)\n\n#### Tips\n\nランタイムファイルはLuaのモジュールシステムをベースとしていないため、2つのプラグインは`plugin/main.lua`を問題なく持つことができます。\n\n## Vim scriptからLuaを使用する\n\n### :lua\n\nLuaのチャンクを実行します。\n\n```vim\n:lua require('myluamodule')\n```\n\nヒアドキュメント構文を使用すると複数行に書くことができます。:\n\n```vim\necho \"Here's a bigger chunk of Lua code\"\n\nlua << EOF\nlocal mod = require('mymodule')\nlocal tbl = {1, 2, 3}\n\nfor k, v in ipairs(tbl) do\n    mod.method(v)\nend\n\nprint(tbl)\nEOF\n```\n\nNote: 各`:lua`コマンドは独自のスコープを持っており、`local`を付けた変数はコマンドの外からアクセスできません。\n次の例は動作しません。:\n\n```vim\n:lua local foo = 1\n:lua print(foo)\n\" '1'ではなく'nil'が出力されます。\n```\n\nNote 2: Luaの`print()`は`:echomsg`と同じように動作します。出力はメッセージ履歴に保存されます。また、`:silent`で抑制できます。\n\n参照:\n\n- [`:help :lua`](https://neovim.io/doc/user/lua.html#Lua)\n- [`:help :lua-heredoc`](https://neovim.io/doc/user/lua.html#:lua-heredoc)\n\n### :luado\n\nこのコマンドはカレントバッファの範囲行にLuaチャンクを実行します。範囲を指定しない場合、バッファ全体に作用します。\nチャンクから`return`された文字列は、各行を置き換えるために使用されます。\n\n次のコマンドは、カレントバッファのすべての行を`hello world`に置き換えます。:\n\n```vim\n:luado return 'hello world'\n```\n\n2つの暗黙的な変数`line`と`liner`が提供されます。`line`は対象行のテキストで、`liner`はその行数です。\n次のコマンドは、すべての偶数行のテキストを大文字にします。\n\n```vim\n:luado if linenr % 2 == 0 then return line:upper() end\n```\n\n参照:\n\n- [`:help :luado`](https://neovim.io/doc/user/lua.html#:luado)\n\n### Luaファイルの読み込み\n\nNeovimはLuaファイルを読み込むためのEXコマンドを3つ提供しています。\n\n- `:luafile`\n- `:source`\n- `:runtime`\n\n`:luafile`と`:source`はとてもよく似ています。:\n\n```vim\n:luafile ~/foo/bar/baz/myluafile.lua\n:luafile %\n:source ~/foo/bar/baz/myluafile.lua\n:source %\n```\n\n`:source`は範囲指定もサポートしており、スクリプトの一部を実行するのに役立ちます。:\n\n```vim\n:1,10source\n```\n\n`:runtime`は少し異なります。: `'runtimepath'`オプションで読み込むファイルを指定します。\n詳細は[`:help :runtime`](https://neovim.io/doc/user/repeat.html#:runtime)を参照してください。\n\n参照:\n\n- [`:help :luafile`](https://neovim.io/doc/user/lua.html#:luafile)\n- [`:help :source`](https://neovim.io/doc/user/repeat.html#:source)\n- [`:help :runtime`](https://neovim.io/doc/user/repeat.html#:runtime)\n\n#### Sourcing a lua file vs calling require():\n\n`require()`関数を呼ぶこととLuaファイルの読み込みの違いは何か、どちらを使うべきかを疑問に思うかもしれません。\nそれらには異なるユースケースがあります。:\n\n- `require()`:\n    - Luaの組込み関数です。Luaのモジュールを読み込むのに使用します。\n    - `'runtimepath'`内にある`lua/`フォルダからモジュールを探します。\n    - どのモジュールをロードしたかを記憶し、多重に実行されるのを防ぎます。Neovim実行中に、モジュールに含まれるコードを変更し、もう一度`require()`を実行してもモジュールは更新されません。\n- `:luafile`, `:source`, `runtime`:\n    - Exコマンドです。モジュールには対応していません。\n    - 以前に実行されたかどうかに関わらず実行されます。\n    - `:luafile`と`:source`は現在のウィンドウのディレクトリに対して相対パス・絶対パスを取ります。\n    - `runtime`は、`'rutimepath'`オプションを使用してファイルを探します。\n\n`:source`や`:runtime`、ランタイムディレクトリから自動的に読み込まれたファイルも`scriptnames`と`--startuptime`に表示されます。\n\n### luaeval()\n\nVim scriptの組込み関数です。文字列のLua式を評価して返します。\nLuaの型は自動的にVim scriptの型に変換されます。(その逆も同様です。)\n\n```vim\n\" 変数に結果を代入することができます。\nlet variable = luaeval('1 + 1')\necho variable\n\" 2\nlet concat = luaeval('\"Lua\"..\" is \"..\"awesome\"')\necho concat\n\" 'Lua is awesome'\n\n\" リストのようなテーブルはVimのリストに変換されます。\nlet list = luaeval('{1, 2, 3, 4}')\necho list[0]\n\" 1\necho list[1]\n\" 2\n\" 注意 Luaのテーブルと違い、Vimのリストは0インデックスです。\n\n\" 辞書のようなテーブルはVimの辞書に変換されます。\nlet dict = luaeval('{foo = \"bar\", baz = \"qux\"}')\necho dict.foo\n\" 'bar'\n\n\" bool値とnilも同様です。\necho luaeval('true')\n\" v:true\necho luaeval('nil')\n\" v:null\n\n\" Lua関数のエイリアスをVim scriptで作ることができます。\nlet LuaMathPow = luaeval('math.pow')\necho LuaMathPow(2, 2)\n\" 4\nlet LuaModuleFunction = luaeval('require(\"mymodule\").myfunction')\ncall LuaModuleFunction()\n\n\" Vimの関数にLuaの関数を値として渡すこともできます。\nlua X = function(k, v) return string.format(\"%s:%s\", k, v) end\necho map([1, 2, 3], luaeval(\"X\"))\n```\n\n`luaeval()`は式にデータを渡すことのできる任意の2つ目の引数があります。Luaからは`_A`としてアクセスできます。\n\n```vim\necho luaeval('_A[1] + _A[2]', [1, 1])\n\" 2\n\necho luaeval('string.format(\"Lua is %s\", _A)', 'awesome')\n\" 'Lua is awesome'\n```\n\n参照:\n- [`:help luaeval()`](https://neovim.io/doc/user/lua.html#luaeval())\n\n### v:lua\n\nVimのグローバル変数です。Vim scriptからLuaのグローバル名前空間([`_G`](https://www.lua.org/manual/5.1/manual.html#pdf-_G)) 内の関数を直接呼ぶことができます。\nこの場合でも、Vim scriptの型はLuaの型に変換されます。逆も同様です。\n\n```vim\ncall v:lua.print('Hello from Lua!')\n\" 'Hello from Lua!'\n\nlet scream = v:lua.string.rep('A', 10)\necho scream\n\" 'AAAAAAAAAA'\n\n\" How about a nice statusline?\nlua << EOF\nfunction _G.statusline()\n    local filepath = '%f'\n    local align_section = '%='\n    local percentage_through_file = '%p%%'\n    return string.format(\n        '%s%s%s',\n        filepath,\n        align_section,\n        percentage_through_file\n    )\nend\nEOF\n\nset statusline=%!v:lua.statusline()\n\n\" Also works in expression mappings\nlua << EOF\nfunction _G.check_back_space()\n    local col = vim.api.nvim_win_get_cursor(0)[2]\n    return (col == 0 or vim.api.nvim_get_current_line():sub(col, col):match('%s')) and true\nend\nEOF\n\ninoremap <silent> <expr> <Tab>\n    \\ pumvisible() ? \"\\<C-N>\" :\n    \\ v:lua.check_back_space() ? \"\\<Tab>\" :\n    \\ completion#trigger_completion()\n\n\" シングルクォートを使用したり、括弧を省略して、Luaモジュールから関数を呼び出します:\ncall v:lua.require'module'.foo()\n```\n\n参照:\n- [`:help v:lua`](https://neovim.io/doc/user/eval.html#v:lua)\n- [`:help v:lua-call`](https://neovim.io/doc/user/lua.html#v:lua-call)\n\n#### 警告\n\nこの変数は関数呼び出しにのみ使用できます。次の例はエラーになります。:\n\n```vim\n\" 関数のエイリアスは動作しません\nlet LuaPrint = v:lua.print\n\n\" 辞書アクセスは動作しません\necho v:lua.some_global_dict['key']\n\n\" 関数を値として使用できません\necho map([1, 2, 3], v:lua.global_callback)\n```\n\n### Tips\n\n設定ファイルに、`let g:vimsyn_embed = 'l'`を追加すると.vimファイル内のLuaを構文ハイライトできます。\n詳細は[`:help g:vimsyn_embed`](https://neovim.io/doc/user/syntax.html#g:vimsyn_embed)を参照してください。\n\n## vim名前空間\n\nNeovimはLuaからAPIを使うためのエントリーポイントとして、`vim`グローバル変数を公開しています。\nこれは、拡張された標準ライブラリやさまざまなサブモジュールを提供します。\n\nいくつかの注目すべき関数とモジュール:\n\n- `vim.inspect`: Luaオブジェクトを人間が読みやすい文字列に変換する(テーブルを調べるのに便利です。)\n- `vim.regex`: LuaからVimの正規表現を使う\n- `vim.api`: API関数を公開するモジュール(リモートプラグインで使うAPIと同じです)\n- `vim.ui`: プラグインから利用できる上書き可能な関数\n- `vim.loop`: Neovimのイベントループ機能を公開するモジュール(LibUVを使います)\n- `vim.lsp`: 組込みのLSPクライアントを操作するモジュール\n- `vim.treesitter`: tree-sitterライブラリの機能を公開するモジュール\n\nこのリストは決して包括的なリストではありません。`vim`変数で何かできるかを詳しく知りたい場合は、[`:help lua-stdlib`](https://neovim.io/doc/user/lua.html#lua-stdlib)と[`:help lua-vim`](https://neovim.io/doc/user/lua.html#lua-vim)が最適です。\nまたは、`:lua print(vim.inspect(vim))`を実行してすべてのモジュールのリストを取得できます。\nAPI関数は、[`:help api-global`](https://neovim.io/doc/user/api.html#api-global)にあります。\n\n#### Tips\n\nオブジェクトの中身を検査するのに毎回`print(vim.inspect(x))`を書くのは面倒です。設定にグローバルなラッパー関数を含めることは価値があるかもしれません。(Neovim 0.7.0+では、この関数は組込み関数です。参照 [`:help vim.pretty_print()`](https://neovim.io/doc/user/lua.html#vim.pretty_print())):\n\n```lua\nfunction _G.put(...)\n  local objects = {}\n  for i = 1, select('#', ...) do\n    local v = select(i, ...)\n    table.insert(objects, vim.inspect(v))\n  end\n\n  print(table.concat(objects, '\\n'))\n  return ...\nend\n```\n\nコードまたはコマンドラインからとても早くオブジェクトの中身を検査できます。\n\n```lua\nput({1, 2, 3})\n```\n\n```vim\n:lua put(vim.loop)\n```\n\nまたは、`:lua`コマンドでLua式の前に `=` をつけて、整列させて表示できます。(Neovim 0.7+のみ)\n\n```vim\n:lua =vim.loop\n```\n\n加えて、他の言語と比較して組込みのLua関数が不足している場合があります(例えば、`os.clock`はミリ秒ではなく秒数のみを返します)。\n必ず、Neovim stdlib(それと`vim.fn`。詳しくは後述します。)を見てください。おそらく、探しものはそこにあります。\n\n## LuaからVim scriptを使用する\n\n### vim.api.nvim_eval()\n\n文字列で与えられたVim scriptの式を評価してその値を返します。Vim scriptの型は自動的にLuaの型に変換されます。(その逆も同様です。)\n\nこれは、Vim scriptの`luaeval()`と同様です。\n\n```lua\n-- 型は正しく変換されます。\nprint(vim.api.nvim_eval('1 + 1')) -- 2\nprint(vim.inspect(vim.api.nvim_eval('[1, 2, 3]'))) -- { 1, 2, 3 }\nprint(vim.inspect(vim.api.nvim_eval('{\"foo\": \"bar\", \"baz\": \"qux\"}'))) -- { baz = \"qux\", foo = \"bar\" }\nprint(vim.api.nvim_eval('v:true')) -- true\nprint(vim.api.nvim_eval('v:null')) -- nil\n```\n\n#### 警告\n\n`luaeval()`と違い、式にデータを渡すための暗黙的な変数`_A`を提供しません。\n\n### vim.api.nvim_exec()\n\nVim scriptのチャンクを実行します。実行するソースコートを含む文字列と、コードの出力を返すかどうかを決めるbool値を受け取ります(例えば、出力を変数に格納できます)。\n\n```lua\nlocal result = vim.api.nvim_exec(\n[[\nlet s:mytext = 'hello world'\n\nfunction! s:MyFunction(text)\n    echo a:text\nendfunction\n\ncall s:MyFunction(mytext)\n]],\ntrue)\n\nprint(result) -- 'hello world'\n```\n\n#### 警告\n\nNeovim 0.6.0より前のバージョンでは 、`nvim_exec` はスクリプトローカル変数(`s:`)をサポートしていません。\n\n### vim.api.nvim_command()\n\nExコマンドを実行します。実行するコマンドを含む文字列を受け取ります。\n\n```lua\nvim.api.nvim_command('new')\nvim.api.nvim_command('wincmd H')\nvim.api.nvim_command('set nonumber')\nvim.api.nvim_command('%s/foo/bar/g')\n```\n\n### vim.cmd()\n\n`vim.api.nvim_exec()`のエイリアスです。コマンドの引数のみを必要とし、`output`は常に`false`に設定されます。\n\n```lua\nvim.cmd('buffers')\nvim.cmd([[\nlet g:multiline_list = [\n            \\ 1,\n            \\ 2,\n            \\ 3,\n            \\ ]\n\necho g:multiline_list\n]])\n```\n\n#### Tips\n\nこれらの関数は文字列を渡すため、多くの場合、バックスラッシュをエスケープする必要があります。:\n\n```lua\nvim.cmd('%s/\\\\Vfoo/bar/g')\n```\n\n二重括弧の文字列はエスケープが必要ないため使いやすいです。:\n\n```lua\nvim.cmd([[%s/\\Vfoo/bar/g]])\n```\n\n### vim.api.nvim_replace_termcodes()\n\nこのAPI関数はターミナルコードとVimのキーコードをエスケープできます。\n\n次のようなマッピングを見たことがあるかもしれません。:\n\n```vim\ninoremap <expr> <Tab> pumvisible() ? \"\\<C-N>\" : \"\\<Tab>\"\n```\n\n同じことをLuaでやると大変です。次のようにやるかもしれません。:\n\n```lua\nfunction _G.smart_tab()\n    return vim.fn.pumvisible() == 1 and [[\\<C-N>]] or [[\\<Tab>]]\nend\n\nvim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr = true, noremap = true})\n```\n\nマッピングに `\\<Tab>` と `\\<C-N>` が挿入されているのを知るためだけに...\n\nキーコードをエスケープできるのは、Vim scriptの機能です。`\\r`, `\\42` や `\\x10` のような多くのプログラミング言語に共通する通常のエスケープシーケンスとは別に、Vim scriptの `expr-quotes` (ダブルクォートで囲まれる文字列)を使用すると、人間が読める表現のVimキーコードをエスケープします。\n\nLuaにはそのような機能は組み込まれていません。嬉しいことに、NeovimにはターミナルコードとキーコードをエスケープするAPI関数 `nvim_replace_termcodes()` があります。:\n\n```lua\nprint(vim.api.nvim_replace_termcodes('<Tab>', true, true, true))\n```\n\nこれは少し冗長です。再利用できるラッパーを作ると便利です。:\n\n```lua\n-- `termcodes` 専用の `t` 関数です\n-- この名前で呼ばなくてもいいですが、この簡潔さが便利です\nlocal function t(str)\n    -- 必要に応じてboolean引数で調整します\n    return vim.api.nvim_replace_termcodes(str, true, true, true)\nend\n\nprint(t'<Tab>')\n```\n\n先程の例はこれで期待通りに動きます:\n\n```lua\nlocal function t(str)\n    return vim.api.nvim_replace_termcodes(str, true, true, true)\nend\n\nfunction _G.smart_tab()\n    return vim.fn.pumvisible() == 1 and t'<C-N>' or t'<Tab>'\nend\n\nvim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr = true, noremap = true})\n```\n\n`vim.keymap.set()`では、このハックは必要ありません。`expr`が有効な場合、デフォルトで自動的に変換されます。:\n\n```lua\nvim.keymap.set('i', '<Tab>', function()\n    return vim.fn.pumvisible() == 1 and '<C-N>' or '<Tab>'\nend, {expr = true})\n```\n\n参照:\n- [`:help keycodes`](https://neovim.io/doc/user/intro.html#keycodes)\n- [`:help expr-quote`](https://neovim.io/doc/user/eval.html#expr-quote)\n- [`:help nvim_replace_termcodes()`](https://neovim.io/doc/user/api.html#nvim_replace_termcodes())\n\n## vimオプションを管理する\n\n### API関数を使用する\n\nNeovimは、オプションの値を読み書きできるAPI関数を提供しています。\n\n- グローバルオプション:\n    - [`vim.api.nvim_set_option()`](https://neovim.io/doc/user/api.html#nvim_set_option())\n    - [`vim.api.nvim_get_option()`](https://neovim.io/doc/user/api.html#nvim_get_option())\n- バッファオプション:\n    - [`vim.api.nvim_buf_set_option()`](https://neovim.io/doc/user/api.html#nvim_buf_set_option())\n    - [`vim.api.nvim_buf_get_option()`](https://neovim.io/doc/user/api.html#nvim_buf_get_option())\n- ウィンドウオプション:\n    - [`vim.api.nvim_win_set_option()`](https://neovim.io/doc/user/api.html#nvim_win_set_option())\n    - [`vim.api.nvim_win_get_option()`](https://neovim.io/doc/user/api.html#nvim_win_get_option())\n\nそれらはオプションの名前と設定したい値を含む文字列を受け取ります。\n\nboolな(`(no)number`のような)オプションは`true`か`false`のどちらかに設定する必要があります。:\n\n```lua\nvim.api.nvim_set_option('smarttab', false)\nprint(vim.api.nvim_get_option('smarttab')) -- false\n```\n\n当然ながら、文字列のオプションには文字列を設定する必要があります。:\n\n```lua\nvim.api.nvim_set_option('selection', 'exclusive')\nprint(vim.api.nvim_get_option('selection')) -- 'exclusive'\n```\n\n数値のオプションは数値を受け取ります。:\n\n```lua\nvim.api.nvim_set_option('updatetime', 3000)\nprint(vim.api.nvim_get_option('updatetime')) -- 3000\n```\n\nバッファローカルとウィンドウローカルなオプションはそれぞれの番号も必要です。(`0`を指定した場合、カレントバッファ/ウィンドウが対象になります。):\n\n```lua\nvim.api.nvim_win_set_option(0, 'number', true)\nvim.api.nvim_buf_set_option(10, 'shiftwidth', 4)\nprint(vim.api.nvim_win_get_option(0, 'number')) -- true\nprint(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4\n```\n\n### メタアクセサーを使用する\n\nもっと使い慣れた方法でオプションを設定したい場合、いくつかのメタアクセサーを使用できます。それらは、上記のAPI関数をラップしたものでオプションを変数のように操作できます。:\n\n- [`vim.o.{option}`](https://neovim.io/doc/user/lua.html#vim.o): `:let &{option-name}`のように動作します\n- [`vim.go.{option}`](https://neovim.io/doc/user/lua.html#vim.go): `:let &g:{option-name}`のように動作します\n- [`vim.bo.{option}`](https://neovim.io/doc/user/lua.html#vim.bo): バッファローカルオプションの場合`:let &l:{option-name}`のように動作します\n- [`vim.wo.{option}`](https://neovim.io/doc/user/lua.html#vim.wo): ウィンドウローカルオプションの場合`:let &l:{option-name}`のように動作します\n\n```lua\nvim.o.smarttab = false -- let &smarttab = v:false\nprint(vim.o.smarttab) -- false\nvim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname = &isfname .. ',@-@'\nprint(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'\n\nvim.bo.shiftwidth = 4\nprint(vim.bo.shiftwidth) -- 4\n```\n\nバッファとウィンドウの番号を指定できます。0を指定した場合、カレントバッファ/ウィンドウが使用されます。:\n\n```lua\nvim.bo[4].expandtab = true -- same as vim.api.nvim_buf_set_option(4, 'expandtab', true)\nvim.wo.number = true -- same as vim.api.nvim_win_set_option(0, 'number', true)\n```\n\nこれらには、Luaで設定するのに便利なより洗練されたラッパーとして`vim.opt`があります。\n`init.vim`で慣れているものと似ています。:\n\n- `vim.opt.{option}`: `:set`のように動作します\n- `vim.opt_global.{option}`: `:setglobal`のように動作します\n- `vim.opt_local.{option}`: `:setlocal`のように動作します\n\n```lua\nvim.opt.smarttab = false\nprint(vim.opt.smarttab:get()) -- false\n```\n\nいくつかのオプションはLuaのテーブルを使用して設定できます。:\n\n```lua\nvim.opt.completeopt = {'menuone', 'noselect'}\nprint(vim.inspect(vim.opt.completeopt:get())) -- { \"menuone\", \"noselect\" }\n```\n\nlist、map、setのようなオプションのラッパーには、Vim scriptの`:set+=`, `:set^=`, `:set-=`と同じように動作するメソッドとメタメソッドが用意されています。\n\n```lua\nvim.opt.shortmess:append({ I = true })\n-- どちらも等価です:\nvim.opt.shortmess = vim.opt.shortmess + { I = true }\n\nvim.opt.whichwrap:remove({ 'b', 's' })\n-- どちらも等価です:\nvim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' }\n```\n\n詳細は、必ず[`:help vim.opt`](https://neovim.io/doc/user/lua.html#vim.opt)を参照してください。\n\n参照:\n- [`:help lua-vim-options`](https://neovim.io/doc/user/lua.html#lua-vim-options)\n\n## vim内部の変数を管理する\n\n### API関数を使用する\n\nオプションのように、内部変数にもAPI関数があります。\n\n- グローバル変数 (`g:`):\n    - [`vim.api.nvim_set_var()`](https://neovim.io/doc/user/api.html#nvim_set_var())\n    - [`vim.api.nvim_get_var()`](https://neovim.io/doc/user/api.html#nvim_get_var())\n    - [`vim.api.nvim_del_var()`](https://neovim.io/doc/user/api.html#nvim_del_var())\n- バッファ変数 (`b:`):\n    - [`vim.api.nvim_buf_set_var()`](https://neovim.io/doc/user/api.html#nvim_buf_set_var())\n    - [`vim.api.nvim_buf_get_var()`](https://neovim.io/doc/user/api.html#nvim_buf_get_var())\n    - [`vim.api.nvim_buf_del_var()`](https://neovim.io/doc/user/api.html#nvim_buf_del_var())\n- ウィンドウ変数 (`w:`):\n    - [`vim.api.nvim_win_set_var()`](https://neovim.io/doc/user/api.html#nvim_win_set_var())\n    - [`vim.api.nvim_win_get_var()`](https://neovim.io/doc/user/api.html#nvim_win_get_var())\n    - [`vim.api.nvim_win_del_var()`](https://neovim.io/doc/user/api.html#nvim_win_del_var())\n- タブ変数 (`t:`):\n    - [`vim.api.nvim_tabpage_set_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_set_var())\n    - [`vim.api.nvim_tabpage_get_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_get_var())\n    - [`vim.api.nvim_tabpage_del_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_del_var())\n- Vimの定義済み変数 (`v:`):\n    - [`vim.api.nvim_set_vvar()`](https://neovim.io/doc/user/api.html#nvim_set_vvar())\n    - [`vim.api.nvim_get_vvar()`](https://neovim.io/doc/user/api.html#nvim_get_vvar())\n\nVimの定義済み変数を除いて、削除できます(Vim scriptの`:unlet`と同様です)。\nローカル変数(`l:`)、スクリプト変数(`s:`)、関数の引数(`a:`)はVim script内でのみ意味があるため操作できません。\nLuaには独自のスコープルールがあります。\n\nこれらの変数が不慣れな場合、[`:help internal-variables`](https://neovim.io/doc/user/eval.html#internal-variables)に説明があります。\n\nこれらの関数は対象の変数名と、設定したい値を含む文字列を受け取ります。\n\n```lua\nvim.api.nvim_set_var('some_global_variable', { key1 = 'value', key2 = 300 })\nprint(vim.inspect(vim.api.nvim_get_var('some_global_variable'))) -- { key1 = \"value\", key2 = 300 }\nvim.api.nvim_del_var('some_global_variable')\n```\n\nバッファ、ウィンドウ、タブページなスコープを持つ変数はそれぞれの番号を受け取ります(0を指定した場合は現在のバッファ/ウィンドウ/タブページが使われます。)。:\n\n```lua\nvim.api.nvim_win_set_var(0, 'some_window_variable', 2500)\nvim.api.nvim_tab_set_var(3, 'some_tabpage_variable', 'hello world')\nprint(vim.api.nvim_win_get_var(0, 'some_window_variable')) -- 2500\nprint(vim.api.nvim_buf_get_var(3, 'some_tabpage_variable')) -- 'hello world'\nvim.api.nvim_win_del_var(0, 'some_window_variable')\nvim.api.nvim_buf_del_var(3, 'some_tabpage_variable')\n```\n\n### メタアクセサーを使用する\n\n内部の変数はメタアクセサーを使用し、もっと直感的に操作できます。:\n\n- [`vim.g.{name}`](https://neovim.io/doc/user/lua.html#vim.g): グローバル変数\n- [`vim.b.{name}`](https://neovim.io/doc/user/lua.html#vim.b): バッファ変数\n- [`vim.w.{name}`](https://neovim.io/doc/user/lua.html#vim.w): ウィンドウ変数\n- [`vim.t.{name}`](https://neovim.io/doc/user/lua.html#vim.t): タブ変数\n- [`vim.v.{name}`](https://neovim.io/doc/user/lua.html#vim.v): Vimの定義済み変数\n- [`vim.env.{name}`](https://neovim.io/doc/user/lua.html#vim.env): 環境変数\n\n```lua\nvim.g.some_global_variable = {\n    key1 = 'value',\n    key2 = 300\n}\n\nprint(vim.inspect(vim.g.some_global_variable)) -- { key1 = \"value\", key2 = 300 }\n\n-- 特定のバッファ/ウィンドウ/タブを対象とします(Neovim 0.6+)\nvim.b[2].myvar = 1\n```\n\n一部の変数名には、Luaの識別子に使用できない文字が含まれている場合があります。\nこの構文を使用してこれらの変数を操作できます。: `vim.g['my#variable']`\n\n変数を削除するには単に`nil`を代入します。:\n\n```lua\nvim.g.some_global_variable = nil\n```\n\n参照:\n- [`:help lua-vim-variables`](https://neovim.io/doc/user/lua.html#lua-vim-variables)\n\n#### 警告\n\n\n辞書の1つのキーを追加/更新/削除できません。例えば、次のVim scriptは期待通りに動きません。:\n\n```vim\nlet g:variable = {}\nlua vim.g.variable.key = 'a'\necho g:variable\n\" {}\n```\n\n一時的な変数を使用する回避策があります:\n\n```vim\nlet g:variable = {}\nlua << EOF\nlocal tmp = vim.g.variable\ntmp.key = 'a'\nvim.g.variable = tmp\nEOF\necho g:variable\n\" {'key': 'a'}\n```\n\n既知のissue:\n\n- [Issue #12544](https://github.com/neovim/neovim/issues/12544)\n\n## Vim scriptの関数を呼び出す\n\n### vim.fn.{function}()\n\n`vim.fn`は、Vim script組込みの関数を呼び出せます。\n型はVimとLuaとで変換されます。\n\n```lua\nprint(vim.fn.printf('Hello from %s', 'Lua'))\n\nlocal reversed_list = vim.fn.reverse({ 'a', 'b', 'c' })\nprint(vim.inspect(reversed_list)) -- { \"c\", \"b\", \"a\" }\n\nlocal function print_stdout(chan_id, data, name)\n    print(data[1])\nend\n\nvim.fn.jobstart('ls', { on_stdout = print_stdout })\n```\n\nハッシュ(`#`)はLuaで有効な識別子ではないため、autoload関数は次の構文で呼び出す必要があります。:\n\n```lua\nvim.fn['my#autoload#function']()\n```\n\n`vim.fn`は`vim.call`と同じ動作ですが、よりLuaらしい構文を使用できます。\n\n`vim.api.nvim_call_function`とは、Vim/Luaオブジェクトを自動で変換する点が異なります。:\n`vim.api.nvim_call_function`は浮動小数点数のテーブルを返しLuaのクロージャーを受け入れませんが、`vim.fn`はこれらの型を扱えます。\n\n参照:\n- [`:help vim.fn`](https://neovim.io/doc/user/lua.html#vim.fn)\n\n#### Tips\n\nNeovimにはプラグインに便利な強力な組込み関数を含むライブラリがあります。\nアルファベット順のリストは[`:help vim-function`](https://neovim.io/doc/user/eval.html#vim-function)を参照してください。\n[`:help function-list`](https://neovim.io/doc/user/usr_41.html#function-list)は機能別に分類されたリストです。\n\nNeovimのAPI関数は`vim.api{..}`のように直接使用できます。\n詳細は[`:help api`](https://neovim.io/doc/user/api.html#API)を参照してください。\n\n#### 警告\n\nいくつかのVim関数はbool値の変わりに`1`か`0`を返します。これは、Vim scriptでは`1`は真で`0`は偽になるため問題ありません。\n次のようなことが可能です。:\n\n```vim\nif has('nvim')\n    \" do something...\nendif\n```\n\nしかし、Luaで偽になるのは`false`と`nil`のみで、数値は値に関係なく常に`true`と評価されます。\n明示的に`1`か`0`かをチェックする必要があります。:\n\n```lua\nif vim.fn.has('nvim') == 1 then\n    -- do something...\nend\n```\n\n## マッピングを定義する\n\n### API関数\n\nNeovimはマッピングを設定、取得、削除するためのAPI関数を提供します。:\n\n- グローバルマッピング:\n    - [`vim.api.nvim_set_keymap()`](https://neovim.io/doc/user/api.html#nvim_set_keymap())\n    - [`vim.api.nvim_get_keymap()`](https://neovim.io/doc/user/api.html#nvim_get_keymap())\n    - [`vim.api.nvim_del_keymap()`](https://neovim.io/doc/user/api.html#nvim_del_keymap())\n- バッファローカルマッピング:\n    - [`vim.api.nvim_buf_set_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_set_keymap())\n    - [`vim.api.nvim_buf_get_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_get_keymap())\n    - [`vim.api.nvim_buf_del_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_del_keymap())\n\n`vim.api.nvim_set_keymap()`と`vim.api.nvim_buf_set_keymap()`から始めましょう。\n\n最初の引数には有効にするモードの名前を含む文字列を渡します。:\n\n| String value           | Help page     | Affected modes                           | Vimscript equivalent |\n| ---------------------- | ------------- | ---------------------------------------- | -------------------- |\n| `''` (an empty string) | `mapmode-nvo` | Normal, Visual, Select, Operator-pending | `:map`               |\n| `'n'`                  | `mapmode-n`   | Normal                                   | `:nmap`              |\n| `'v'`                  | `mapmode-v`   | Visual and Select                        | `:vmap`              |\n| `'s'`                  | `mapmode-s`   | Select                                   | `:smap`              |\n| `'x'`                  | `mapmode-x`   | Visual                                   | `:xmap`              |\n| `'o'`                  | `mapmode-o`   | Operator-pending                         | `:omap`              |\n| `'!'`                  | `mapmode-ic`  | Insert and Command-line                  | `:map!`              |\n| `'i'`                  | `mapmode-i`   | Insert                                   | `:imap`              |\n| `'l'`                  | `mapmode-l`   | Insert, Command-line, Lang-Arg           | `:lmap`              |\n| `'c'`                  | `mapmode-c`   | Command-line                             | `:cmap`              |\n| `'t'`                  | `mapmode-t`   | Terminal                                 | `:tmap`              |\n\n2つ目の引数は、左側のマッピングを含む文字列(マッピングで定義されたコマンドを起動するためのキー)です。\n空の文字列は`<Nop>`と同じで、キーを無効にします。\n\n3つ目の引数は、右側のマッピングを含む文字列(実行するコマンド)です。\n\n最後の引数は、[`:help :map-arguments`](https://neovim.io/doc/user/map.html#:map-arguments)で定義されているbool型のオプションのテーブルです(`noremap`を含み、`buffer`を除く)。\nNeovim 0.7.0から、マッピング実行時、右側のマッピングの代わりに `callback` オプションに渡した関数を呼び出せます。\n\nバッファローカルなマッピングは、バッファ番号を引数の最初に受け取ります(`0`を指定した場合、カレントバッファです)。\n\n```lua\nvim.api.nvim_set_keymap('n', '<Leader><Space>', ':set hlsearch!<CR>', { noremap = true, silent = true })\n-- :nnoremap <silent> <Leader><Space> :set hlsearch<CR>\nvim.api.nvim_set_keymap('n', '<Leader>tegf',  [[<Cmd>lua require('telescope.builtin').git_files()<CR>]], { noremap = true, silent = true })\n-- :nnoremap <silent> <Leader>tegf <Cmd>lua require('telescope.builtin').git_files()<CR>\n\nvim.api.nvim_buf_set_keymap(0, '', 'cc', 'line(\".\") == 1 ? \"cc\" : \"ggcc\"', { noremap = true, expr = true })\n-- :noremap <buffer> <expr> cc line('.') == 1 ? 'cc' : 'ggcc'\n\nvim.api.nvim_set_keymap('n', '<Leader>ex', '', {\n    noremap = true,\n    callback = function()\n        print('My example')\n    end,\n    -- Lua関数は便利な文字列表現を持っていないため、 \"desc\" オプションを使用してマッピングの説明を記入できます。\n    desc = 'Prints \"My example\" in the message area',\n})\n```\n\n`vim.api.nvim_get_keymap()`は、モードの省略名(上記の表を参照)を含む文字列を受け取ります。\nそのモードにあるすべてのグローバルマッピングのテーブルを返します。\n\n```lua\nprint(vim.inspect(vim.api.nvim_get_keymap('n')))\n-- :verbose nmap\n```\n\n`vim.api.nvim_buf_get_keymap()`は、最初の引数に追加でバッファ番号を受け取ります(`0`を指定した場合、カレントバッファです)。\n\n```lua\nprint(vim.inspect(vim.api.nvim_buf_get_keymap(0, 'i')))\n-- :verbose imap <buffer>\n```\n\n`vim.api.nvim_del_keymap()`は、モードと左側のマッピングを受け取ります。\n\n```lua\nvim.api.nvim_del_keymap('n', '<Leader><Space>')\n-- :nunmap <Leader><Space>\n```\n\nこの場合でも、`vim.api.nvim_buf_del_keymap()`は最初の引数にバッファ番号を受け取ります。`0`を指定した場合、カレントバッファです。\n\n```lua\nvim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')\n-- :iunmap <buffer> <Tab>\n```\n\n### vim.keymap\n\n:warning: このセクションで説明するAPI関数はNeovim 0.7.0+のみで使用できます。\n\nNeovimはマッピングを設定/削除できる2つの関数を提供します:\n- [`vim.keymap.set()`](https://neovim.io/doc/user/lua.html#vim.keymap.set())\n- [`vim.keymap.del()`](https://neovim.io/doc/user/lua.html#vim.keymap.del())\n\nこれらは、上記のAPI関数に糖類構文を追加したようなものです。\n\n`vim.keymap.set()` は最初の引数として文字列を受け取ります。\nまた、複数のモードのマッピングを1度に定義するため、文字列のテーブルを受け取ることもできます:\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>lua vim.notify(\"Example 1\")<CR>')\nvim.keymap.set({'n', 'c'}, '<Leader>ex2', '<Cmd>lua vim.notify(\"Example 2\")<CR>')\n```\n\n2つ目の引数は左側のマッピングです。\n\n3つ目の引数は右側のマッピングで、文字列かLua関数を受け取れます。\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>')\nvim.keymap.set('n', '<Leader>ex2', function() print(\"Example 2\") end)\nvim.keymap.set('n', '<Leader>pl1', require('plugin').plugin_action)\n-- モジュールの読み込みによる起動コストを避けるため、マッピングを呼び出したときにモジュールの遅延読みこみができるように関数でラップすることができます。:\nvim.keymap.set('n', '<Leader>pl2', function() require('plugin').plugin_action() end)\n```\n\n4つ目の引数(省略可能)はオプションのテーブルで、 `vim.api.nvim_set_keymap()` に渡されるオプションに対応しており、いくつか追加項目があります([`:help vim.keymap.set()`](https://neovim.io/doc/user/lua.html#vim.keymap.set())に一覧があります)。\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>', {buffer = true})\nvim.keymap.set('n', '<Leader>ex2', function() print('Example 2') end, {desc = 'Prints \"Example 2\" to the message area'})\n```\n\n文字列を使用して定義するキーマップとLua関数で定義したキーマップは違います。\n通常の`:nmap <Leader>ex1`のようなキーマップ情報を表示する方法では、\n`Lua function` とだけ表示され有用な情報（関数の内容自体）が表示されません。\nキーマップの動作を説明する`desc`キーを追加するのを推奨します。\nこれはプラグインのマッピングのドキュメント化に特に重要です。\nユーザーはキーマップの使用方法をより簡単に理解できます。\n\nこのAPIが面白いところとして、Vimのマッピングの歴史的な癖をいくつか解消しています。\n- `rhs` が `<Plug>` マッピングである場合以外、デフォルトで `noremap` です。\n  このため、マッピングが再帰的であるかを考える必要はあまりないです。\n\n```lua\nvim.keymap.set('n', '<Leader>test1', '<Cmd>echo \"test\"<CR>')\n-- :nnoremap <Leader>test <Cmd>echo \"test\"<CR>\n\n-- マッピングを再帰的に行ないたい場合は、 `remap` オプションを `true` にします\nvim.keymap.set('n', '>', ']', {remap = true})\n-- :nmap > ]\n\n-- <Plug> マッピングは再帰的でないと機能しませんが、 vim.keymap.set() は自動的に処理します\nvim.keymap.set('n', '<Leader>plug', '<Plug>(plugin)')\n-- :nmap <Leader>plug <Plug>(plugin)\n```\n\n- `expr` マッピングが有効なら、 Lua関数が返す文字列に対して `nvim_replace_termcodes()` が自動的に適用されます:\n\n```lua\nvim.keymap.set('i', '<Tab>', function()\n    return vim.fn.pumvisible == 1 and '<C-N>' or '<Tab>'\nend, {expr = true})\n```\n\n参照:\n- [`:help recursive_mapping`](https://neovim.io/doc/user/map.html#recursive_mapping)\n\n`vim.keymap.del()` も同じように機能しますが、マッピングを削除します:\n\n```lua\nvim.keymap.del('n', '<Leader>ex1')\nvim.keymap.del({'n', 'c'}, '<Leader>ex2', {buffer = true})\n```\n\n## ユーザーコマンドを定義する\n\n:warning: このセクションで説明するAPI関数はNeovim 0.7.0+のみで使用できます。\n\nNeovimはユーザーコマンドを作成するAPI関数を提供します。\n\n- Global user commands:\n    - [`vim.api.nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command())\n    - [`vim.api.nvim_del_user_command()`](https://neovim.io/doc/user/api.html#nvim_del_user_command())\n- Buffer-local user commands:\n    - [`vim.api.nvim_buf_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_buf_create_user_command())\n    - [`vim.api.nvim_buf_del_user_command()`](https://neovim.io/doc/user/api.html#nvim_buf_del_user_command())\n\nまず `vim.api.nvim_create_user_command()` から始めます\n\n最初の引数はコマンドの名前です(名前は大文字で始める必要があります)。\n\n2つめの引数はコマンドが呼びだされたときに実行するコードです。次のどちらかでコードを指定できます:\n\n文字列(この場合、VimScriptとして実行されます)。`:commands` のように、`<q-args>`, `<range>` などのエスケープシーケンスを使用できます。\n```lua\nvim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 })\n-- :command! -nargs=1 Upper echo toupper(<q-args>)\n\nvim.cmd('Upper hello world') -- prints \"HELLO WORLD\"\n```\n\nもしくは、Lua関数。通常のエスケープシーケンスによって提供されるデータを含む、辞書のようなテーブルを受け取ります(利用できるキーのリストは[`:help nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command())で確認できます)。\n```lua\nvim.api.nvim_create_user_command(\n    'Upper',\n    function(opts)\n        print(string.upper(opts.args))\n    end,\n    { nargs = 1 }\n)\n```\n\n3つめの引数はコマンドの属性をテーブルとして渡せます([`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)を参照)。`vim.api.nvim_buf_create_user_command()`を使用すればバッファローカルなユーザーコマンドを定義できるため、`-buffer`は有効な属性ではありません。\n\n追加された2つの属性:\n- `desc`はLuaのコールバックとして定義されたコマンドに対して`:command {cmd}`を実行したときの表示内容を制御できます。\n  キーマップと同様、Lua関数として定義するコマンドには `desc`キーを追加するのを推奨します。\n- `force`は`:command!`を呼び出すのと同じで、同じ名前のユーザーコマンドが既に存在する場合、そのコマンドを置き換えます。Vimscriptとは異なり、デフォルトでtrueです。\n\n`-complete`属性は[`:help :command-complete`](https://neovim.io/doc/user/map.html#:command-complete)に記載されている属性に加え、Lua関数を取ることができます。\n\n```lua\nvim.api.nvim_create_user_command('Upper', function() end, {\n    nargs = 1,\n    complete = function(ArgLead, CmdLine, CursorPos)\n        -- return completion candidates as a list-like table\n        return { 'foo', 'bar', 'baz' }\n    end,\n})\n```\n\nバッファローカルなユーザーコマンドも第1引数にバッファ番号を受け取ります。現在のバッファ用のコマンドを定義することができる`-buffer`より、これは便利です。\n\n```lua\nvim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})\n```\n\n`vim.api.nvim_del_user_command()` はコマンド名を受け取ります。\n\n```lua\nvim.api.nvim_del_user_command('Upper')\n-- :delcommand Upper\n```\n\nここでも、`vim.api.nvim_buf_del_user_command()`はバッファ番号を第1引数として受け取り、`0`は現在のバッファを表します。\n\n```lua\nvim.api.nvim_buf_del_user_command(4, 'Upper')\n```\n\n参照:\n- [`:help nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command())\n- [`:help 40.2`](https://neovim.io/doc/user/usr_40.html#40.2)\n- [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)\n\n#### 警告\n\n`-complete=custom`属性は自動的に補完候補をフィルタリングし、ワイルドカード([`:help wildcard`](https://neovim.io/doc/user/editing.html#wildcard))をサポートする機能を組み込みます:\n\n```vim\nfunction! s:completion_function(ArgLead, CmdLine, CursorPos) abort\n    return join([\n        \\ 'strawberry',\n        \\ 'star',\n        \\ 'stellar',\n        \\ ], \"\\n\")\nendfunction\n\ncommand! -nargs=1 -complete=custom,s:completion_function Test echo <q-args>\n\" `:Test st[ae]<Tab>` と入力すると \"star\" と \"stellar\" を返します\n```\n\n`complete` にLua関数を渡すと、ユーザーにフィルタ方法を任せる`customlist`のような動作をします。\n\n```lua\nvim.api.nvim_create_user_command('Test', function() end, {\n    nargs = 1,\n    complete = function(ArgLead, CmdLine, CursorPos)\n        return {\n            'strawberry',\n            'star',\n            'stellar',\n        }\n    end,\n})\n\n-- 候補リストをフィルタしてないので `:Test z<Tab>` と入力すると全ての補完候補を返します\n```\n\n## オートコマンドを定義する\n\n(この章は現在作成中です)\n\nNeovim 0.7.0はオートコマンド用のAPI関数を持っています。詳細は `:help api-autocmd` を参照してください。\n\n- [Pull request #14661](https://github.com/neovim/neovim/pull/14661) (lua: autocmds take 2)\n\n## ハイライトを定義する\n\n(この章は現在作成中です)\n\nNeovim 0.7.0はハイライトグループ用のAPI関数を持っています。\n\n参照:\n- [`:help nvim_set_hl()`](https://neovim.io/doc/user/api.html#nvim_set_hl())\n- [`:help nvim_get_hl_by_id()`](https://neovim.io/doc/user/api.html#nvim_get_hl_by_id())\n- [`:help nvim_get_hl_by_name()`](https://neovim.io/doc/user/api.html#nvim_get_hl_by_name())\n\n## 一般的なTipsと推奨\n\n### キャッシュされたモジュールのリロード\n\nLuaでは、`require()`関数がモジュールをキャッシュします。\nこれはパフォーマンスには良いですが、後から`require()`を呼んでもモジュールは更新されないため少し面倒です。\n\n特定のモジュールのキャッシュを更新する場合、`package.loaded`グローバルテーブルを変更する必要があります。:\n\n```lua\npackage.loaded['modname'] = nil\nrequire('modname') -- 新しい'modname'モジュールを読み込みます\n```\n\n[nvim-lua/plenary.nvim](https://github.com/nvim-lua/plenary.nvim)には、これを行う[関数](https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/reload.lua)があります。\n\n### Luaの文字列をパディングしないでください!\n\n二重括弧の文字列を使用するとき、パディングの誘惑に負けないでください! スペースを無視するときは問題ないですが、スペースが重要な意味を持つときはデバックが困難な問題の原因になる可能性があります。:\n\n```lua\nvim.api.nvim_set_keymap('n', '<Leader>f', [[ <Cmd>call foo()<CR> ]], {noremap = true})\n```\n\n上記の例では、`<Leader>f`は`<Cmd>call foo()<CR>`ではなく`<Space><Cmd>call foo()<CR><Space>`にマッピングされます。\n\n### Vim script <--> Lua 型変換の注意\n\n#### 変数を変換するとコピーが作られます:\n\nVimからLua、LuaからVimのオブジェクトの参照を直接操作できません。\n例えば、Vim scriptの`map()`は変数をその場で変更します(破壊的)。\n\n```vim\nlet s:list = [1, 2, 3]\nlet s:newlist = map(s:list, {_, v -> v * 2})\n\necho s:list\n\" [2, 4, 6]\necho s:newlist\n\" [2, 4, 6]\necho s:list is# s:newlist\n\" 1\n```\n\nLuaからこの関数を使用すると、代りにコピーが作られます\n\n```lua\nlocal tbl = {1, 2, 3}\nlocal newtbl = vim.fn.map(tbl, function(_, v) return v * 2 end)\n\nprint(vim.inspect(tbl)) -- { 1, 2, 3 }\nprint(vim.inspect(newtbl)) -- { 2, 4, 6 }\nprint(tbl == newtbl) -- false\n```\n\n#### 変換を常にできるとは限りません\n\nこれは主に関数とテーブルに影響します。\n\nLuaのリストと辞書が混在するテーブルは変換できません。\n\n```lua\nprint(vim.fn.count({1, 1, number = 1}, 1))\n-- E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys\n```\n\nLuaで`vim.fn`を使用してVim関数を呼べますが、それらの参照を保持できません。\nそれは不測の動作の原因になります。:\n\n```lua\nlocal FugitiveHead = vim.fn.funcref('FugitiveHead')\nprint(FugitiveHead) -- vim.NIL\n\nvim.cmd(\"let g:test_dict = {'test_lambda': {-> 1}}\")\nprint(vim.g.test_dict.test_lambda) -- nil\nprint(vim.inspect(vim.g.test_dict)) -- {}\n```\n\nLuaの関数をVimの関数に渡せますが、Vimの変数に格納できません。\n(Neovim 0.7.0+で修正されて、格納できるようになりました。)\n\n```lua\n-- This works:\nvim.fn.jobstart({'ls'}, {\n    on_stdout = function(chan_id, data, name)\n        print(vim.inspect(data))\n    end\n})\n\n-- This doesn't:\nvim.g.test_dict = {test_lambda = function() return 1 end} -- Error: Cannot convert given lua type\n```\n\nただし、Vim scriptから`luaeval()`を使用して同じことをすると**動作します**。:\n\n```vim\nlet g:test_dict = {'test_lambda': luaeval('function() return 1 end')}\necho g:test_dict\n\" {'test_lambda': function('<lambda>4714')}\n```\n\n#### Vim booleans\nVim scriptの一般的なパターンではbool値の代わりに`1`と`0`を使用します。\n実際、Vimにはバージョン7.4.1154まで区別されたbool型がありませんでした。\n\nLuaのbool値は数値ではなく、Vim scriptの実際のbool値に変換されます。:\n\n```vim\nlua vim.g.lua_true = true\necho g:lua_true\n\" v:true\nlua vim.g.lua_false = false\necho g:lua_false\n\" v:false\n```\n\n### リンターと言語サーバーの設定\n\nLuaのプロジェクトでリンターや言語サーバーを使用して、診断と自動補完を利用している場合、Neovim固有の設定が必要になる場合があります。人気のあるツールの推奨設定は次のとおりです。:\n\n#### luacheck\n\n次の設定を `~/.luacheckrc` (もしくは `$XDG_CONFIG_HOME/luacheck/.luacheckrc`)に配置すれば、[luacheck](https://github.com/mpeterv/luacheck/)でvimモジュールを認識できます。:\n\n\n```lua\nglobals = {\n    \"vim\",\n}\n```\n\n言語サーバーの[Alloyed/lua-lsp](https://github.com/Alloyed/lua-lsp/)は `luacheck` を使用してリンティングを提供し、同じファイルを読み込みます。\n\n`luacheck` の設定方法の詳細は[ドキュメント](https://luacheck.readthedocs.io/en/stable/config.html)を参照してください。\n\n#### sumneko/lua-language-server\n\n[nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/)リポジトリに[sumneko/lua-language-serverの設定方法](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua)があります（例は組込みのLSPクライアントを使っていますが、他のLSPクライアントでも同じ設定である必要があります）。\n\n[sumneko/lua-language-server](https://github.com/sumneko/lua-language-server/)の設定方法の詳細は[\"Setting\"](https://github.com/sumneko/lua-language-server/wiki/Setting)を見てください。\n\n#### coc.nvim\n\n[coc.nvim](https://github.com/neoclide/coc.nvim/)の補完ソースである[rafcamlet/coc-nvim-lua](https://github.com/rafcamlet/coc-nvim-lua/)はNeovim stdlibの項目を提供しています。\n\n### Luaコードのデバッグ\n\n別のNeovimインスタンスで実行しているLuaコードを[jbyuki/one-small-step-for-vimkind](https://github.com/jbyuki/one-small-step-for-vimkind)でデバッグできます。\n\nこのプラグインは[Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/)を使用しています。\nデバッグアダプターに接続するには、[mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap/)や[puremourning/vimspector](https://github.com/puremourning/vimspector/)のようなDAPクライアントが必要です。\n\n### Luaマッピング/コマンド/オートコマンドのデバッグ\n\nマッピング/コマンド/オートコマンドが定義されている位置を `:verbose` コマンドで確認できます:\n\n```vim\n:verbose map m\n```\n\n```text\nn  m_          * <Cmd>echo 'example'<CR>\n        Last set from ~/.config/nvim/init.vim line 26\n```\n\nデフォルトでは、Luaのパフォーマンス上の理由でこの機能は無効です。\nNeovim起動時にverboseのレベルが0より上なら、この機能を有効にできます:\n\n```sh\nnvim -V1\n```\n\n参照:\n- [`:help 'verbose'`](https://neovim.io/doc/user/options.html#'verbose')\n- [`:help -V`](https://neovim.io/doc/user/starting.html#-V)\n- [neovim/neovim#15079](https://github.com/neovim/neovim/pull/15079)\n\n### Luaコードのテスト\n\n- [plenary.nvim: test harness](https://github.com/nvim-lua/plenary.nvim/#plenarytest_harness)\n- [notomo/vusted](https://github.com/notomo/vusted)\n\n### Luarocksパッケージを使用する\n\n[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim)はLuarocksパッケージをサポートしています。\n使い方は[README](https://github.com/wbthomason/packer.nvim/#luarocks-support)にあります。\n\n## その他\n\n### vim.loop\n\n`vim.loop`はLibUV APIを公開するモジュールです。いくつかのリソース:\n\n- [Official documentation for LibUV](https://docs.libuv.org/en/v1.x/)\n- [Luv documentation](https://github.com/luvit/luv/blob/master/docs.md)\n- [teukka.tech - Using LibUV in Neovim](https://teukka.tech/posts/2020-01-07-vimloop/)\n\n参照:\n- [`:help vim.loop`](https://neovim.io/doc/user/lua.html#vim.loop)\n\n### vim.lsp\n\n`vim.lsp`は組込みのLSPクライアントを操作するためのモジュールです。\n[neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/)は有名なLanguage Serverの設定集です。\n\nクライアントの動作は\"lsp-handlers\"を使用して設定できます。詳細はこちら:\n- [`:help lsp-handler`](https://neovim.io/doc/user/lsp.html#lsp-handler)\n- [neovim/neovim#12655](https://github.com/neovim/neovim/pull/12655)\n- [How to migrate from diagnostic-nvim](https://github.com/nvim-lua/diagnostic-nvim/issues/73#issue-737897078)\n\n\nLSPクライアントを利用した[プラグイン](https://github.com/rockerBOO/awesome-neovim#lsp)も見たいかもしれません。\n\n参照:\n- [`:help lsp`](https://neovim.io/doc/user/lsp.html#LSP)\n\n### vim.treesitter\n\n`vim.treesitter`はNeovim内の[Tree-sitter](https://tree-sitter.github.io/tree-sitter/)ライブラリを操作するためのモジュールです。\nTree-sitterについてもっと知りたいなら、この[プレゼン (38:37)](https://www.youtube.com/watch?v=Jes3bD6P0To)に興味があるかもしれません。\n\n[nvim-treesitter](https://github.com/nvim-treesitter/)オリジネーションは、ライブラリを利用して様々なプラグインをホストしています。\n\n参照:\n- [`:help lua-treesitter`](https://neovim.io/doc/user/treesitter.html#lua-treesitter)\n\n### トランスパイラ\n\nLuaを使用する利点の1つは実際にLuaを書く必要がないことです！利用できるトランスパイラはたくさんあります。\n\n- [Moonscript](https://moonscript.org/)\n\nおそらく、最も知られているLuaのトランスパイラです。クラス、リスト内包表記、関数リテラルなどの便利な機能を多数追加します。\n[svermeulen/nvim-moonmaker](https://github.com/svermeulen/nvim-moonmaker)はNeovimのプラグインと設定をMoonscriptで直接書けるようにします。\n\n- [Fennel](https://fennel-lang.org/)\n\nlispをLuaにコンパイルします。[Olical/aniseed](https://github.com/Olical/aniseed)または、[Hotpot](https://github.com/rktjmp/hotpot.nvim)を使用するとNeovimのプラグインと設定を書くことができます。\nさらに、[Olical/conjure](https://github.com/Olical/conjure)は対話的な開発環境を提供します(他の言語の中で)。\n\n- [Teal](https://github.com/teal-language/tl)\n\nTealの名前の由来はTL(typed lua)の発音からです。\nまさにその通りで、強力な型をLuaに追加し、それ以外は標準のLuaの構文に近づけています。\n[nvim-teal-maker](https://github.com/svermeulen/nvim-teal-maker)プラグインを使用して、\nTealでNeovimプラグインや設定ファイルを書けます。\n\nその他の興味深いプロジェクト:\n- [TypeScriptToLua/TypeScriptToLua](https://github.com/TypeScriptToLua/TypeScriptToLua)\n- [Haxe](https://haxe.org/)\n- [SwadicalRag/wasm2lua](https://github.com/SwadicalRag/wasm2lua)\n- [hengestone/lua-languages](https://github.com/hengestone/lua-languages)\n"
  },
  {
    "path": "README.md",
    "content": ":arrow_upper_left: (Feeling lost? Use the GitHub TOC!)\n\n**:warning: :warning: :warning: A more up-to-date version of this guide is available in the Neovim documentation, see [`:help lua-guide`](https://neovim.io/doc/user/lua-guide.html#lua-guide) :warning: :warning: :warning:**\n\n---\n\n# Getting started using Lua in Neovim\n\n## Translations\n\n- [Chinese version](https://github.com/glepnir/nvim-lua-guide-zh)\n- [Spanish version](https://github.com/RicardoRien/nvim-lua-guide/blob/master/README.esp.md)\n- [Portuguese version](https://github.com/npxbr/nvim-lua-guide/blob/master/README.pt-br.md)\n- [Japanese version](https://github.com/willelz/nvim-lua-guide-ja/blob/master/README.ja.md)\n- [Russian version](https://github.com/kuator/nvim-lua-guide-ru)\n- [Ukrainian version](https://github.com/famiclone/nvim-lua-guide-ua)\n- [Korean version](https://github.com/krapjost/nvim-lua-guide-kr)\n\n## Introduction\n\nThe [integration of Lua](https://www.youtube.com/watch?v=IP3J56sKtn0) as a [first-class language inside Neovim](https://github.com/neovim/neovim/wiki/FAQ#why-embed-lua-instead-of-x) is shaping up to be one of its killer features.\nHowever, the amount of teaching material for learning how to write plugins in Lua is not as large as what you would find for writing them in Vimscript. This is an attempt at providing some basic information to get people started.\n\nThis guide assumes you are using at least version 0.5 of Neovim.\n\n### Learning Lua\n\nIf you are not already familiar with the language, there are plenty of resources to get started:\n\n- The [Learn X in Y minutes page about Lua](https://learnxinyminutes.com/docs/lua/) should give you a quick overview of the basics\n- [This guide](https://github.com/medwatt/Notes/blob/main/Lua/Lua_Quick_Guide.ipynb) is also a good resource for getting started quickly\n- If videos are more to your liking, Derek Banas has a [1-hour tutorial on the language](https://www.youtube.com/watch?v=iMacxZQMPXs)\n- Want something a little more interactive with runnable examples? Try [the LuaScript tutorial](https://www.luascript.dev/learn)\n- The [lua-users wiki](http://lua-users.org/wiki/LuaDirectory) is full of useful information on all kinds of Lua-related topics\n- The [official reference manual for Lua](https://www.lua.org/manual/5.1/) should give you the most comprehensive tour of the language (exists as a Vimdoc plugin if you want to read it from the comfort of your editor: [milisims/nvim-luaref](https://github.com/milisims/nvim-luaref))\n\nIt should also be noted that Lua is a very clean and simple language. It is easy to learn, especially if you have experience with similar scripting languages like JavaScript. You may already know more Lua than you realise!\n\nNote: the version of Lua that Neovim embeds is [LuaJIT](https://staff.fnwi.uva.nl/h.vandermeer/docs/lua/luajit/luajit_intro.html) 2.1.0, which maintains compatibility with Lua 5.1.\n\n### Existing tutorials for writing Lua in Neovim\n\nA few tutorials have already been written to help people write plugins in Lua. Some of them helped quite a bit when writing this guide. Many thanks to their authors.\n\n- [teukka.tech - From init.vim to init.lua](https://teukka.tech/luanvim.html)\n- [dev.to - How to write neovim plugins in Lua](https://dev.to/2nit/how-to-write-neovim-plugins-in-lua-5cca)\n- [dev.to - How to make UI for neovim plugins in Lua](https://dev.to/2nit/how-to-make-ui-for-neovim-plugins-in-lua-3b6e)\n- [ms-jpq - Neovim Async Tutorial](https://github.com/ms-jpq/neovim-async-tutorial)\n- [oroques.dev - Neovim 0.5 features and the switch to init.lua](https://oroques.dev/notes/neovim-init/)\n- [Building A Vim Statusline from Scratch - jdhao's blog](https://jdhao.github.io/2019/11/03/vim_custom_statusline/)\n- [Configuring Neovim using Lua](https://icyphox.sh/blog/nvim-lua/)\n- [Devlog | Everything you need to know to configure neovim using lua](https://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/)\n\n### Companion plugins\n\n- [Vimpeccable](https://github.com/svermeulen/vimpeccable) - Plugin to help write your .vimrc in Lua\n- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) - All the lua functions I don't want to write twice\n- [popup.nvim](https://github.com/nvim-lua/popup.nvim) - An implementation of the Popup API from vim in Neovim\n- [nvim_utils](https://github.com/norcalli/nvim_utils)\n- [nvim-luadev](https://github.com/bfredl/nvim-luadev) - REPL/debug console for nvim lua plugins\n- [nvim-luapad](https://github.com/rafcamlet/nvim-luapad) - Interactive real time neovim scratchpad for embedded lua engine\n- [nlua.nvim](https://github.com/tjdevries/nlua.nvim) - Lua Development for Neovim\n- [BetterLua.vim](https://github.com/euclidianAce/BetterLua.vim) - Better Lua syntax highlighting in Vim/NeoVim\n\n## Where to put Lua files\n\n### init.lua\n\nNeovim supports loading an `init.lua` file for configuration instead of the usual `init.vim`.\n\nNote: `init.lua` is of course _completely_ optional. Support for `init.vim` is not going away and is still a valid option for configuration. Do keep in mind that some features are not 100% exposed to Lua yet.\n\nSee also:\n- [`:help config`](https://neovim.io/doc/user/starting.html#config)\n\n### Modules\n\nLua modules are found inside a `lua/` folder in your `'runtimepath'` (for most users, this will mean `~/.config/nvim/lua` on \\*nix systems and `~/AppData/Local/nvim/lua` on Windows). You can `require()` files in this folder as Lua modules.\n\nLet's take the following folder structure as an example:\n\n```text\n📂 ~/.config/nvim\n├── 📁 after\n├── 📁 ftplugin\n├── 📂 lua\n│  ├── 🌑 myluamodule.lua\n│  └── 📂 other_modules\n│     ├── 🌑 anothermodule.lua\n│     └── 🌑 init.lua\n├── 📁 pack\n├── 📁 plugin\n├── 📁 syntax\n└── 🇻 init.vim\n```\n\nThe following Lua code will load `myluamodule.lua`:\n\n```lua\nrequire('myluamodule')\n```\n\nNotice the absence of a `.lua` extension.\n\nSimilarly, loading `other_modules/anothermodule.lua` is done like so:\n\n```lua\nrequire('other_modules.anothermodule')\n-- or\nrequire('other_modules/anothermodule')\n```\n\nPath separators are denoted by either a dot `.` or a slash `/`.\n\nA folder containing an `init.lua` file can be required directly, without having to specify the name of the file.\n\n```lua\nrequire('other_modules') -- loads other_modules/init.lua\n```\n\nRequiring a nonexistent module or a module which contains syntax errors aborts the currently executing script.\n`pcall()` may be used to prevent errors.\n\n```lua\nlocal ok, _ = pcall(require, 'module_with_error')\nif not ok then\n  -- not loaded\nend\n```\n\nSee also:\n- [`:help lua-require`](https://neovim.io/doc/user/lua.html#lua-require)\n\n#### Tips\n\nSeveral Lua plugins might have identical filenames in their `lua/` folder. This could lead to namespace clashes.\n\nIf two different plugins have a `lua/main.lua` file, then doing `require('main')` is ambiguous: which file do we want to source?\n\nIt might be a good idea to namespace your config or your plugin with a top-level folder, like so: `lua/plugin_name/main.lua`\n\n### Runtime files\n\nMuch like Vimscript files, Lua files can be loaded automatically from special folders in your `runtimepath`. Currently, the following folders are supported:\n\n- `colors/`\n- `compiler/`\n- `ftplugin/`\n- `ftdetect/`\n- `indent/`\n- `plugin/`\n- `syntax/`\n\nNote: in a runtime directory, all `*.vim` files are sourced before `*.lua` files.\n\nSee also:\n- [`:help 'runtimepath'`](https://neovim.io/doc/user/options.html#'runtimepath')\n- [`:help load-plugins`](https://neovim.io/doc/user/starting.html#load-plugins)\n\n#### Tips\n\nSince runtime files aren't based on the Lua module system, two plugins can have a `plugin/main.lua` file without it being an issue.\n\n## Using Lua from Vimscript\n\n### :lua\n\nThis command executes a chunk of Lua code.\n\n```vim\n:lua require('myluamodule')\n```\n\nMulti-line scripts are possible using heredoc syntax:\n\n```vim\necho \"Here's a bigger chunk of Lua code\"\n\nlua << EOF\nlocal mod = require('mymodule')\nlocal tbl = {1, 2, 3}\n\nfor k, v in ipairs(tbl) do\n    mod.method(v)\nend\n\nprint(tbl)\nEOF\n```\n\nNote: each `:lua` command has its own scope and variables declared with the `local` keyword are not accessible outside of the command. This won't work:\n\n```vim\n:lua local foo = 1\n:lua print(foo)\n\" prints 'nil' instead of '1'\n```\n\nNote 2: the `print()` function in Lua behaves similarly to the `:echomsg` command. Its output is saved in the message-history and can be suppressed by the `:silent` command.\n\nSee also:\n\n- [`:help :lua`](https://neovim.io/doc/user/lua.html#Lua)\n- [`:help :lua-heredoc`](https://neovim.io/doc/user/lua.html#:lua-heredoc)\n\n### :luado\n\nThis command executes a chunk of Lua code that acts on a range of lines in the current buffer. If no range is specified, the whole buffer is used instead. Whatever string is `return`ed from the chunk is used to determine what each line should be replaced with.\n\nThe following command would replace every line in the current buffer with the text `hello world`:\n\n```vim\n:luado return 'hello world'\n```\n\nTwo implicit `line` and `linenr` variables are also provided. `line` is the text of the line being iterated upon whereas `linenr` is its number. The following command would make every line whose number is divisible by 2 uppercase:\n\n```vim\n:luado if linenr % 2 == 0 then return line:upper() end\n```\n\nSee also:\n\n- [`:help :luado`](https://neovim.io/doc/user/lua.html#:luado)\n\n### Sourcing Lua files\n\nNeovim provides 3 Ex commands to source Lua files\n\n- `:luafile`\n- `:source`\n- `:runtime`\n\n`:luafile` and `:source` are very similar:\n\n```vim\n:luafile ~/foo/bar/baz/myluafile.lua\n:luafile %\n:source ~/foo/bar/baz/myluafile.lua\n:source %\n```\n\n`:source` also supports ranges, which can be useful to only execute part of a script:\n\n```vim\n:1,10source\n```\n\n`:runtime` is a little different: it uses the `'runtimepath'` option to determine which files to source. See [`:help :runtime`](https://neovim.io/doc/user/repeat.html#:runtime) for more details.\n\nSee also:\n\n- [`:help :luafile`](https://neovim.io/doc/user/lua.html#:luafile)\n- [`:help :source`](https://neovim.io/doc/user/repeat.html#:source)\n- [`:help :runtime`](https://neovim.io/doc/user/repeat.html#:runtime)\n\n#### Sourcing a lua file vs calling require():\n\nYou might be wondering what the difference between calling the `require()` function and sourcing a Lua file is and whether you should prefer one way over the other. They have different use cases:\n\n- `require()`:\n    - is a built-in Lua function. It allows you to take advantage of Lua's module system\n    - searches for modules in `lua/` folders in your `'runtimepath'`\n    - keeps track of what modules have been loaded and prevents a script from being parsed and executed a second time. If you change the file containing the code for a module and try to `require()` it a second time while Neovim is running, the module will not actually update\n- `:luafile`, `:source` and `:runtime`:\n    - are Ex commands. They do not support modules\n    - execute the contents of a script regardless of whether it has been executed before\n    - `:luafile` and `:source` take a path that is either absolute or relative to the working directory of the current window\n    - `:runtime` uses the `'runtimepath'` option to find files\n\nFiles sourced via `:source`, `:runtime` or automatically from runtime directories will also show up in `:scriptnames` and `--startuptime`\n\n### luaeval()\n\nThis built-in Vimscript function evaluates a Lua expression string and returns its value. Lua data types are automatically converted to Vimscript types (and vice versa).\n\n```vim\n\" You can store the result in a variable\nlet variable = luaeval('1 + 1')\necho variable\n\" 2\nlet concat = luaeval('\"Lua\"..\" is \"..\"awesome\"')\necho concat\n\" 'Lua is awesome'\n\n\" List-like tables are converted to Vim lists\nlet list = luaeval('{1, 2, 3, 4}')\necho list[0]\n\" 1\necho list[1]\n\" 2\n\" Note that unlike Lua tables, Vim lists are 0-indexed\n\n\" Dict-like tables are converted to Vim dictionaries\nlet dict = luaeval('{foo = \"bar\", baz = \"qux\"}')\necho dict.foo\n\" 'bar'\n\n\" Same thing for booleans and nil\necho luaeval('true')\n\" v:true\necho luaeval('nil')\n\" v:null\n\n\" You can create Vimscript aliases for Lua functions\nlet LuaMathPow = luaeval('math.pow')\necho LuaMathPow(2, 2)\n\" 4\nlet LuaModuleFunction = luaeval('require(\"mymodule\").myfunction')\ncall LuaModuleFunction()\n\n\" It is also possible to pass Lua functions as values to Vim functions\nlua X = function(k, v) return string.format(\"%s:%s\", k, v) end\necho map([1, 2, 3], luaeval(\"X\"))\n```\n\n`luaeval()` takes an optional second argument that allows you to pass data to the expression. You can then access that data from Lua using the magic global `_A`:\n\n```vim\necho luaeval('_A[1] + _A[2]', [1, 1])\n\" 2\n\necho luaeval('string.format(\"Lua is %s\", _A)', 'awesome')\n\" 'Lua is awesome'\n```\n\nSee also:\n- [`:help luaeval()`](https://neovim.io/doc/user/lua.html#luaeval())\n\n### v:lua\n\nThis global Vim variable allows you to call Lua functions in the global namespace ([`_G`](https://www.lua.org/manual/5.1/manual.html#pdf-_G)) directly from Vimscript. Again, Vim data types are converted to Lua types and vice versa.\n\n```vim\ncall v:lua.print('Hello from Lua!')\n\" 'Hello from Lua!'\n\nlet scream = v:lua.string.rep('A', 10)\necho scream\n\" 'AAAAAAAAAA'\n\n\" How about a nice statusline?\nlua << EOF\nfunction _G.statusline()\n    local filepath = '%f'\n    local align_section = '%='\n    local percentage_through_file = '%p%%'\n    return string.format(\n        '%s%s%s',\n        filepath,\n        align_section,\n        percentage_through_file\n    )\nend\nEOF\n\nset statusline=%!v:lua.statusline()\n\n\" Also works in expression mappings\nlua << EOF\nfunction _G.check_back_space()\n    local col = vim.api.nvim_win_get_cursor(0)[2]\n    return (col == 0 or vim.api.nvim_get_current_line():sub(col, col):match('%s')) and true\nend\nEOF\n\ninoremap <silent> <expr> <Tab>\n    \\ pumvisible() ? \"\\<C-N>\" :\n    \\ v:lua.check_back_space() ? \"\\<Tab>\" :\n    \\ completion#trigger_completion()\n\n\" Call a function from a Lua module by using single quotes and omitting parentheses:\ncall v:lua.require'module'.foo()\n```\n\nSee also:\n- [`:help v:lua`](https://neovim.io/doc/user/eval.html#v:lua)\n- [`:help v:lua-call`](https://neovim.io/doc/user/lua.html#v:lua-call)\n\n#### Caveats\n\nThis variable can only be used to call functions. The following will always throw an error:\n\n```vim\n\" Aliasing functions doesn't work\nlet LuaPrint = v:lua.print\n\n\" Accessing dictionaries doesn't work\necho v:lua.some_global_dict['key']\n\n\" Using a function as a value doesn't work\necho map([1, 2, 3], v:lua.global_callback)\n```\n\n### Tips\n\nYou can get Lua syntax highlighting inside .vim files by putting `let g:vimsyn_embed = 'l'` in your configuration file. See [`:help g:vimsyn_embed`](https://neovim.io/doc/user/syntax.html#g:vimsyn_embed) for more on this option.\n\n## The vim namespace\n\nNeovim exposes a global `vim` variable which serves as an entry point to interact with its APIs from Lua. It provides users with an extended \"standard library\" of functions as well as various sub-modules.\n\nSome notable functions and modules include:\n\n- `vim.inspect`: transform Lua objects into human-readable strings (useful for inspecting tables)\n- `vim.regex`: use Vim regexes from Lua\n- `vim.api`: module that exposes API functions (the same API used by remote plugins)\n- `vim.ui`: overridable UI functions that can be leveraged by plugins\n- `vim.loop`: module that exposes the functionality of Neovim's event-loop (using LibUV)\n- `vim.lsp`: module that controls the built-in LSP client\n- `vim.treesitter`: module that exposes the functionality of the tree-sitter library\n\nThis list is by no means comprehensive. If you wish to know more about what's made available by the `vim` variable, [`:help lua-stdlib`](https://neovim.io/doc/user/lua.html#lua-stdlib) and [`:help lua-vim`](https://neovim.io/doc/user/lua.html#lua-vim) are the way to go. Alternatively, you can do `:lua print(vim.inspect(vim))` to get a list of every module. API functions are documented under [`:help api-global`](https://neovim.io/doc/user/api.html#api-global).\n\n#### Tips\n\nWriting `print(vim.inspect(x))` every time you want to inspect the contents of an object can get pretty tedious. It might be worthwhile to have a global wrapper function somewhere in your configuration (in Neovim 0.7.0+, this function is built-in, see [`:help vim.pretty_print()`](https://neovim.io/doc/user/lua.html#vim.pretty_print())):\n\n```lua\nfunction _G.put(...)\n  local objects = {}\n  for i = 1, select('#', ...) do\n    local v = select(i, ...)\n    table.insert(objects, vim.inspect(v))\n  end\n\n  print(table.concat(objects, '\\n'))\n  return ...\nend\n```\n\nYou can then inspect the contents of an object very quickly in your code or from the command-line:\n\n```lua\nput({1, 2, 3})\n```\n\n```vim\n:lua put(vim.loop)\n```\n\nAlternatively, you can use the `:lua` command to pretty-print a Lua expression by prefixing it with `=` (Neovim 0.7+ only):\n```vim\n:lua =vim.loop\n```\n\nAdditionally, you may find that built-in Lua functions are sometimes lacking compared to what you would find in other languages (for example `os.clock()` only returns a value in seconds, not milliseconds). Be sure to look at the Neovim stdlib (and `vim.fn`, more on that later), it probably has what you're looking for.\n\n## Using Vimscript from Lua\n\n### vim.api.nvim_eval()\n\nThis function evaluates a Vimscript expression string and returns its value. Vimscript data types are automatically converted to Lua types (and vice versa).\n\nIt is the Lua equivalent of the `luaeval()` function in Vimscript\n\n```lua\n-- Data types are converted correctly\nprint(vim.api.nvim_eval('1 + 1')) -- 2\nprint(vim.inspect(vim.api.nvim_eval('[1, 2, 3]'))) -- { 1, 2, 3 }\nprint(vim.inspect(vim.api.nvim_eval('{\"foo\": \"bar\", \"baz\": \"qux\"}'))) -- { baz = \"qux\", foo = \"bar\" }\nprint(vim.api.nvim_eval('v:true')) -- true\nprint(vim.api.nvim_eval('v:null')) -- nil\n```\n\n#### Caveats\n\nUnlike `luaeval()`, `vim.api.nvim_eval()` does not provide an implicit `_A` variable to pass data to the expression.\n\n### vim.api.nvim_exec()\n\nThis function evaluates a chunk of Vimscript code. It takes in a string containing the source code to execute and a boolean to determine whether the output of the code should be returned by the function (you can then store the output in a variable, for example).\n\n```lua\nlocal result = vim.api.nvim_exec(\n[[\nlet s:mytext = 'hello world'\n\nfunction! s:MyFunction(text)\n    echo a:text\nendfunction\n\ncall s:MyFunction(s:mytext)\n]],\ntrue)\n\nprint(result) -- 'hello world'\n```\n\n#### Caveats\n\n`nvim_exec` does not support script-local variables (`s:`) prior to Neovim 0.6.0\n\n### vim.api.nvim_command()\n\nThis function executes an ex command. It takes in a string containing the command to execute.\n\n```lua\nvim.api.nvim_command('new')\nvim.api.nvim_command('wincmd H')\nvim.api.nvim_command('set nonumber')\nvim.api.nvim_command('%s/foo/bar/g')\n```\n\n### vim.cmd()\n\nAlias for `vim.api.nvim_exec()`. Only the command argument is needed, `output` is always set to `false`.\n\n```lua\nvim.cmd('buffers')\nvim.cmd([[\nlet g:multiline_list = [\n            \\ 1,\n            \\ 2,\n            \\ 3,\n            \\ ]\n\necho g:multiline_list\n]])\n```\n\n#### Tips\n\nSince you have to pass strings to these functions, you often end up having to escape backslashes:\n\n```lua\nvim.cmd('%s/\\\\Vfoo/bar/g')\n```\n\nDouble bracketed strings are easier to use as they do not require escaping characters:\n\n```lua\nvim.cmd([[%s/\\Vfoo/bar/g]])\n```\n\n### vim.api.nvim_replace_termcodes()\n\nThis API function allows you to escape terminal codes and Vim keycodes.\n\nYou may have come across mappings like this one:\n\n```vim\ninoremap <expr> <Tab> pumvisible() ? \"\\<C-N>\" : \"\\<Tab>\"\n```\n\nTrying to do the same in Lua can prove to be a challenge. You might be tempted to do it like this:\n\n```lua\nfunction _G.smart_tab()\n    return vim.fn.pumvisible() == 1 and [[\\<C-N>]] or [[\\<Tab>]]\nend\n\nvim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr = true, noremap = true})\n```\n\nonly to find out that the mapping inserts `\\<Tab>` and `\\<C-N>` literally...\n\nBeing able to escape keycodes is actually a Vimscript feature. Aside from the usual escape sequences like `\\r`, `\\42` or `\\x10` that are common to many programming languages, Vimscript `expr-quotes` (strings surrounded with double quotes) allow you to escape the human-readable representation of Vim keycodes.\n\nLua doesn't have such a feature built-in. Fortunately, Neovim has an API function for escaping terminal codes and keycodes: `nvim_replace_termcodes()`\n\n```lua\nprint(vim.api.nvim_replace_termcodes('<Tab>', true, true, true))\n```\n\nThis is a little verbose. Making a reusable wrapper can help:\n\n```lua\n-- The function is called `t` for `termcodes`.\n-- You don't have to call it that, but I find the terseness convenient\nlocal function t(str)\n    -- Adjust boolean arguments as needed\n    return vim.api.nvim_replace_termcodes(str, true, true, true)\nend\n\nprint(t'<Tab>')\n```\n\nComing back to our earlier example, this should now work as expected:\n\n```lua\nlocal function t(str)\n    return vim.api.nvim_replace_termcodes(str, true, true, true)\nend\n\nfunction _G.smart_tab()\n    return vim.fn.pumvisible() == 1 and t'<C-N>' or t'<Tab>'\nend\n\nvim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr = true, noremap = true})\n```\n\nThis is not necessary with `vim.keymap.set()` as it automatically transforms vim keycodes returned by Lua functions in `expr` mappings by default:\n\n```lua\nvim.keymap.set('i', '<Tab>', function()\n    return vim.fn.pumvisible() == 1 and '<C-N>' or '<Tab>'\nend, {expr = true})\n```\n\nSee also:\n\n- [`:help keycodes`](https://neovim.io/doc/user/intro.html#keycodes)\n- [`:help expr-quote`](https://neovim.io/doc/user/eval.html#expr-quote)\n- [`:help nvim_replace_termcodes()`](https://neovim.io/doc/user/api.html#nvim_replace_termcodes())\n\n## Managing vim options\n\n### Using api functions\n\nNeovim provides a set of API functions to either set an option or get its current value:\n\n- Global options:\n    - [`vim.api.nvim_set_option()`](https://neovim.io/doc/user/api.html#nvim_set_option())\n    - [`vim.api.nvim_get_option()`](https://neovim.io/doc/user/api.html#nvim_get_option())\n- Buffer-local options:\n    - [`vim.api.nvim_buf_set_option()`](https://neovim.io/doc/user/api.html#nvim_buf_set_option())\n    - [`vim.api.nvim_buf_get_option()`](https://neovim.io/doc/user/api.html#nvim_buf_get_option())\n- Window-local options:\n    - [`vim.api.nvim_win_set_option()`](https://neovim.io/doc/user/api.html#nvim_win_set_option())\n    - [`vim.api.nvim_win_get_option()`](https://neovim.io/doc/user/api.html#nvim_win_get_option())\n\nThey take a string containing the name of the option to set/get as well as the value you want to set it to.\n\nBoolean options (like `(no)number`) have to be set to either `true` or `false`:\n\n```lua\nvim.api.nvim_set_option('smarttab', false)\nprint(vim.api.nvim_get_option('smarttab')) -- false\n```\n\nUnsurprisingly, string options have to be set to a string:\n\n```lua\nvim.api.nvim_set_option('selection', 'exclusive')\nprint(vim.api.nvim_get_option('selection')) -- 'exclusive'\n```\n\nNumber options accept a number:\n\n```lua\nvim.api.nvim_set_option('updatetime', 3000)\nprint(vim.api.nvim_get_option('updatetime')) -- 3000\n```\n\nBuffer-local and window-local options also need a buffer number or a window number (using `0` will set/get the option for the current buffer/window):\n\n```lua\nvim.api.nvim_win_set_option(0, 'number', true)\nvim.api.nvim_buf_set_option(10, 'shiftwidth', 4)\nprint(vim.api.nvim_win_get_option(0, 'number')) -- true\nprint(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4\n```\n\n### Using meta-accessors\n\nA few meta-accessors are available if you want to set options in a more \"idiomatic\" way. They essentially wrap the above API functions and allow you to manipulate options as if they were variables:\n\n- [`vim.o`](https://neovim.io/doc/user/lua.html#vim.o): behaves like `:let &{option-name}`\n- [`vim.go`](https://neovim.io/doc/user/lua.html#vim.go): behaves like `:let &g:{option-name}`\n- [`vim.bo`](https://neovim.io/doc/user/lua.html#vim.bo): behaves like `:let &l:{option-name}` for buffer-local options\n- [`vim.wo`](https://neovim.io/doc/user/lua.html#vim.wo): behaves like `:let &l:{option-name}` for window-local options\n\n```lua\nvim.o.smarttab = false -- let &smarttab = v:false\nprint(vim.o.smarttab) -- false\nvim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname = &isfname .. ',@-@'\nprint(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'\n\nvim.bo.shiftwidth = 4\nprint(vim.bo.shiftwidth) -- 4\n```\n\nYou can specify a number for buffer-local and window-local options. If no number is given, the current buffer/window is used:\n\n```lua\nvim.bo[4].expandtab = true -- same as vim.api.nvim_buf_set_option(4, 'expandtab', true)\nvim.wo.number = true -- same as vim.api.nvim_win_set_option(0, 'number', true)\n```\n\nThese wrappers also have more sophisticated `vim.opt*` variants that provide convenient mechanisms for setting options in Lua. They're similar to what you might be used to in your `init.vim`:\n\n- `vim.opt`: behaves like `:set`\n- `vim.opt_global`: behaves like `:setglobal`\n- `vim.opt_local`: behaves like `:setlocal`\n\n```lua\nvim.opt.smarttab = false\nprint(vim.opt.smarttab:get()) -- false\n```\n\nSome options can be set using Lua tables:\n\n```lua\nvim.opt.completeopt = {'menuone', 'noselect'}\nprint(vim.inspect(vim.opt.completeopt:get())) -- { \"menuone\", \"noselect\" }\n```\n\nWrappers for list-like, map-like and set-like options also come with methods and metamethods that work similarly to their `:set+=`, `:set^=` and `:set-=` counterparts in Vimscript.\n\n```lua\nvim.opt.shortmess:append({ I = true })\n-- alternative form:\nvim.opt.shortmess = vim.opt.shortmess + { I = true }\n\nvim.opt.whichwrap:remove({ 'b', 's' })\n-- alternative form:\nvim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' }\n```\n\nBe sure to look at [`:help vim.opt`](https://neovim.io/doc/user/lua.html#vim.opt) for more information.\n\nSee also:\n- [`:help lua-vim-options`](https://neovim.io/doc/user/lua.html#lua-vim-options)\n\n## Managing vim internal variables\n\n### Using api functions\n\nMuch like options, internal variables have their own set of API functions:\n\n- Global variables (`g:`):\n    - [`vim.api.nvim_set_var()`](https://neovim.io/doc/user/api.html#nvim_set_var())\n    - [`vim.api.nvim_get_var()`](https://neovim.io/doc/user/api.html#nvim_get_var())\n    - [`vim.api.nvim_del_var()`](https://neovim.io/doc/user/api.html#nvim_del_var())\n- Buffer variables (`b:`):\n    - [`vim.api.nvim_buf_set_var()`](https://neovim.io/doc/user/api.html#nvim_buf_set_var())\n    - [`vim.api.nvim_buf_get_var()`](https://neovim.io/doc/user/api.html#nvim_buf_get_var())\n    - [`vim.api.nvim_buf_del_var()`](https://neovim.io/doc/user/api.html#nvim_buf_del_var())\n- Window variables (`w:`):\n    - [`vim.api.nvim_win_set_var()`](https://neovim.io/doc/user/api.html#nvim_win_set_var())\n    - [`vim.api.nvim_win_get_var()`](https://neovim.io/doc/user/api.html#nvim_win_get_var())\n    - [`vim.api.nvim_win_del_var()`](https://neovim.io/doc/user/api.html#nvim_win_del_var())\n- Tabpage variables (`t:`):\n    - [`vim.api.nvim_tabpage_set_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_set_var())\n    - [`vim.api.nvim_tabpage_get_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_get_var())\n    - [`vim.api.nvim_tabpage_del_var()`](https://neovim.io/doc/user/api.html#nvim_tabpage_del_var())\n- Predefined Vim variables (`v:`):\n    - [`vim.api.nvim_set_vvar()`](https://neovim.io/doc/user/api.html#nvim_set_vvar())\n    - [`vim.api.nvim_get_vvar()`](https://neovim.io/doc/user/api.html#nvim_get_vvar())\n\nWith the exception of predefined Vim variables, they can also be deleted (the `:unlet` command is the equivalent in Vimscript). Local variables (`l:`), script variables (`s:`) and function arguments (`a:`) cannot be manipulated as they only make sense in the context of a Vim script, Lua has its own scoping rules.\n\nIf you are unfamiliar with what these variables do, [`:help internal-variables`](https://neovim.io/doc/user/eval.html#internal-variables) describes them in detail.\n\nThese functions take a string containing the name of the variable to set/get/delete as well as the value you want to set it to.\n\n```lua\nvim.api.nvim_set_var('some_global_variable', { key1 = 'value', key2 = 300 })\nprint(vim.inspect(vim.api.nvim_get_var('some_global_variable'))) -- { key1 = \"value\", key2 = 300 }\nvim.api.nvim_del_var('some_global_variable')\n```\n\nVariables that are scoped to a buffer, a window or a tabpage also receive a number (using `0` will set/get/delete the variable for the current buffer/window/tabpage):\n\n```lua\nvim.api.nvim_win_set_var(0, 'some_window_variable', 2500)\nvim.api.nvim_tab_set_var(3, 'some_tabpage_variable', 'hello world')\nprint(vim.api.nvim_win_get_var(0, 'some_window_variable')) -- 2500\nprint(vim.api.nvim_buf_get_var(3, 'some_tabpage_variable')) -- 'hello world'\nvim.api.nvim_win_del_var(0, 'some_window_variable')\nvim.api.nvim_buf_del_var(3, 'some_tabpage_variable')\n```\n\n### Using meta-accessors\n\nInternal variables can be manipulated more intuitively using these meta-accessors:\n\n- [`vim.g`](https://neovim.io/doc/user/lua.html#vim.g): global variables\n- [`vim.b`](https://neovim.io/doc/user/lua.html#vim.b): buffer variables\n- [`vim.w`](https://neovim.io/doc/user/lua.html#vim.w): window variables\n- [`vim.t`](https://neovim.io/doc/user/lua.html#vim.t): tabpage variables\n- [`vim.v`](https://neovim.io/doc/user/lua.html#vim.v): predefined Vim variables\n- [`vim.env`](https://neovim.io/doc/user/lua.html#vim.env): environment variables\n\n```lua\nvim.g.some_global_variable = {\n    key1 = 'value',\n    key2 = 300\n}\n\nprint(vim.inspect(vim.g.some_global_variable)) -- { key1 = \"value\", key2 = 300 }\n\n-- target a specific buffer/window/tabpage (Neovim 0.6+)\nvim.b[2].myvar = 1\n```\n\nSome variable names may contain characters that cannot be used for identifiers in Lua. You can still manipulate these variables by using this syntax: `vim.g['my#variable']`.\n\nTo delete one of these variables, simply assign `nil` to it:\n\n```lua\nvim.g.some_global_variable = nil\n```\n\nSee also:\n- [`:help lua-vim-variables`](https://neovim.io/doc/user/lua.html#lua-vim-variables)\n\n#### Caveats\n\nYou cannot add/update/delete keys from a dictionary stored in one of these variables. For example, this snippet of Vimscript code does not work as expected:\n\n```vim\nlet g:variable = {}\nlua vim.g.variable.key = 'a'\necho g:variable\n\" {}\n```\n\nYou can use a temporary variable as a workaround:\n\n```vim\nlet g:variable = {}\nlua << EOF\nlocal tmp = vim.g.variable\ntmp.key = 'a'\nvim.g.variable = tmp\nEOF\necho g:variable\n\" {'key': 'a'}\n```\n\nThis is a known issue:\n\n- [Issue #12544](https://github.com/neovim/neovim/issues/12544)\n\n## Calling Vimscript functions\n\n### vim.fn.{function}()\n\n`vim.fn` can be used to call a Vimscript function. Data types are converted back and forth from Lua to Vimscript.\n\n```lua\nprint(vim.fn.printf('Hello from %s', 'Lua'))\n\nlocal reversed_list = vim.fn.reverse({ 'a', 'b', 'c' })\nprint(vim.inspect(reversed_list)) -- { \"c\", \"b\", \"a\" }\n\nlocal function print_stdout(chan_id, data, name)\n    print(data[1])\nend\n\nvim.fn.jobstart('ls', { on_stdout = print_stdout })\n```\n\nHashes (`#`) are not valid characters for identifiers in Lua, so autoload functions have to be called with this syntax:\n\n```lua\nvim.fn['my#autoload#function']()\n```\n\nThe functionality of `vim.fn` is identical to `vim.call`, but allows a more Lua-like syntax.\n\nIt is distinct from `vim.api.nvim_call_function` in that converting Vim/Lua objects is automatic: `vim.api.nvim_call_function` returns a table for floating point numbers and does not accept Lua closures while `vim.fn` handles these types transparently.\n\nSee also:\n- [`:help vim.fn`](https://neovim.io/doc/user/lua.html#vim.fn)\n\n#### Tips\n\nNeovim has an extensive library of powerful built-in functions that are very useful for plugins. See [`:help vim-function`](https://neovim.io/doc/user/eval.html#vim-function) for an alphabetical list and [`:help function-list`](https://neovim.io/doc/user/usr_41.html#function-list) for a list of functions grouped by topic.\n\nNeovim API functions can be used directly through `vim.api.{..}`. See [`:help api`](https://neovim.io/doc/user/api.html#API) for information.\n\n#### Caveats\n\nSome Vim functions that should return a boolean return `1` or `0` instead. This isn't a problem in Vimscript as `1` is truthy and `0` falsy, enabling constructs like these:\n\n```vim\nif has('nvim')\n    \" do something...\nendif\n```\n\nIn Lua however, only `false` and `nil` are considered falsy, numbers always evaluate to `true` no matter their value. You have to explicitly check for `1` or `0`:\n\n```lua\nif vim.fn.has('nvim') == 1 then\n    -- do something...\nend\n```\n\n## Defining mappings\n\n### API functions\n\nNeovim provides a list of API functions to set, get and delete mappings:\n\n- Global mappings:\n    - [`vim.api.nvim_set_keymap()`](https://neovim.io/doc/user/api.html#nvim_set_keymap())\n    - [`vim.api.nvim_get_keymap()`](https://neovim.io/doc/user/api.html#nvim_get_keymap())\n    - [`vim.api.nvim_del_keymap()`](https://neovim.io/doc/user/api.html#nvim_del_keymap())\n- Buffer-local mappings:\n    - [`vim.api.nvim_buf_set_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_set_keymap())\n    - [`vim.api.nvim_buf_get_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_get_keymap())\n    - [`vim.api.nvim_buf_del_keymap()`](https://neovim.io/doc/user/api.html#nvim_buf_del_keymap())\n\nLet's start with `vim.api.nvim_set_keymap()` and `vim.api.nvim_buf_set_keymap()`\n\nThe first argument passed to the function is a string containing the name of the mode for which the mapping will take effect:\n\n| String value           | Help page     | Affected modes                           | Vimscript equivalent |\n| ---------------------- | ------------- | ---------------------------------------- | -------------------- |\n| `''` (an empty string) | `mapmode-nvo` | Normal, Visual, Select, Operator-pending | `:map`               |\n| `'n'`                  | `mapmode-n`   | Normal                                   | `:nmap`              |\n| `'v'`                  | `mapmode-v`   | Visual and Select                        | `:vmap`              |\n| `'s'`                  | `mapmode-s`   | Select                                   | `:smap`              |\n| `'x'`                  | `mapmode-x`   | Visual                                   | `:xmap`              |\n| `'o'`                  | `mapmode-o`   | Operator-pending                         | `:omap`              |\n| `'!'`                  | `mapmode-ic`  | Insert and Command-line                  | `:map!`              |\n| `'i'`                  | `mapmode-i`   | Insert                                   | `:imap`              |\n| `'l'`                  | `mapmode-l`   | Insert, Command-line, Lang-Arg           | `:lmap`              |\n| `'c'`                  | `mapmode-c`   | Command-line                             | `:cmap`              |\n| `'t'`                  | `mapmode-t`   | Terminal                                 | `:tmap`              |\n\nThe second argument is a string containing the left-hand side of the mapping (the key or set of keys that trigger the command defined in the mapping). An empty string is equivalent to `<Nop>`, which disables a key.\n\nThe third argument is a string containing the right-hand side of the mapping (the command to execute).\n\nThe final argument is a table containing boolean options for the mapping as defined in [`:help :map-arguments`](https://neovim.io/doc/user/map.html#:map-arguments) (including `noremap` and excluding `buffer`). Since Neovim 0.7.0, you can also pass a `callback` option to invoke a Lua function instead of the right-hand side when executing the mapping.\n\nBuffer-local mappings also take a buffer number as their first argument (`0` sets the mapping for the current buffer).\n\n```lua\nvim.api.nvim_set_keymap('n', '<Leader><Space>', ':set hlsearch!<CR>', { noremap = true, silent = true })\n-- :nnoremap <silent> <Leader><Space> :set hlsearch<CR>\nvim.api.nvim_set_keymap('n', '<Leader>tegf',  [[<Cmd>lua require('telescope.builtin').git_files()<CR>]], { noremap = true, silent = true })\n-- :nnoremap <silent> <Leader>tegf <Cmd>lua require('telescope.builtin').git_files()<CR>\n\nvim.api.nvim_buf_set_keymap(0, '', 'cc', 'line(\".\") == 1 ? \"cc\" : \"ggcc\"', { noremap = true, expr = true })\n-- :noremap <buffer> <expr> cc line('.') == 1 ? 'cc' : 'ggcc'\n\nvim.api.nvim_set_keymap('n', '<Leader>ex', '', {\n    noremap = true,\n    callback = function()\n        print('My example')\n    end,\n    -- Since Lua function don't have a useful string representation, you can use the \"desc\" option to document your mapping\n    desc = 'Prints \"My example\" in the message area',\n})\n```\n\n`vim.api.nvim_get_keymap()` takes a string containing the shortname of the mode for which you want the list of mappings (see table above). The return value is a table containing all global mappings for the mode.\n\n```lua\nprint(vim.inspect(vim.api.nvim_get_keymap('n')))\n-- :verbose nmap\n```\n\n`vim.api.nvim_buf_get_keymap()` takes an additional buffer number as its first argument (`0` will get mapppings for the current bufffer)\n\n```lua\nprint(vim.inspect(vim.api.nvim_buf_get_keymap(0, 'i')))\n-- :verbose imap <buffer>\n```\n\n`vim.api.nvim_del_keymap()` takes a mode and the left-hand side of a mapping.\n\n```lua\nvim.api.nvim_del_keymap('n', '<Leader><Space>')\n-- :nunmap <Leader><Space>\n```\n\nAgain, `vim.api.nvim_buf_del_keymap()`, takes a buffer number as its first argument, with `0` representing the current buffer.\n\n```lua\nvim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')\n-- :iunmap <buffer> <Tab>\n```\n\n### vim.keymap\n\n:warning: The functions discussed in this section are only available in Neovim 0.7.0+\n\nNeovim provides two functions to set/del mappings:\n- [`vim.keymap.set()`](https://neovim.io/doc/user/lua.html#vim.keymap.set())\n- [`vim.keymap.del()`](https://neovim.io/doc/user/lua.html#vim.keymap.del())\n\nThese are similar to the above API functions with added syntactic sugar.\n\n`vim.keymap.set()` takes a string as its first argument. It can also be a table of strings to define mappings for multiple modes at once:\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>lua vim.notify(\"Example 1\")<CR>')\nvim.keymap.set({'n', 'c'}, '<Leader>ex2', '<Cmd>lua vim.notify(\"Example 2\")<CR>')\n```\n\nThe second argument is the left-hand side of the mapping.\n\nThe third argument is the right-hand side of the mapping, which can either be a string or a Lua function:\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>')\nvim.keymap.set('n', '<Leader>ex2', function() print(\"Example 2\") end)\nvim.keymap.set('n', '<Leader>pl1', require('plugin').plugin_action)\n-- To avoid the startup cost of requiring the module, you can wrap it in a function to require it lazily when invoking the mapping:\nvim.keymap.set('n', '<Leader>pl2', function() require('plugin').plugin_action() end)\n```\n\nThe fourth (optional) argument is a table of options that correspond to the options passed to `vim.api.nvim_set_keymap()`, with a few additions (see [`:help vim.keymap.set()`](https://neovim.io/doc/user/lua.html#vim.keymap.set()) for the full list).\n\n```lua\nvim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>', {buffer = true})\nvim.keymap.set('n', '<Leader>ex2', function() print('Example 2') end, {desc = 'Prints \"Example 2\" to the message area'})\n```\n\nDefining keymaps with a Lua function is different from using a string. The usual way to show information about a keymap like `:nmap <Leader>ex1` will not output useful information (the string itself), but instead only show `Lua function`. It is recommended to add a `desc` key to describe the behavior of your keymap. This is especially important for documenting plugin mappings so users can understand the usage of the keymap more easily.\n\nAn interesting feature of this API is that it irons out some historical quirks of Vim mappings:\n- Mappings are `noremap` by default, except when the `rhs` is a `<Plug>` mapping. This means you rarely have to think about whether a mapping should be recursive or not:\n    ```lua\n    vim.keymap.set('n', '<Leader>test1', '<Cmd>echo \"test\"<CR>')\n    -- :nnoremap <Leader>test <Cmd>echo \"test\"<CR>\n\n    -- If you DO want the mapping to be recursive, set the \"remap\" option to \"true\"\n    vim.keymap.set('n', '>', ']', {remap = true})\n    -- :nmap > ]\n\n    -- <Plug> mappings don't work unless they're recursive, vim.keymap.set() handles that for you automatically\n    vim.keymap.set('n', '<Leader>plug', '<Plug>(plugin)')\n    -- :nmap <Leader>plug <Plug>(plugin)\n    ```\n- In `expr` mappings, `nvim_replace_termcodes()` is automatically applied to strings returned from Lua functions:\n    ```lua\n    vim.keymap.set('i', '<Tab>', function()\n        return vim.fn.pumvisible == 1 and '<C-N>' or '<Tab>'\n    end, {expr = true})\n    ```\n\nSee also:\n- [`:help recursive_mapping`](https://neovim.io/doc/user/map.html#recursive_mapping)\n\n`vim.keymap.del()` works the same way but deletes mappings instead:\n\n```lua\nvim.keymap.del('n', '<Leader>ex1')\nvim.keymap.del({'n', 'c'}, '<Leader>ex2', {buffer = true})\n```\n\n## Defining user commands\n\n:warning: The API functions discussed in this section are only available in Neovim 0.7.0+\n\nNeovim provides API functions for user-defined commands:\n\n- Global user commands:\n    - [`vim.api.nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command())\n    - [`vim.api.nvim_del_user_command()`](https://neovim.io/doc/user/api.html#nvim_del_user_command())\n- Buffer-local user commands:\n    - [`vim.api.nvim_buf_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_buf_create_user_command())\n    - [`vim.api.nvim_buf_del_user_command()`](https://neovim.io/doc/user/api.html#nvim_buf_del_user_command())\n\nLet's start with `vim.api.nvim_create_user_command()`\n\nThe first argument passed to this function is the name of the command (which must start with an uppercase letter).\n\nThe second argument is the code to execute when invoking said command. It can either be:\n\nA string (in which case it will be executed as Vimscript). You can use escape sequences like `<q-args>`, `<range>`, etc. like you would with `:command`\n```lua\nvim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 })\n-- :command! -nargs=1 Upper echo toupper(<q-args>)\n\nvim.cmd('Upper hello world') -- prints \"HELLO WORLD\"\n```\n\nOr a Lua function. It receives a dictionary-like table that contains the data normally provided by escape sequences (see [`:help nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command()) for a list of available keys)\n```lua\nvim.api.nvim_create_user_command(\n    'Upper',\n    function(opts)\n        print(string.upper(opts.args))\n    end,\n    { nargs = 1 }\n)\n```\n\nThe third argument lets you pass command attributes as a table (see [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)). Since you can already define buffer-local user commands with `vim.api.nvim_buf_create_user_command()`, `-buffer` is not a valid attribute.\n\nTwo additional attributes are available:\n- `desc` allows you to control what gets displayed when you run `:command {cmd}` on a command defined as a Lua callback. Similarly to keymaps, it is recommended to add a `desc` key to commands defined as Lua functions.\n- `force` is equivalent to calling `:command!` and replaces a command if one with the same name already exists. It is true by default, unlike its Vimscript equivalent.\n\nThe `-complete` attribute can take a Lua function in addition to the attributes listed in [`:help :command-complete`](https://neovim.io/doc/user/map.html#:command-complete).\n\n```lua\nvim.api.nvim_create_user_command('Upper', function() end, {\n    nargs = 1,\n    complete = function(ArgLead, CmdLine, CursorPos)\n        -- return completion candidates as a list-like table\n        return { 'foo', 'bar', 'baz' }\n    end,\n})\n```\n\nBuffer-local user commands also take a buffer number as their first argument. This is an advantage over `-buffer` which can only define a command for the current buffer.\n\n```lua\nvim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})\n```\n\n`vim.api.nvim_del_user_command()` takes a command name.\n\n```lua\nvim.api.nvim_del_user_command('Upper')\n-- :delcommand Upper\n```\n\nAgain, `vim.api.nvim_buf_del_user_command()`, takes a buffer number as its first argument, with `0` representing the current buffer.\n\n```lua\nvim.api.nvim_buf_del_user_command(4, 'Upper')\n```\n\nSee also:\n- [`:help nvim_create_user_command()`](https://neovim.io/doc/user/api.html#nvim_create_user_command())\n- [`:help 40.2`](https://neovim.io/doc/user/usr_40.html#40.2)\n- [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)\n\n### Caveats\n\nThe `-complete=custom` attribute automatically filters completion candidates and has built-in wildcard ([`:help wildcard`](https://neovim.io/doc/user/editing.html#wildcard)) support:\n\n```vim\nfunction! s:completion_function(ArgLead, CmdLine, CursorPos) abort\n    return join([\n        \\ 'strawberry',\n        \\ 'star',\n        \\ 'stellar',\n        \\ ], \"\\n\")\nendfunction\n\ncommand! -nargs=1 -complete=custom,s:completion_function Test echo <q-args>\n\" Typing `:Test st[ae]<Tab>` returns \"star\" and \"stellar\"\n```\n\nPassing a Lua function to `complete` makes it behave like `customlist` which leaves filtering up to the user:\n\n```lua\nvim.api.nvim_create_user_command('Test', function() end, {\n    nargs = 1,\n    complete = function(ArgLead, CmdLine, CursorPos)\n        return {\n            'strawberry',\n            'star',\n            'stellar',\n        }\n    end,\n})\n\n-- Typing `:Test z<Tab>` returns all the completion results because the list was not filtered\n```\n\n## Defining autocommands\n\n(this section is a work in progress)\n\nNeovim 0.7.0 has API functions for autocommands. See `:help api-autocmd` for details\n\n- [Pull request #14661](https://github.com/neovim/neovim/pull/14661) (lua: autocmds take 2)\n\n## Defining highlights\n\n(this section is a work in progress)\n\nNeovim 0.7.0 has API functions for highlight groups. See also:\n\n- [`:help nvim_set_hl()`](https://neovim.io/doc/user/api.html#nvim_set_hl())\n- [`:help nvim_get_hl_by_id()`](https://neovim.io/doc/user/api.html#nvim_get_hl_by_id())\n- [`:help nvim_get_hl_by_name()`](https://neovim.io/doc/user/api.html#nvim_get_hl_by_name())\n\n## General tips and recommendations\n\n### Reloading cached modules\n\nIn Lua, the `require()` function caches modules. This is a good thing for performance, but it can make working on plugins a bit cumbersome because modules are not updated on subsequent `require()` calls.\n\nIf you'd like to refresh the cache for a particular module, you have to modify the `package.loaded` global table:\n\n```lua\npackage.loaded['modname'] = nil\nrequire('modname') -- loads an updated version of module 'modname'\n```\n\nThe [nvim-lua/plenary.nvim](https://github.com/nvim-lua/plenary.nvim) plugin has a [custom function](https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/reload.lua) that does this for you.\n\n### Don't pad Lua strings!\n\nWhen using double bracketed strings, resist the temptation to pad them! While it is fine to do in contexts where spaces are ignored, it can cause hard to debug issues when whitespace is significant:\n\n```lua\nvim.api.nvim_set_keymap('n', '<Leader>f', [[ <Cmd>call foo()<CR> ]], {noremap = true})\n```\n\nIn the above example, `<Leader>f` is mapped to `<Space><Cmd>call foo()<CR><Space>` instead of `<Cmd>call foo()<CR>`.\n\n### Notes about Vimscript <-> Lua type conversion\n\n#### Converting a variable creates a copy:\nYou can't directly interact with the reference to a Vim object from Lua or a Lua object from Vimscript.  \nFor example, the `map()` function in Vimscript modifies a variable in place:\n\n```vim\nlet s:list = [1, 2, 3]\nlet s:newlist = map(s:list, {_, v -> v * 2})\n\necho s:list\n\" [2, 4, 6]\necho s:newlist\n\" [2, 4, 6]\necho s:list is# s:newlist\n\" 1\n```\n\nUsing this function from Lua creates a copy instead:\n\n```lua\nlocal tbl = {1, 2, 3}\nlocal newtbl = vim.fn.map(tbl, function(_, v) return v * 2 end)\n\nprint(vim.inspect(tbl)) -- { 1, 2, 3 }\nprint(vim.inspect(newtbl)) -- { 2, 4, 6 }\nprint(tbl == newtbl) -- false\n```\n\n#### Conversion is not always possible\nThis mostly affects functions and tables:\n\nLua tables that are a mix between a List and a Dictionary can't be converted:\n\n```lua\nprint(vim.fn.count({1, 1, number = 1}, 1))\n-- E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys\n```\n\nWhile you can call Vim functions in Lua with `vim.fn`, you can't hold references to them. This can cause surprising behaviors:\n\n```lua\nlocal FugitiveHead = vim.fn.funcref('FugitiveHead')\nprint(FugitiveHead) -- vim.NIL\n\nvim.cmd(\"let g:test_dict = {'test_lambda': {-> 1}}\")\nprint(vim.g.test_dict.test_lambda) -- nil\nprint(vim.inspect(vim.g.test_dict)) -- {}\n```\n\nPassing Lua functions to Vim functions is OK, storing them in Vim variables is not (fixed in Neovim 0.7.0+):\n\n```lua\n-- This works:\nvim.fn.jobstart({'ls'}, {\n    on_stdout = function(chan_id, data, name)\n        print(vim.inspect(data))\n    end\n})\n\n-- This doesn't:\nvim.g.test_dict = {test_lambda = function() return 1 end} -- Error: Cannot convert given lua type\n```\n\nNote however that doing the same from Vimscript with `luaeval()` **does** work:\n\n```vim\nlet g:test_dict = {'test_lambda': luaeval('function() return 1 end')}\necho g:test_dict\n\" {'test_lambda': function('<lambda>4714')}\n```\n\n#### Vim booleans\nA common pattern in Vim scripts is to use `1` or `0` instead of proper booleans. Indeed, Vim did not have a separate boolean type until version 7.4.1154.\n\nLua booleans are converted to actual booleans in Vimscript, not numbers:\n\n```vim\nlua vim.g.lua_true = true\necho g:lua_true\n\" v:true\nlua vim.g.lua_false = false\necho g:lua_false\n\" v:false\n```\n\n### Setting up linters/language servers\n\nIf you're using linters and/or language servers to get diagnostics and autocompletion for Lua projects, you may have to configure Neovim-specific settings for them. Here are a few recommended settings for popular tools:\n\n#### luacheck\n\nYou can get [luacheck](https://github.com/mpeterv/luacheck/) to recognize the `vim` global by putting this configuration in `~/.luacheckrc` (or `$XDG_CONFIG_HOME/luacheck/.luacheckrc`):\n\n```lua\nglobals = {\n    \"vim\",\n}\n```\n\nThe [Alloyed/lua-lsp](https://github.com/Alloyed/lua-lsp/) language server uses `luacheck` to provide linting and reads the same file.\n\nFor more information on how to configure `luacheck`, please refer to its [documentation](https://luacheck.readthedocs.io/en/stable/config.html)\n\n#### sumneko/lua-language-server\n\nThe [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/) repository contains [instructions to configure sumneko/lua-language-server](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua) (the example uses the built-in LSP client but the configuration should be identical for other LSP client implementations).\n\nFor more information on how to configure [sumneko/lua-language-server](https://github.com/sumneko/lua-language-server/) see [\"Setting\"](https://github.com/sumneko/lua-language-server/wiki/Setting)\n\n#### coc.nvim\n\nThe [rafcamlet/coc-nvim-lua](https://github.com/rafcamlet/coc-nvim-lua/) completion source for [coc.nvim](https://github.com/neoclide/coc.nvim/) provides completion items for the Neovim stdlib.\n\n### Debugging Lua code\n\nYou can debug Lua code running in a separate Neovim instance with [jbyuki/one-small-step-for-vimkind](https://github.com/jbyuki/one-small-step-for-vimkind)\n\nThe plugin uses the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/). Connecting to a debug adapter requires a DAP client like [mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap/) or [puremourning/vimspector](https://github.com/puremourning/vimspector/).\n\n### Debugging Lua mappings/commands/autocommands\n\nThe `:verbose` command allows you to see where a mapping/command/autocommand was defined:\n\n```vim\n:verbose map m\n```\n\n```text\nn  m_          * <Cmd>echo 'example'<CR>\n        Last set from ~/.config/nvim/init.vim line 26\n```\n\nBy default, this feature is disabled in Lua for performance reasons. You can enable it by starting Neovim with a verbose level greater than 0:\n\n```sh\nnvim -V1\n```\n\nSee also:\n- [`:help 'verbose'`](https://neovim.io/doc/user/options.html#'verbose')\n- [`:help -V`](https://neovim.io/doc/user/starting.html#-V)\n- [neovim/neovim#15079](https://github.com/neovim/neovim/pull/15079)\n\n### Testing Lua code\n\n- [plenary.nvim: test harness](https://github.com/nvim-lua/plenary.nvim/#plenarytest_harness)\n- [notomo/vusted](https://github.com/notomo/vusted)\n\n### Using Luarocks packages\n\n[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim) supports Luarocks packages. Instructions for how to set this up are available in the [README](https://github.com/wbthomason/packer.nvim/#luarocks-support)\n\n## Miscellaneous\n\n### vim.loop\n\n`vim.loop` is the module that exposes the LibUV API. Some resources:\n\n- [Official documentation for LibUV](https://docs.libuv.org/en/v1.x/)\n- [Luv documentation](https://github.com/luvit/luv/blob/master/docs.md)\n- [teukka.tech - Using LibUV in Neovim](https://teukka.tech/posts/2020-01-07-vimloop/)\n\nSee also:\n- [`:help vim.loop`](https://neovim.io/doc/user/lua.html#vim.loop)\n\n### vim.lsp\n\n`vim.lsp` is the module that controls the built-in LSP client. The [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/) repository contains default configurations for popular language servers.\n\nThe behavior of the client can be configured using \"lsp-handlers\". For more information:\n- [`:help lsp-handler`](https://neovim.io/doc/user/lsp.html#lsp-handler)\n- [neovim/neovim#12655](https://github.com/neovim/neovim/pull/12655)\n- [How to migrate from diagnostic-nvim](https://github.com/nvim-lua/diagnostic-nvim/issues/73#issue-737897078)\n\nYou may also want to take a look at [plugins built around the LSP client](https://github.com/rockerBOO/awesome-neovim#lsp)\n\nSee also:\n- [`:help lsp`](https://neovim.io/doc/user/lsp.html#LSP)\n\n### vim.treesitter\n\n`vim.treesitter` is the module that controls the integration of the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) library in Neovim. If you want to know more about Tree-sitter, you may be interested in this [presentation (38:37)](https://www.youtube.com/watch?v=Jes3bD6P0To).\n\nThe [nvim-treesitter](https://github.com/nvim-treesitter/) organisation hosts various plugins taking advantage of the library.\n\nSee also:\n- [`:help lua-treesitter`](https://neovim.io/doc/user/treesitter.html#lua-treesitter)\n\n### Transpilers\n\nOne advantage of using Lua is that you don't actually have to write Lua code! There is a multitude of transpilers available for the language.\n\n- [Moonscript](https://moonscript.org/)\n\nProbably one of the most well-known transpilers for Lua. Adds a lots of convenient features like classes, list comprehensions or function literals. The [svermeulen/nvim-moonmaker](https://github.com/svermeulen/nvim-moonmaker) plugin allows you to write Neovim plugins and configuration directly in Moonscript.\n\n- [Fennel](https://fennel-lang.org/)\n\nA lisp that compiles to Lua. You can write configuration and plugins for Neovim in Fennel with the [Olical/aniseed](https://github.com/Olical/aniseed) or the [Hotpot](https://github.com/rktjmp/hotpot.nvim) plugin. Additionally, the [Olical/conjure](https://github.com/Olical/conjure) plugin provides an interactive development environment that supports Fennel (among other languages).\n\n- [Teal](https://github.com/teal-language/tl)\n\nThe name Teal comes from pronouncing TL (typed lua).  This is exactly what it tries to do - add strong typing to lua while otherwise remaining close to standard lua syntax.  The [nvim-teal-maker](https://github.com/svermeulen/nvim-teal-maker) plugin can be used to write Neovim plugins or configuration files directly in Teal\n\nOther interesting projects:\n- [TypeScriptToLua/TypeScriptToLua](https://github.com/TypeScriptToLua/TypeScriptToLua)\n- [Haxe](https://haxe.org/)\n- [SwadicalRag/wasm2lua](https://github.com/SwadicalRag/wasm2lua)\n- [hengestone/lua-languages](https://github.com/hengestone/lua-languages)\n"
  },
  {
    "path": "doc/nvim-lua-guide.jax",
    "content": "*nvim-lua-guide.txt*  Getting started using Lua in Neovim\n\n==============================================================================\nはじめに\n                                                         *luaguide-introduction*\n\nNeovimのファーストクラス言語としてのLuaはキラー機能の1つになりつつあります。\nしかし、Luaでプラグインを書くための教材はVim\nscript程多くありません。これは、Luaを始めるための基本的な情報を提供する試みです。\n\nこのガイドは少なくともNeovim 0.5を使用していることを前提としています。\n\nLuaを学ぶ~\n\nまだLuaについて詳しくない場合、学ぶためのリソースはたくさんあります。:\n\n- Learn X in Y minutes page about Lua:\nhttps://learnxinyminutes.com/docs/lua/\nは基本的な概要を説明します。\n- このガイド https://github.com/medwatt/Notes/blob/main/Lua/Lua_Quick_Guide.ipynb\nも素早く始めるのに良いチュートリアルです。\n- 動画が好きなら、Derek Banasの動画があります。 1-hour\ntutorial on the language: https://www.youtube.com/watch?v=iMacxZQMPXs\n- 実行できるサンプルを使い、対話的に学びたいですか？\nLuaScript tutorial: https://www.luascript.dev/learn を試してみてください。\n-  lua-users wiki: http://lua-users.org/wiki/LuaDirectory\nにはLua関連のトピックごとの便利な情報がたくさんあります。\n-  official reference manual for Lua: https://www.lua.org/manual/5.1/\nには最も包括的な情報があります。\nエディタで快適に読みたいなら、Vimdocプラグインがあります。:\nmilisims/nvim-luaref: https://github.com/milisims/nvim-luaref\n\nLuaはとてもクリーンでシンプルな言語であることに注意してください。\nJavaScriptのようなスクリプト言語の経験があれば、学ぶことは簡単です。\nあなたはもう自分で思っているよりLuaについて知っているかもしれません！\n\nNote: Neovimに埋め込まれているLuaはLuaJIT:\nhttps://staff.fnwi.uva.nl/h.vandermeer/docs/lua/luajit/luajit_intro.html\n2.1.0でLua 5.1と互換性を維持しています。\n\nLuaを書くための既存のチュートリアル~\n\nLuaでプラグインを書くためのチュートリアルが既にいくつかあります。\nそれらはこのガイドを書くのに役に立ちました。筆者に感謝します。\n\n-  teukka.tech - init.vimからinit.luaへ:\nhttps://teukka.tech/luanvim.html\n-  2n.pl - プラグインをLuaで書く方法:\nhttps://dev.to/2nit/how-to-write-neovim-plugins-in-lua-5cca\n-  2n.pl - プラグインのUIをLuaで作る方法:\nhttps://dev.to/2nit/how-to-make-ui-for-neovim-plugins-in-lua-3b6e\n-  ms-jpq - Neovim Async Tutorial:\nhttps://github.com/ms-jpq/neovim-async-tutorial\n-  oroques.dev - Neovim 0.5の機能とinit.luaへの切り替え:\nhttps://oroques.dev/notes/neovim-init/\n-  ゼロからステータスラインを作る - jdhao's blog:\nhttps://jdhao.github.io/2019/11/03/vim_custom_statusline/\n-  LuaでNeovimを設定する: https://icyphox.sh/blog/nvim-lua/\n-  Devlog | Luaで設定するために知る必要のあること:\nhttps://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/\n\n関連するプラグイン~\n\n-  Vimpeccable: https://github.com/svermeulen/vimpeccable  -\n.vimrc内でLuaを書くのに役に立つプラグイン\n-  plenary.nvim: https://github.com/nvim-lua/plenary.nvim  -\n二度書きたくないLua関数のすべて\n-  popup.nvim: https://github.com/nvim-lua/popup.nvim  - vimのPopup\nAPIのNeovimでの実装\n-  nvim_utils: https://github.com/norcalli/nvim_utils\n-  nvim-luadev: https://github.com/bfredl/nvim-luadev  -\nREPL/debugコンソール\n-  nvim-luapad: https://github.com/rafcamlet/nvim-luapad  -\n組込みLuaエンジンのインタラクティブなリアルタイムスクラッチパッド\n-  nlua.nvim: https://github.com/tjdevries/nlua.nvim  - NeovimのLua開発\n-  BetterLua.vim: https://github.com/euclidianAce/BetterLua.vim  -\nVim/Neovimより良いシンタックスハイライト\n\n==============================================================================\nLuaファイルを置く場所\n                                               *luaguide-where-to-put-lua-files*\n\ninit.lua~\n\nNeovimは、`init.vim`の代わりに設定ファイルとして`init.lua`を読み込むことをサポートしています。\n\nNote: `init.lua`は_完全に_オプションです。`init.vim`は廃止されず、設定として有効です。\nいくつかの機能は、まだ100%Luaに公開されていないので注意してください。\n\n参照:\n- |config|\n\nモジュール~\n\nLuaモジュールは、`'runtimepath'`内の`lua/`フォルダにあります(ほとんどの場合、\n\\*nixでは`~/.config/nvim/lua`、Windowsでは`~/AppData/Local/nvim/lua`を意味します)。\nこのフォルダにあるファイルをLuaモジュールとして`require()`できます。\n\n例として次のフォルダ構造を取り上げましょう。:\n\n    >\n    📂 ~/.config/nvim\n    ├── 📁 after\n    ├── 📁 ftplugin\n    ├── 📂 lua\n    │  ├── 🌑 myluamodule.lua\n    │  └── 📂 other_modules\n    │     ├── 🌑 anothermodule.lua\n    │     └── 🌑 init.lua\n    ├── 📁 pack\n    ├── 📁 plugin\n    ├── 📁 syntax\n    └── 🇻 init.vim\n<\n\n次のLuaコードは`myluamodule.lua`をロードします。:\n\n    >\n    require('myluamodule')\n<\n\n`.lua`拡張子がないことに注意してください。\n\n同様に、`other_modules/anothermodule.lua`\nのロードは次のように行います。:\n\n    >\n    require('other_modules.anothermodule')\n    -- or\n    require('other_modules/anothermodule')\n<\n\nパスの区切りはドット`.`またはスラッシュ`/`で示されます。\n\nフォルダに`init.lua`が含まれている場合、ファイル名を指定せずにロードできます。\n\n    >\n    require('other_modules') -- other_modules/init.luaをロード\n<\n\n存在しないモジュール、構文エラーを含むモジュールをrequireすると実行中のスクリプトは停止します。\nエラーを防ぐために、`pcall()`を使用できます。\n\n    >\n    local ok, _ = pcall(require, 'module_with_error')\n    if not ok then\n      -- not loaded\n    end\n<\n\n参照:\n- `:help lua-require`\n\nRuntime files~\n\nVim scriptと同様に、`runtimepath`内にある特定のフォルダからLuaファイルを自動的に読み込めます。\n現在、次のフォルダがサポートされています。:\n\n- `colors/`\n- `compiler/`\n- `ftplugin/`\n- `ftdetect/`\n- `indent/`\n- `plugin/`\n- `syntax/`\n\n参照:\n- `:help 'runtimepath'`\n\nTips~\n\nいくつかのLuaプラグインは`lua/`フォルダ内に同じ名前のファイルがあるかもしれません。\nこれにより、名前空間の衝突を起こす可能性があります。\n\n異なる2つのプラグインに`lua/main.lua`がある場合、`require('main')`は曖昧です。:\nどのファイルを読み込みますか？\n\nトップレベルのフォルダで名前空間をつけることをお勧めします。:\n`lua/plugin_name/main.lua`\n\nRuntime files~\n\nVim scriptと同様に、`runtimepath`内にある特定のフォルダからLuaファイルを自動的に読み込めます。\n現在、次のフォルダがサポートされています。:\n\n- `colors/`\n- `compiler/`\n- `ftplugin/`\n- `ftdetect/`\n- `indent/`\n- `plugin/`\n- `syntax/`\n\nNote: runtimeデイレクトリでは、すべての`*.vim`ファイルは`*.lua`ファイルの前に読み込まれます。\n\n\n参照:\n- `:help 'runtimepath'`\n- `:help load-plugins`\n\nTips~\n\nランタイムファイルはLuaのモジュールシステムをベースとしていないため、2つのプラグインは`plugin/main.lua`を問題なく持つことができます。\n\n==============================================================================\nVim scriptからLuaを使用する\n                                             *luaguide-using-lua-from-vimscript*\n\n:lua~\n\nLuaのチャンクを実行します。\n\n    >\n    :lua require('myluamodule')\n<\n\nヒアドキュメント構文を使用すると複数行に書くことができます。:\n\n    >\n    echo \"Here's a bigger chunk of Lua code\"\n\n    lua << EOF\n    local mod = require('mymodule')\n    local tbl = {1, 2, 3}\n\n    for k, v in ipairs(tbl) do\n        mod.method(v)\n    end\n\n    print(tbl)\n    EOF\n<\n\nNote: 各`:lua`コマンドは独自のスコープを持っており、`local`を付けた変数はコマンドの外からアクセスできません。\n次の例は動作しません。:\n\n   >\n   :lua local foo = 1\n   :lua print(foo)\n   \" '1'ではなく'nil'が出力されます。\n<\n\nNote 2: Luaの`print()`は`:echomsg`と同じように動作します。出力はメッセージ履歴に保存されます。また、`:silent`で抑制できます。\n\n参照:\n\n- |:lua|\n- |:lua-heredoc|\n\n:luado~\n\nこのコマンドはカレントバッファの範囲行にLuaチャンクを実行します。範囲を指定しない場合、バッファ全体に作用します。\nチャンクから`return`された文字列は、各行を置き換えるために使用されます。\n\n次のコマンドは、カレントバッファのすべての行を`hello\nworld`に置き換えます。:\n\n    >\n    :luado return 'hello world'\n<\n\n2つの暗黙的な変数`line`と`liner`が提供されます。`line`は対象行のテキストで、`liner`はその行数です。\n次のコマンドは、すべての偶数行のテキストを大文字にします。\n\n    >\n    :luado if linenr % 2 == 0 then return line:upper() end\n<\n\n参照:\n\n- |:luado|\n\nLuaファイルの読み込み~\n\nNeovimはLuaファイルを読み込むためのEXコマンドを3つ提供しています。\n\n- `:luafile`\n- `:source`\n- `:runtime`\n\n`:luafile`と`:source`はとてもよく似ています。:\n\n    >\n    :luafile ~/foo/bar/baz/myluafile.lua\n    :luafile %\n    :source ~/foo/bar/baz/myluafile.lua\n    :source %\n<\n\n`:source`は範囲指定もサポートしており、スクリプトの一部を実行するのに役立ちます。:\n\n    >\n    :1,10source\n<\n\n`:runtime`は少し異なります。: `'runtimepath'`オプションで読み込むファイルを指定します。詳細は`:help :runtime`を参照してください。\n\n参照:\n\n- `:help :luafile`\n- `:help :source`\n- `:help :runtime`\n\nSourcing a lua file vs calling require()~\n\n`require()`関数を呼ぶこととLuaファイルの読み込みの違いは何か、どちらを使うべきかを疑問に思うかもしれません。\nそれらには異なるユースケースがあります。:\n\n- `require()`:\n    - Luaの組込み関数です。Luaのモジュールを読み込むのに使用します。\n    - `'runtimepath'`内にある`lua/`フォルダからモジュールを探します。\n    - どのモジュールをロードしたかを記憶し、多重に実行されるのを防ぎます。\n      Neovim実行中に、モジュールに含まれるコードを変更し、もう一度`require()`を実行してもモジュールは更新されません。\n- `:luafile`, `:source`, `runtime`:\n    - Exコマンドです。モジュールには対応していません。\n    - 以前に実行されたかどうかに関わらず実行されます。\n    - `:luafile`と`:source`は現在のウィンドウのディレクトリに対して相対パス・絶対パスを取ります。\n    - `runtime`は、`'rutimepath'`オプションを使用してファイルを探します。\n\n`:source`や`:runtime`、ランタイムディレクトリから自動的に読み込まれたファイルも`scriptnames`と`--startuptime`に表示されます。\n\nluaeval()~\n\nVim\nscriptの組込み関数です。文字列のLua式を評価して返します。\nLuaの型は自動的にVim\nscriptの型に変換されます。(その逆も同様です。)\n\n    >\n    \" 変数に結果を代入することができます。\n    let variable = luaeval('1 + 1')\n    echo variable\n    \" 2\n    let concat = luaeval('\"Lua\"..\" is \"..\"awesome\"')\n    echo concat\n    \" 'Lua is awesome'\n\n    \" リストのようなテーブルはVimのリストに変換されます。\n    let list = luaeval('{1, 2, 3, 4}')\n    echo list[0]\n    \" 1\n    echo list[1]\n    \" 2\n    \" 注意\n    Luaのテーブルと違い、Vimのリストは0インデックスです。\n\n    \" 辞書のようなテーブルはVimの辞書に変換されます。\n    let dict = luaeval('{foo = \"bar\", baz = \"qux\"}')\n    echo dict.foo\n    \" 'bar'\n\n    \" bool値とnilも同様です。\n    echo luaeval('true')\n    \" v:true\n    echo luaeval('nil')\n    \" v:null\n\n    \" Lua関数のエイリアスをVim\n    scriptで作ることができます。\n    let LuaMathPow = luaeval('math.pow')\n    echo LuaMathPow(2, 2)\n    \" 4\n    let LuaModuleFunction = luaeval('require(\"mymodule\").myfunction')\n    call LuaModuleFunction()\n\n    \" Vimの関数にLuaの関数を値として渡すこともできます。\n    lua X = function(k, v) return string.format(\"%s:%s\", k, v) end\n    echo map([1, 2, 3], luaeval(\"X\"))\n<\n\n`luaeval()`は式にデータを渡すことのできる任意の2つ目の引数があります。Luaからは`_A`としてアクセスできます。\n\n    >\n    echo luaeval('_A[1] + _A[2]', [1, 1])\n    \" 2\n\n    echo luaeval('string.format(\"Lua is %s\", _A)', 'awesome')\n    \" 'Lua is awesome'\n<\n\n参照:\n- |luaeval()|\n\nv:lua~\n\nVimのグローバル変数です。Vim\nscriptからLuaのグローバル名前空間(`_G`: https://www.lua.org/manual/5.1/manual.html#pdf-_G\n)内の関数を直接呼ぶことができます。\nこの場合でも、Vim scriptの型はLuaの型に変換されます。逆も同様です。\n\n    >\n    call v:lua.print('Hello from Lua!')\n    \" 'Hello from Lua!'\n\n    let scream = v:lua.string.rep('A', 10)\n    echo scream\n    \" 'AAAAAAAAAA'\n\n    \" How about a nice statusline?\n    lua << EOF\n    function _G.statusline()\n        local filepath = '%f'\n        local align_section = '%='\n        local percentage_through_file = '%p%%'\n        return string.format(\n            '%s%s%s',\n            filepath,\n            align_section,\n            percentage_through_file\n        )\n    end\n    EOF\n\n    set statusline=%!v:lua.statusline()\n\n    \" Also works in expression mappings\n    lua << EOF\n    function _G.check_back_space()\n        local col = vim.api.nvim_win_get_cursor(0)[2]\n        return (col == 0 or vim.api.nvim_get_current_line():sub(col, col):match('%s')) and true\n    end\n    EOF\n\n    inoremap <silent> <expr> <Tab>\n        \\ pumvisible() ? \"\\<C-N>\" :\n        \\ v:lua.check_back_space() ? \"\\<Tab>\" :\n        \\ completion#trigger_completion()\n\n    \" シングルクォートを使用したり、括弧を省略して、\n    \" Luaモジュールから関数を呼び出します:\n    call v:lua.require'module'.foo()\n<\n\n参照:\n- |v:lua|\n- |v:lua-call|\n\n警告~\n\nこの変数は関数呼び出しにのみ使用できます。次の例はエラーになります。:\n\n    >\n    \" 関数のエイリアスは動作しません\n    let LuaPrint = v:lua.print\n\n    \" 辞書アクセスは動作しません\n    echo v:lua.some_global_dict['key']\n\n    \" 関数を値として使用できません\n    echo map([1, 2, 3], v:lua.global_callback)\n<\n\nTips~\n\n設定ファイルに、`let g:vimsyn_embed =\n'l'`を追加すると.vimファイル内のLuaを構文ハイライトできます。\n詳細は`:h g:vimsyn_embed`を参照してください。\n\n==============================================================================\nvim名前空間\n                                                    *luaguide-the-vim-namespace*\n\nNeovimはLuaからAPIを使うためのエントリーポイントとして、`vim`グーローバル変数を公開しています。\nこれは、拡張された標準ライブラリやさまざまなサブモジュールを提供します。\n\nいくつかの注目すべき関数とモジュール:\n\n- `vim.inspect`:\nLuaオブジェクトを人間が読みやすい文字列に変換する(テーブルを調べるのに便利です。)\n- `vim.regex`: LuaからVimの正規表現を使う\n- `vim.api`:\nAPI関数を公開するモジュール(リモートプラグインで使うAPIと同じです)\n- `vim.ui`:\nプラグインから利用できる上書き可能な関数\n- `vim.loop`:\nNeovimのイベントループ機能を公開するモジュール(LibUVを使います)\n- `vim.lsp`:\n組込みのLSPクライアントを操作するモジュール\n- `vim.treesitter`:\ntree-sitterライブラリの機能を公開するモジュール\n\nこのリストは決して包括的なリストではありません。`vim`変数で何かできるかを詳しく知りたい場合は、`:h\nlua-stdlib`と`:help lua-vim`が最適です。\nまたは、`:lua\nprint(vim.inspect(vim))`を実行してすべてのモジュールのリストを取得できます。\nAPI関数は、`:help api-global`にあります。\n\nTips~\n\nオブジェクトの中身を検査するのに毎回`print(vim.inspect(x)`を書くのは面倒です。設定にグローバルなラッパー関数を含めることは価値があるかもしれません。\n(Neovim 0.7.0+では、この関数は組込み関数です。参照 |help vim.pretty_print()|):\n\n    >\n    function _G.put(...)\n      local objects = {}\n      for i = 1, select('#', ...) do\n        local v = select(i, ...)\n        table.insert(objects, vim.inspect(v))\n      end\n\n      print(table.concat(objects, '\\n'))\n      return ...\n    end\n<\n\nコードまたはコマンドラインからとても早くオブジェクトの中身を検査できます。\n\n    >\n    put({1, 2, 3})\n<\n\n    >\n    :lua put(vim.loop)\n<\n\nまたは、`:lua`コマンドでLua式の前に `=` をつけて、整列させて表示できます。(Neovim 0.7+のみ)\n    >\n    :lua =vim.loop\n\n\n加えて、他の言語と比較して組込みのLua関数が不足している場合があります(例えば、`os.clock`はミリ秒ではなく秒数のみを返します)。\n必ず、Neovim\nstdlib(それと`vim.fn`。詳しくは後述します。)を見てください。おそらく、探しものはそこにあります。\n\n==============================================================================\nLuaからVim scriptを使用する\n                                             *luaguide-using-vimscript-from-lua*\n\nvim.api.nvim_eval()~\n\n文字列で与えられたVim\nscriptの式を評価してその値を返します。Vim\nscriptの型は自動的にLuaの型に変換されます。(その逆も同様です。)\n\nこれは、Vim scriptの`luaeval()`と同様です。\n\n    >\n    -- 型は正しく変換されます。\n    print(vim.api.nvim_eval('1 + 1')) -- 2\n    print(vim.inspect(vim.api.nvim_eval('[1, 2, 3]'))) -- { 1, 2, 3 }\n    print(vim.inspect(vim.api.nvim_eval('{\"foo\": \"bar\", \"baz\": \"qux\"}')))\n    -- { baz = \"qux\", foo = \"bar\" }\n    print(vim.api.nvim_eval('v:true')) -- true\n    print(vim.api.nvim_eval('v:null')) -- nil\n<\n\n警告~\n\n`luaeval()`と違い、式にデータを渡すための暗黙的な変数`_A`を提供しません。\n\nvim.api.nvim_exec()~\n\nVim\nscriptのチャンクを実行します。実行するソースコートを含む文字列と、コードの出力を返すかどうかを決めるbool値を受け取ります(例えば、出力を変数に格納できます)。\n\n    >\n    local result = vim.api.nvim_exec(\n    [[\n    let s:mytext = 'hello world'\n\n    function! s:MyFunction(text)\n        echo a:text\n    endfunction\n\n    call MyFunction(s:mytext)\n    ]],\n    true)\n\n    print(result) -- 'hello world'\n<\n警告\n\nNeovim 0.6.0より前のバージョンでは 、`nvim_exec` はスクリプトローカル変数(`s:`)をサポートしていません。\n\nvim.api.nvim_command()~\n\nExコマンドを実行します。実行するコマンドを含む文字列を受け取ります。\n\n    >\n    vim.api.nvim_command('new')\n    vim.api.nvim_command('wincmd H')\n    vim.api.nvim_command('set nonumber')\n    vim.api.nvim_command('%s/foo/bar/g')\n<\n\n\nvim.cmd()~\n\n`vim.api.nvim_exec()`のエイリアスです。コマンドの引数のみを必要とし、`output`は常に`false`に設定されます。\n\n    >\n    vim.cmd('buffers')\n    vim.cmd([[\n    let g:multiline_list = [\n                \\ 1,\n                \\ 2,\n                \\ 3,\n                \\ ]\n\n    echo g:multiline_list\n    ]])\n\nTips~\n\nこれらの関数は文字列を渡すため、多くの場合、バックスラッシュをエスケープする必要があります。:\n\n    >\n    vim.cmd('%s/\\\\Vfoo/bar/g')\n<\n\n二重括弧の文字列はエスケープが必要ないため使いやすいです。:\n\n    >\n    vim.cmd([[%s/\\Vfoo/bar/g]])\n<\n\nvim.api.nvim_replace_termcodes()~\n\nこのAPI関数はターミナルコードとVimのキーコードをエスケープできます。\n\n次のようなマッピングを見たことがあるかもしれません。:\n\n    >\n    inoremap <expr> <Tab> pumvisible() ? \"\\<C-N>\" : \"\\<Tab>\"\n<\n\n同じことをLuaでやると大変です。\n次のようにやるかもしれません。:\n\n    >\n    function _G.smart_tab()\n        return vim.fn.pumvisible() == 1 and [[\\<C-N>]] or [[\\<Tab>]]\n    end\n\n    vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr =\n    true, noremap = true})\n<\n\nマッピングに `\\<Tab>` と `\\<C-N>` が挿入されているのを知るためだけに...\n\nキーコードをエスケープできるのは、Vim scriptの機能です。\n`\\r`, `\\42` や `\\x10` のような多くのプログラミング言語に共通する通常のエスケープシーケンスとは別に、\nVim scriptの `expr-quotes` (ダブルクォートで囲まれる文字列)を使用すると、\n人間が読める表現のVimキーコードをエスケープします。\n\nLuaにはそのような機能は組み込まれていません。\n嬉しいことに、NeovimにはターミナルコードとキーコードをエスケープするAPI関数\n`nvim_replace_termcodes()` があります。:\n\n    >\n    print(vim.api.nvim_replace_termcodes('<Tab>', true, true, true))\n<\n\nこれは少し冗長です。再利用できるラッパーを作ると便利です。:\n\n    >\n    -- `termcodes` 専用の `t` 関数です\n    -- この名前で呼ばなくてもいいですが、この簡潔さが便利です\n    local function t(str)\n        -- 必要に応じてboolean引数で調整します\n        return vim.api.nvim_replace_termcodes(str, true, true, true)\n    end\n\n    print(t'<Tab>')\n<\n\n先程の例はこれで期待通りに動きます。:\n\n    >\n    local function t(str)\n        return vim.api.nvim_replace_termcodes(str, true, true, true)\n    end\n\n    function _G.smart_tab()\n        return vim.fn.pumvisible() == 1 and t'<C-N>' or t'<Tab>'\n    end\n\n    vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr =\n    true, noremap = true})\n<\n\n`vim.keymap.set()`では、このハックは必要ありません。\n`expr`が有効な場合、デフォルトで自動的に変換されます。:\n\n    >\n    vim.keymap.set('i', '<Tab>', function()\n        return vim.fn.pumvisible() == 1 and '<C-N>' or '<Tab>'\n    end, {expr = true})\n<\n\n参照:\n- |keycodes|\n- |expr-quote|\n- |nvim_replace_termcodes()|\n\n==============================================================================\nvimオプションを管理する\n                                                 *luaguide-managing-vim-options*\n\nAPI関数を使用する~\n\nNeovimは、オプションの値を読み書きできるAPI関数を提供しています。\n\n- グローバルオプション:\n    - `vim.api.nvim_set_option()`\n    - `vim.api.nvim_get_option()`\n- バッファオプション:\n    - `vim.api.nvim_buf_set_option()`\n    - `vim.api.nvim_buf_get_option()`\n- ウィンドウオプション:\n    - `vim.api.nvim_win_set_option()`\n    - `vim.api.nvim_win_get_option()`\n\nそれらはオプションの名前と設定したい値を含む文字列を受け取ります。\n\nboolな(`(no)number`のような)オプションは`true`か`false`のどちらかに設定する必要があります。:\n\n    >\n    vim.api.nvim_set_option('smarttab', false)\n    print(vim.api.nvim_get_option('smarttab')) -- false\n<\n\n当然ながら、文字列のオプションには文字列を設定する必要があります。:\n\n    >\n    vim.api.nvim_set_option('selection', 'exclusive')\n    print(vim.api.nvim_get_option('selection')) -- 'exclusive'\n<\n\n数値のオプションは数値を受け取ります。:\n\n    >\n    vim.api.nvim_set_option('updatetime', 3000)\n    print(vim.api.nvim_get_option('updatetime')) -- 3000\n<\n\nバッファローカルとウィンドウローカルなオプションはそれぞれの番号も必要です。(`0`を指定した場合、カレントバッファ/ウィンドウが対象になります。):\n\n    >\n    vim.api.nvim_win_set_option(0, 'number', true)\n    vim.api.nvim_buf_set_option(10, 'shiftwidth', 4)\n    print(vim.api.nvim_win_get_option(0, 'number')) -- true\n    print(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4\n<\n\nメタアクセサーを使用する~\n\nもっと使い慣れた方法でオプションを設定したい場合、いくつかのメタアクセサーを使用できます。それらは、上記のAPI関数をラップしたものでオプションを変数のように操作できます。:\n\n- `vim.o.{option}`: `:let &{option-name}`のように動作します\n- `vim.go.{option}`: `:let &g:{option-name}`のように動作します\n- `vim.bo.{option}`: バッファローカルオプションの場合`:let &l:{option-name}`のように動作します\n- `vim.wo.{option}`: ウィンドウローカルオプションの場合`:let &l:{option-name}`のように動作します\n\n    >\n    vim.o.smarttab = false -- let &smarttab = v:false\n    print(vim.o.smarttab) -- false\n    vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname = &isfname .. ',@-@'\n    print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'\n\n    vim.bo.shiftwidth = 4\n    print(vim.bo.shiftwidth) -- 4\n<\n\nバッファとウィンドウの番号を指定できます。0を指定した場合、カレントバッファ/ウィンドウが使用されます。:\n\n    >\n    vim.bo[4].expandtab = true -- same as vim.api.nvim_buf_set_option(4,\n    'expandtab', true)\n    vim.wo.number = true -- same as vim.api.nvim_win_set_option(0,\n    'number', true)\n<\n\nこれらには、Luaで設定するのに便利なより洗練されたラッパーとして`vim.opt`があります。\n`init.vim`で慣れているものと似ています。:\n\n- `vim.opt.{option}`: `:set`のように動作します\n- `vim.opt_global.{option}`: `:setglobal`のように動作します\n- `vim.opt_local.{option}`: `:setlocal`のように動作します\n\n>\n    vim.opt.smarttab = false\n    print(vim.opt.smarttab:get()) -- false\n<\n\nいくつかのオプションはLuaのテーブルを使用して設定できます。:\n\n>\n    vim.opt.completeopt = {'menuone', 'noselect'}\n    print(vim.inspect(vim.opt.completeopt:get())) -- { \"menuone\", \"noselect\" }\n<\n\nlist、map、setのようなオプションのラッパーには、Vim scriptの\n`:set+=`, `:set^=`, `:set-=`と同じように動作するメソッドとメタメソッドが用意されています。\n\n>\n    vim.opt.shortmess:append({ I = true })\n    -- どちらも等価です:\n    vim.opt.shortmess = vim.opt.shortmess + { I = true }\n\n    vim.opt.whichwrap:remove({ 'b', 's' })\n    -- どちらも等価です:\n    vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' }\n<\n\n詳細は、必ず`:help vim.opt`を参照してください。\n\n参照:\n- `:help lua-vim-options`\n\n参照:\n- |lua-vim-options|\n\n==============================================================================\nvim内部の変数を管理する\n                                      *luaguide-managing-vim-internal-variables*\n\nAPI関数を使用する~\n\nオプションのように、内部変数にもAPI関数があります。\n\n- グローバル変数 (`g:`):\n    - `vim.api.nvim_set_var()`\n    - `vim.api.nvim_get_var()`\n    - `vim.api.nvim_del_var()`\n- バッファ変数 (`b:`):\n    - `vim.api.nvim_buf_set_var()`\n    - `vim.api.nvim_buf_get_var()`\n    - `vim.api.nvim_buf_del_var()`\n- ウィンドウ変数 (`w:`):\n    - `vim.api.nvim_win_set_var()`\n    - `vim.api.nvim_win_get_var()`\n    - `vim.api.nvim_win_del_var()`\n- タブ変数 (`t:`):\n    - `vim.api.nvim_tabpage_set_var()`\n    - `vim.api.nvim_tabpage_get_var()`\n    - `vim.api.nvim_tabpage_del_var()`\n- Vimの定義済み変数 (`v:`):\n    - `vim.api.nvim_set_vvar()`\n    - `vim.api.nvim_get_vvar()`\n\nVimの定義済み変数を除いて、削除できます(Vim\nscriptの`:unlet`と同様です)。\nローカル変数(`l:`)、スクリプト変数(`s:`)、関数の引数(`a:`)はVim\nscript内でのみ意味があるため操作できません。\nLuaには独自のスコープルールがあります。\n\nこれらの変数が不慣れな場合、`:h\ninternal-variables`に説明があります。\n\nこれらの関数は対象の変数名と、設定したい値を含む文字列を受け取ります。\n\n    >\n    vim.api.nvim_set_var('some_global_variable', { key1 = 'value', key2 =\n    300 })\n    print(vim.inspect(vim.api.nvim_get_var('some_global_variable'))) --\n    { key1 = \"value\", key2 = 300 }\n    vim.api.nvim_del_var('some_global_variable')\n<\n\nバッファ、ウィンドウ、タブページなスコープを持つ変数はそれぞれの番号を受け取ります(0を指定した場合は現在のバッファ/ウィンドウ/タブページが使われます。)。:\n\n    >\n    vim.api.nvim_win_set_var(0, 'some_window_variable', 2500)\n    vim.api.nvim_tab_set_var(3, 'some_tabpage_variable', 'hello world')\n    print(vim.api.nvim_win_get_var(0, 'some_window_variable')) -- 2500\n    print(vim.api.nvim_buf_get_var(3, 'some_tabpage_variable')) --\n    'hello world'\n    vim.api.nvim_win_del_var(0, 'some_window_variable')\n    vim.api.nvim_buf_del_var(3, 'some_tabpage_variable')\n<\n\nメタアクセサーを使用する~\n\n内部の変数はメタアクセサーを使用し、もっと直感的に操作できます。:\n\n- `vim.g.{name}`: グローバル変数\n- `vim.b.{name}`: バッファ変数\n- `vim.w.{name}`: ウィンドウ変数\n- `vim.t.{name}`: タブ変数\n- `vim.v.{name}`: Vimの定義済み変数\n- `vim.env.{name}`: 環境変数\n\n    >\n    vim.g.some_global_variable = {\n        key1 = 'value',\n        key2 = 300\n    }\n\n    print(vim.inspect(vim.g.some_global_variable)) -- { key1 = \"value\",\n    key2 = 300 }\n\n    -- 特定のバッファ/ウィンドウ/タブを対象とします(Neovim 0.6+)\n    vim.b[2].myvar = 1\n<\n\n一部の変数名には、Luaの識別子に使用できない文字が含まれている場合があります。\nこの構文を使用してこれらの変数を操作できます。: `vim.g['my#variable']`\n\n変数を削除するには単に`nil`を代入します。:\n\n    >\n    vim.g.some_global_variable = nil\n<\n\n警告~\n\n辞書の1つのキーを追加/更新/削除できません。例えば、次のVim\nscriptは期待通りに動きません。:\n\n    >\n    let g:variable = {}\n    lua vim.g.variable.key = 'a'\n    echo g:variable\n    \" {}\n\n\n一時的な変数を使用する回避策があります:\n\n    >\n    let g:variable = {}\n    lua << EOF\n    local tmp = vim.g.variable\n    tmp.key = 'a'\n    vim.g.variable = tmp\n    EOF\n    echo g:variable\n    \" {'key': 'a'}\n\n\n既知のissue:\n\n-  Issue #12544: https://github.com/neovim/neovim/issues/12544\n\n==============================================================================\nVim scriptの関数を呼び出す\n                                          *luaguide-calling-vimscript-functions*\n\nvim.fn.{function}()~\n\n`vim.fn`は、Vim script組込みの関数を呼び出せます。\n型はVimとLuaとで変換されます。\n\n    >\n    print(vim.fn.printf('Hello from %s', 'Lua'))\n\n    local reversed_list = vim.fn.reverse({ 'a', 'b', 'c' })\n    print(vim.inspect(reversed_list)) -- { \"c\", \"b\", \"a\" }\n\n    local function print_stdout(chan_id, data, name)\n        print(data[1])\n    end\n\n    vim.fn.jobstart('ls', { on_stdout = print_stdout })\n<\n\nハッシュ(`#`)はLuaで有効な識別子ではないため、autoload関数は次の構文で呼び出す必要があります。:\n\n    >\n    vim.fn['my#autoload#function']()\n<\n`vim.fn`は`vim.call`と同じ動作ですが、よりLuaらしい構文を使用できます。\n\n`vim.api.nvim_call_function`とは、Vim/Luaオブジェクトを自動で変換する点が異なります。:\n`vim.api.nvim_call_function`は浮動小数点数のテーブルを返しLuaのクロージャーを受け入れませんが、`vim.fn`はこれらの型を扱えます。\n\n参照:\n- |vim.fn|\n\nTips~\n\nNeovimにはプラグインに便利な強力な組込み関数を含むライブラリがあります。\nアルファベット順のリストは`:help\nvim-function`を参照してください。\n`:help function-list`は機能別に分類されたリストです。\n\nNeovimのAPI関数は`vim.api{..}`のように直接使用できます。\n詳細は`:help api`を参照してください。\n\n警告~\n\nいくつかのVim関数はbool値の変わりに`1`か`0`を返します。これは、Vim\nscriptでは`1`は真で`0`は偽になるため問題ありません。\n次のようなことが可能です。:\n\n    >\n    if has('nvim')\n        \" do something...\n    endif\n<\n\nしかし、Luaで偽になるのは`false`と`nil`のみで、数値は値に関係なく常に`true`と評価されます。\n明示的に`1`か`0`かをチェックする必要があります。:\n\n    >\n    if vim.fn.has('nvim') == 1 then\n        -- do something...\n    end\n<\n\n==============================================================================\nマッピングを定義する\n                                                    *luaguide-defining-mappings*\n\nAPI関数~\n\nNeovimはマッピングを設定、取得、削除するためのAPI関数を提供します。:\n\n- グローバルマッピング:\n    - `vim.api.nvim_set_keymap()`\n    - `vim.api.nvim_get_keymap()`\n    - `vim.api.nvim_del_keymap()`\n- バッファローカルマッピング:\n    - `vim.api.nvim_buf_set_keymap()`\n    - `vim.api.nvim_buf_get_keymap()`\n    - `vim.api.nvim_buf_del_keymap()`\n\n`vim.api.nvim_set_keymap()`と`vim.api.nvim_buf_set_keymap()`から始めましょう。\n\n最初の引数には有効にするモードの名前を含む文字列を渡します。:\n\n\n| String value           | Help page     | Affected modes                           | Vimscript equivalent |\n| ---------------------- | ------------- | ---------------------------------------- | -------------------- |\n| `''` (an empty string) | `mapmode-nvo` | Normal, Visual, Select, Operator-pending | `:map`               |\n| `'n'`                  | `mapmode-n`   | Normal                                   | `:nmap`              |\n| `'v'`                  | `mapmode-v`   | Visual and Select                        | `:vmap`              |\n| `'s'`                  | `mapmode-s`   | Select                                   | `:smap`              |\n| `'x'`                  | `mapmode-x`   | Visual                                   | `:xmap`              |\n| `'o'`                  | `mapmode-o`   | Operator-pending                         | `:omap`              |\n| `'!'`                  | `mapmode-ic`  | Insert and Command-line                  | `:map!`              |\n| `'i'`                  | `mapmode-i`   | Insert                                   | `:imap`              |\n| `'l'`                  | `mapmode-l`   | Insert, Command-line, Lang-Arg           | `:lmap`              |\n| `'c'`                  | `mapmode-c`   | Command-line                             | `:cmap`              |\n| `'t'`                  | `mapmode-t`   | Terminal                                 | `:tmap`              |\n\n2つ目の引数は、左側のマッピングを含む文字列(マッピングで定義されたコマンドを起動するためのキー)です。\n空の文字列は`<Nop>`と同じで、キーを無効にします。\n\n3つ目の引数は、右側のマッピングを含む文字列(実行するコマンド)です。\n\n最後の引数は、|:map-arguments| で定義されているbool型のオプションのテーブルです(`noremap`を含み、`buffer`を除く)。\nNeovim 0.7.0から、マッピング実行時、右側のマッピングの代わりに `callback` オプションに渡した関数を呼び出せます。\n\nバッファローカルなマッピングは、バッファ番号を引数の最初に受け取ります(`0`を指定した場合、カレントバッファです)。\n\n    >\n    vim.api.nvim_set_keymap('n', '<Leader><Space>', ':set hlsearch!<CR>',\n    { noremap = true, silent = true })\n    -- :nnoremap <silent> <Leader><Space> :set hlsearch<CR>\n    vim.api.nvim_set_keymap('n', '<Leader>tegf',  [[<Cmd>lua\n    require('telescope.builtin').git_files()<CR>]], { noremap = true,\n    silent = true })\n    -- :nnoremap <silent> <Leader>tegf <Cmd>lua\n    require('telescope.builtin').git_files()<CR>\n\n    vim.api.nvim_buf_set_keymap(0, '', 'cc', 'line(\".\") == 1 ? \"cc\" :\n    \"ggcc\"', { noremap = true, expr = true })\n    -- :noremap <buffer> <expr> cc line('.') == 1 ? 'cc' : 'ggcc'\n\n    vim.api.nvim_set_keymap('n', '<Leader>ex', '', {\n        noremap = true,\n        callback = function()\n            print('My example')\n        end,\n        -- Lua関数は便利な文字列表現を持っていないため、\n        -- \"desc\" オプションを使用してマッピングの説明を記入できます。\n        desc = 'Prints \"My example\" in the message area',\n    })\n<\n\n`vim.api.nvim_get_keymap()`は、モードの省略名(上記の表を参照)を含む文字列を受け取ります。\nそのモードにあるすべてのグローバルマッピングのテーブルを返します。\n\n    >\n    print(vim.inspect(vim.api.nvim_get_keymap('n')))\n    -- :verbose nmap\n<\n\n`vim.api.nvim_buf_get_keymap()`は、最初の引数に追加でバッファ番号を受け取ります(`0`を指定した場合、カレントバッファです)。\n\n    >\n    print(vim.inspect(vim.api.nvim_buf_get_keymap(0, 'i')))\n    -- :verbose imap <buffer>\n<\n\n`vim.api.nvim_del_keymap()`は、モードと左側のマッピングを受け取ります。\n\n    >\n    vim.api.nvim_del_keymap('n', '<Leader><Space>')\n    -- :nunmap <Leader><Space>\n<\n\nこの場合でも、`vim.api.nvim_buf_del_keymap()`は最初の引数にバッファ番号を受け取ります。`0`を指定した場合、カレントバッファです。\n\n    >\n    vim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')\n    -- :iunmap <buffer> <Tab>\n<\n\nvim.keymap~\n\n:警告: このセクションで説明するAPI関数はNeovim\n0.7.0+のみで使用できます。\n\nNeovimはマッピングを設定/削除できる2つの関数を提供します:\n- |vim.keymap.set()|\n- |vim.keymap.del()|\n\nこれらは、上記の類似API関数に糖類構文を追加したようなものです。\n\n`vim.keymap.set()`\nは最初の引数として文字列を受け取ります。\nまた、複数のモードのマッピングを1度に定義するため、文字列のテーブルを受け取ることもできます:\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>lua vim.notify(\"Example\n    1\")<CR>')\n    vim.keymap.set({'n', 'c'}, '<Leader>ex2', '<Cmd>lua\n    vim.notify(\"Example 2\")<CR>')\n<\n\n2つ目の引数は左側のマッピングです。\n\n3つ目の引数は右側のマッピングで、文字列かLua関数を受け取れます。\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>')\n    vim.keymap.set('n', '<Leader>ex2', function() print(\"Example 2\") end)\n    vim.keymap.set('n', '<Leader>pl1', require('plugin').plugin_action)\n    -- モジュールの読み込みによる起動コストを避けるため、\n    -- マッピングを呼び出したときにモジュールの遅延読みこみができるように関数でラップすることができます。:\n    vim.keymap.set('n', '<Leader>pl2', function() require('plugin').plugin_action() end)\n<\n\n4つ目の引数)省略可能)はオプションのテーブルで、 `vim.api.nvim_set_keymap`\nに渡されるオプションに対応しており、いくつか追加項目があります\n(|vim.keymap.set()|にhttps://neovim.io/doc/user/lua.html#vim.keymap.setに一覧があります)。\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>',\n    {buffer = true})\n    vim.keymap.set('n', '<Leader>ex2', function() print('Example 2')\n    end, {desc = 'Prints \"Example 2\" to the message area'})\n<\n文字列を使用して定義するキーマップとLua関数で定義したキーマップは違います。\n通常の`:nmap <Leader>ex1`のようなキーマップ情報を表示する方法では、\n`Lua function` とだけ表示され有用な情報（関数の内容自体）が表示されません。\nキーマップの動作を説明する`desc`キーを追加するのを推奨します。\nこれはプラグインのマッピングのドキュメント化に特に重要です。\nユーザーはキーマップの使用方法をより簡単に理解できます。\n\nこのAPIが面白いところとして、Vimのマッピングの歴史的な癖をいくつか解消しています。\n- `rhs` が `<Plug>` マッピングである場合以外、デフォルトで `noremap` です。\n  このため、マッピングが再帰的であるかを考える必要はあまりないです。\n\n    >\n    vim.keymap.set('n', '<Leader>test1', '<Cmd>echo \"test\"<CR>')\n    -- :nnoremap <Leader>test <Cmd>echo \"test\"<CR>\n\n    -- マッピングを再帰的に行ないたい場合は、 `remap`\n    オプションを `true` にします\n    vim.keymap.set('n', '>', ']', {remap = true})\n    -- :nmap > ]\n\n    -- <Plug> マッピングは再帰的でないと機能しませんが、 vim.keymap.set() は自動的に処理します\n    vim.keymap.set('n', '<Leader>plug', '<Plug>(plugin)')\n    -- :nmap <Leader>plug <Plug>(plugin)\n<\n\n- `expr` マッピングが有効なら、 Lua関数が返す文字列に対して `nvim_replace_termcodes()` が自動的に適用されます:\n\n    >\n    vim.keymap.set('i', '<Tab>', function()\n        return vim.fn.pumvisible == 1 and '<C-N>' or '<Tab>'\n    end, {expr = true})\n<\n\n参照:\n-  `:help recursive_mapping`:\nhttps://neovim.io/doc/user/map.html#recursive_mapping\n\n`vim.keymap.del()` も同じように機能しますが、マッピングを削除します:\n\n    >\n    vim.keymap.del('n', '<Leader>ex1')\n    vim.keymap.del({'n', 'c'}, '<Leader>ex2', {buffer = true})\n<\n\n==============================================================================\nユーザーコマンドを定義する\n                                               *luaguide-defining-user-commands*\n\nWARNING: このセクションで説明するAPI関数はNeovim 0.7.0+のみで使用できます。\n\nNeovimはユーザーコマンドを作成するAPI関数を提供します。\n\n- Global user commands:\n    - |nvim_create_user_command()|\n    - |nvim_del_user_command()|\n- Buffer-local user commands:\n    - |nvim_buf_create_user_command()|\n    - |nvim_buf_del_user_command()|\n\nまず `vim.api.nvim_create_user_command()` から始めます\n\n最初の引数はコマンドの名前です(名前は大文字で始める必要があります)。\n\n2つめの引数はコマンドが呼びだされたときに実行するコードです。次のどちらかでコードを指定できます:\n\n文字列(この場合、VimScriptとして実行されます)。\n`:commands` のように、`<q-args>`, `<range>` などのエスケープシーケンスを使用できます。\n    >\n    vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)', {\n    nargs = 1 })\n    -- :command! -nargs=1 Upper echo toupper(<q-args>)\n\n    vim.cmd('Upper hello world') -- prints \"HELLO WORLD\"\n<\n\nもしくは、Lua関数。\n通常のエスケープシーケンスによって提供されるデータを含む、 辞書のようなテーブルを受け取ります\n(利用できるキーのリストは|nvim_create_user_command()|で確認できます)。\n    >\n    vim.api.nvim_create_user_command(\n        'Upper',\n        function(opts)\n            print(string.upper(opts.args))\n        end,\n        { nargs = 1 }\n    )\n<\n\n3つめの引数はコマンドの属性をテーブルとして渡せます(|command-attributes|を参照)。\n`vim.api.nvim_buf_create_user_command()`を使用すればバッファローカルなユーザーコマンドを定義できるため、\n`-buffer`は有効な属性ではありません。\n\n追加された2つの属性:\n- `desc`はLuaのコールバックとして定義されたコマンドに対して`:command {cmd}`を実行したときの表示内容を制御できます。\n  キーマップと同様、Lua関数として定義するコマンドには `desc`キーを追加するのを推奨します。\n- `force`は`:command!`を呼び出すのと同じで、同じ名前のユーザーコマンドが既に存在する場合、そのコマンドを置き換えます。\n  Vimscriptとは異なり、デフォルトでtrueです。\n\n`-complete`属性は|:command-complete|に記載されている属性に加え、Lua関数を取ることができます。\n\n    >\n    vim.api.nvim_create_user_command('Upper', function() end, {\n        nargs = 1,\n        complete = function(ArgLead, CmdLine, CursorPos)\n            -- return completion candidates as a list-like table\n            return { 'foo', 'bar', 'baz' }\n        end,\n    })\n<\n\nバッファローカルなユーザーコマンドも第1引数にバッファ番号を受け取ります。\n現在のバッファ用のコマンドを定義することができる`-buffer`より、これは便利です。\n\n    >\n    vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})\n<\n\n`vim.api.nvim_del_user_command()` はコマンド名を受け取ります。\n\n    >\n    vim.api.nvim_del_user_command('Upper')\n    -- :delcommand Upper\n<\n\nここでも、`vim.api.nvim_buf_del_user_command()`はバッファ番号を第1引数として受け取り、`0`は現在のバッファを表します。\n\n    >\n    vim.api.nvim_buf_del_user_command(4, 'Upper')\n<\n\n参照:\n- |nvim_create_user_command()|\n- |40.2|\n- |command-attributes|\n\n警告~\n\n`-complete=custom`属性は自動的に補完候補をフィルタリングし、\nワイルドカード(|wildcard|)をサポートする機能を組み込みます:\n\n    >\n    function! s:completion_function(ArgLead, CmdLine, CursorPos) abort\n        return join([\n            \\ 'strawberry',\n            \\ 'star',\n            \\ 'stellar',\n            \\ ], \"\\n\")\n    endfunction\n\n    command! -nargs=1 -complete=custom,s:completion_function Test echo\n    <q-args>\n    \" `:Test st[ae]<Tab>` と入力すると \"star\" と \"stellar\" を返します\n<\n\n`complete` にLua関数に渡すと、ユーザーにフィルタ方法を任せる`customlist`のような動作をします。\n\n    >\n    vim.api.nvim_create_user_command('Test', function() end, {\n        nargs = 1,\n        complete = function(ArgLead, CmdLine, CursorPos)\n            return {\n                'strawberry',\n                'star',\n                'stellar',\n            }\n        end,\n    })\n\n    -- 候補リストをフィルタしてないので `:Test z<Tab>` と入力すると全ての補完候補を返します\n<\n\n==============================================================================\nオートコマンドを定義する\n                                                *luaguide-defining-autocommands*\n\n(この章は現在作成中です)\n\nNeovim 0.7.0はオートコマンド用のAPI関数を持っています。詳細は|api-autocmd|を参照してください。\n\n- Pull request #14661: https://github.com/neovim/neovim/pull/14661 (lua: autocmds take 2)\n\n==============================================================================\nハイライトを定義する\n                                           *luaguide-defining-syntax-highlights*\n\n(この章は現在作成中です)\n\nNeovim 0.7.0はハイライトグループ用のAPI関数を持っています。\n\n参照:\n- |nvim_set_hl()|\n- |nvim_get_hl_by_id()|\n- |nvim_get_hl_by_name()|\n\n==============================================================================\n一般的なTipsと推奨\n                                     *luaguide-general-tips-and-recommendations*\n\n\nキャッシュされたモジュールのリロード~\n\nLuaでは、`require()`関数がモジュールをキャッシュします。\nこれはパフォーマンスには良いですが、後から`require()`を呼んでもモジュールは更新されないため少し面倒です。\n\n特定のモジュールのキャッシュを更新する場合、`package.loaded`グローバルテーブルを変更する必要があります。:\n\n    >\n    package.loaded['modname'] = nil\n    require('modname') -- 新しい'modname'モジュールを読み込みます\n<\n\nnvim-lua/plenary.nvim: https://github.com/nvim-lua/plenary.nvim には、これを行う関数:\nhttps://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/reload.lua があります。\n\nLuaの文字列をパディングしないでください!~\n\n二重括弧の文字列を使用するとき、パディングの誘惑に負けないでください!\nスペースを無視するときは問題ないですが、スペースが重要な意味を持つときはデバックが困難な問題の原因になる可能性があります。:\n\n    >\n    vim.api.nvim_set_keymap('n', '<Leader>f', [[ <Cmd>call foo()<CR>\n    ]], {noremap = true})\n<\n\n上記の例では、`<Leader>f`は`<Cmd>call foo()<CR>`ではなく`<Space><Cmd>call foo()<CR><Space>`にマッピングされます。\n\nVim script <--> Lua 型変換の注意~\n\n\n変数を変換するとコピーが作られます:~\n\nVimからLua、LuaからVimのオブジェクトの参照を直接操作できません。\n例えば、Vim scriptの`map()`は変数をその場で変更します(破壊的)。\n\n    >\n    let s:list = [1, 2, 3]\n    let s:newlist = map(s:list, {_, v -> v * 2})\n\n    echo s:list\n    \" [2, 4, 6]\n    echo s:newlist\n    \" [2, 4, 6]\n    echo s:list is# s:newlist\n    \" 1\n<\n\nLuaからこの関数を使用すると、代りにコピーが作られます\n\n    >\n    local tbl = {1, 2, 3}\n    local newtbl = vim.fn.map(tbl, function(_, v) return v * 2 end)\n\n    print(vim.inspect(tbl)) -- { 1, 2, 3 }\n    print(vim.inspect(newtbl)) -- { 2, 4, 6 }\n    print(tbl == newtbl) -- false\n<\n\n変換を常にできるとは限りません~\n\nこれは主に関数とテーブルに影響します。\n\nLuaのリストと辞書が混在するテーブルは変換できません。\n\n    >\n    print(vim.fn.count({1, 1, number = 1}, 1))\n    -- E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys\n<\n\nLuaで`vim.fn`を使用してVim関数を呼べますが、それらの参照を保持できません。\nそれは不測の動作の原因になります。:\n\n    >\n    local FugitiveHead = vim.fn.funcref('FugitiveHead')\n    print(FugitiveHead) -- vim.NIL\n\n    vim.cmd(\"let g:test_dict = {'test_lambda': {-> 1}}\")\n    print(vim.g.test_dict.test_lambda) -- nil\n    print(vim.inspect(vim.g.test_dict)) -- {}\n<\n\nLuaの関数をVimの関数に渡せますが、Vimの変数に格納できません。\n(Neovim 0.7.0+で修正されて、格納できるようになりました。)\n\n\n    >\n    -- This works:\n    vim.fn.jobstart({'ls'}, {\n        on_stdout = function(chan_id, data, name)\n            print(vim.inspect(data))\n        end\n    })\n\n    -- This doesn't:\n    vim.g.test_dict = {test_lambda = function() return 1 end} -- Error: Cannot convert given lua type\n<\n\nただし、Vim scriptから`luaeval()`を使用して同じことをすると**動作します**。:\n\n    >\n    let g:test_dict = {'test_lambda': luaeval('function() return 1 end')}\n    echo g:test_dict\n    \" {'test_lambda': function('<lambda>4714')}\n<\n\nVim booleans~\nVim scriptの一般的なパターンではbool値の代わりに`1`と`0`を使用します。\n実際、Vimにはバージョン7.4.1154まで区別されたbool型がありませんでした。\n\nLuaのbool値は数値ではなく、Vim scriptの実際のbool値に変換されます。:\n\n    >\n    lua vim.g.lua_true = true\n    echo g:lua_true\n    \" v:true\n    lua vim.g.lua_false = false\n    echo g:lua_false\n    \" v:false\n<\n\nリンターと言語サーバーの設定~\n\nLuaのプロジェクトでリンターや言語サーバーを使用して、診断と自動補完を利用している場合、Neovim固有の設定が必要になる場合があります。人気のあるツールの推奨設定は次のとおりです。:\n\nluacheck~\n\n次の設定を `~/.luacheckrc`  もしくは `$XDG_CONFIG_HOME/luacheck/.luacheckrc` に配置すれば、 luacheck: https://github.com/mpeterv/luacheck/ でvimモジュールを認識できます。:\n\n\n    >\n    globals = {\n        \"vim\",\n    }\n<\n\n言語サーバーの Alloyed/lua-lsp: https://github.com/Alloyed/lua-lsp/ は `luacheck` を使用してリンティングを提供し、同じファイルを読み込みます。\n\n`luacheck` の設定方法の詳細は ドキュメント: https://luacheck.readthedocs.io/en/stable/config.html を参照してください。\n\nsumneko/lua-language-server~\n\nnvim-lspconfig: https://github.com/neovim/nvim-lspconfig/ リポジトリに sumneko/lua-language-serverの設定方法: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua があります。例は組込みのLSPクライアントを使っていますが、他のLSPクライアントでも同じ設定である必要があります。\n\nsumneko/lua-language-server: https://github.com/sumneko/lua-language-server/ の設定方法の詳細は \"Setting\": https://github.com/sumneko/lua-language-server/wiki/Setting を見てください。\n\ncoc.nvim~\n\ncoc.nvim: https://github.com/neoclide/coc.nvim/ の補完ソースである rafcamlet/coc-nvim-lua: https://github.com/rafcamlet/coc-nvim-lua/ はNeovim stdlibの項目を提供しています。\n\nLuaコードのデバッグ~\n\n別のNeovimインスタンスで実行しているLuaコードを jbyuki/one-small-step-for-vimkind:\nhttps://github.com/jbyuki/one-small-step-for-vimkind でデバッグできます。\n\nこのプラグインは Debug Adapter Protocol: https://microsoft.github.io/debug-adapter-protocol/ を使用しています。\nデバッグアダプターに接続するには、 mfussenegger/nvim-dap: https://github.com/mfussenegger/nvim-dap/ や\npuremourning/vimspector: https://github.com/puremourning/vimspector/ のようなDAPクライアントが必要です。\n\nLuaマッピング/コマンド/オートコマンドのデバッグ~\n\nマッピング/コマンド/オートコマンドが定義されている位置を `:verbose` コマンドで確認できます:\n\n    >\n    :verbose map m\n<\n\n    >\n    n  m_          * <Cmd>echo 'example'<CR>\n            Last set from ~/.config/nvim/init.vim line 26\n<\n\nデフォルトでは、Luaのパフォーマンス上の理由でこの機能は無効です。\nNeovim起動時にverboseのレベルが0より上なら、この機能を有効にできます:\n\n    >\n    nvim -V1\n<\n\n参照:\n- |'verbose'|\n- |-V|\n-  neovim/neovim#15079: https://github.com/neovim/neovim/pull/15079\n\nLuaコードのテスト~\n\n-  plenary.nvim: test harness:\nhttps://github.com/nvim-lua/plenary.nvim/#plenarytest_harness\n-  notomo/vusted: https://github.com/notomo/vusted\n\nLuarocksパッケージを使用する~\n\nwbthomason/packer.nvim: https://github.com/wbthomason/packer.nvim はLuarocksパッケージをサポートしています。\n使い方はREADME: https://github.com/wbthomason/packer.nvim/#luarocks-support にあります。\n\n==============================================================================\nその他\n                                                        *luaguide-miscellaneous*\n\nvim.loop~\n\n`vim.loop`はLibUV\nAPIを公開するモジュールです。いくつかのリソース:\n\n-  Official documentation for LibUV: https://docs.libuv.org/en/v1.x/\n-  Luv documentation: https://github.com/luvit/luv/blob/master/docs.md\n-  teukka.tech - Using LibUV in Neovim: https://teukka.tech/posts/2020-01-07-vimloop/\n\n参照:\n- |vim.loop|\n\nvim.lsp~\n\n`vim.lsp`は組込みのLSPクライアントを操作するためのモジュールです。\n neovim/nvim-lspconfig: https://github.com/neovim/nvim-lspconfig/\n は有名なLanguage Serverの設定集です。\n\nクライアントの動作は\"lsp-handlers\"を使用して設定できます。詳細はこちら:\n- |lsp-handler|\n-  neovim/neovim#12655: https://github.com/neovim/neovim/pull/12655\n-  How to migrate from diagnostic-nvim:\nhttps://github.com/nvim-lua/diagnostic-nvim/issues/73#issue-737897078\n\n\nLSPクライアントを利用したプラグインも見たいかもしれません。:\nhttps://github.com/rockerBOO/awesome-neovim#lsp\n\n参照:\n- |lsp|\n\nvim.treesitter~\n\n`vim.treesitter`はNeovim内の Tree-sitter:\nhttps://tree-sitter.github.io/tree-sitter/\nライブラリを操作するためのモジュールです。\nTree-sitterについてもっと知りたいなら、この\nプレゼン  38:37 : https://www.youtube.com/watch?v=Jes3bD6P0To\nに興味があるかもしれません。\n\n nvim-treesitter: https://github.com/nvim-treesitter/\n オリジネーションは、ライブラリを利用して様々なプラグインをホストしています。\n\n参照:\n- |lua-treesitter|\n\nトランスパイラ~\n\nLuaを使用する利点の1つは実際にLuaを書く必要がないことです！利用できるトランスパイラはたくさんあります。\n\n-  Moonscript: https://moonscript.org/\n\nおそらく、最も知られているLuaのトランスパイラです。クラス、リスト内包表記、関数リテラルなどの便利な機能を多数追加します。\n svermeulen/nvim-moonmaker: https://github.com/svermeulen/nvim-moonmaker\n はNeovimのプラグインと設定をMoonscriptで直接書けるようにします。\n\n-  Fennel: https://fennel-lang.org/\n\nlispをLuaにコンパイルします。\nOlical/aniseed: https://github.com/Olical/aniseed\nまたは、Hotpot: https://github.com/rktjmp/hotpot.nvim\nを使用するとNeovimのプラグインと設定を書くことができます。\nさらに、 Olical/conjure: https://github.com/Olical/conjure\nは対話的な開発環境を提供します 他の言語の中で 。\n\n- Teal: https://github.com/teal-language/tl\n\nTealの名前の由来はTL(typed lua)の発音からです。\nまさにその通りで、強力な型をLuaに追加し、それ以外は標準のLuaの構文に近づけています。\nnvim-teal-maker https://github.com/svermeulen/nvim-teal-maker プラグインを使用して、\nTealでNeovimプラグインや設定ファイルを書けます。\n\nその他の興味深いプロジェクト:\n-  TypeScriptToLua/TypeScriptToLua:\nhttps://github.com/TypeScriptToLua/TypeScriptToLua\n-  Haxe: https://haxe.org/\n-  SwadicalRag/wasm2lua: https://github.com/SwadicalRag/wasm2lua\n-  hengestone/lua-languages: https://github.com/hengestone/lua-languages\n\nvim:tw=78:ts=8:noet:ft=help:norl:\n"
  },
  {
    "path": "doc/nvim-lua-guide.txt",
    "content": "*nvim-lua-guide.txt*  Getting started using Lua in Neovim\n\n==============================================================================\nINTRODUCTION\n                                                         *luaguide-introduction*\n\nThe  integration of Lua: https://www.youtube.com/watch?v=IP3J56sKtn0\nas a  first-class language inside Neovim:\nhttps://github.com/neovim/neovim/wiki/FAQ#why-embed-lua-instead-of-x\nis shaping up to be one of its killer features.\nHowever, the amount of teaching material for learning how to write\nplugins in Lua is not as large as what you would find for writing them\nin Vimscript. This is an attempt at providing some basic information to\nget people started.\n\nThis guide assumes you are using at least version 0.5 of Neovim.\n\nLearning Lua~\n\nIf you are not already familiar with the language, there are plenty of\nresources to get started:\n\n- The  Learn X in Y minutes page about Lua:\nhttps://learnxinyminutes.com/docs/lua/  should give you a quick overview\nof the basics\n-  This guide:\nhttps://github.com/medwatt/Notes/blob/main/Lua/Lua_Quick_Guide.ipynb\nis also a good resource for getting started quickly\n- If videos are more to your liking, Derek Banas has a  1-hour tutorial\non the language: https://www.youtube.com/watch?v=iMacxZQMPXs\n- Want something a little more interactive with runnable examples? Try\nthe LuaScript tutorial: https://www.luascript.dev/learn\n- The  lua-users wiki: http://lua-users.org/wiki/LuaDirectory  is full\nof useful information on all kinds of Lua-related topics\n- The  official reference manual for Lua: https://www.lua.org/manual/5.1/\nshould give you the most comprehensive tour of the language  exists as\na Vimdoc plugin if you want to read it from the comfort of your editor:\nmilisims/nvim-luaref: https://github.com/milisims/nvim-luaref\n\nIt should also be noted that Lua is a very clean and simple language. It\nis easy to learn, especially if you have experience with similar scripting\nlanguages like JavaScript. You may already know more Lua than you realise!\n\nNote: the version of Lua that Neovim embeds is  LuaJIT:\nhttps://staff.fnwi.uva.nl/h.vandermeer/docs/lua/luajit/luajit_intro.html\n2.1.0, which maintains compatibility with Lua 5.1.\n\nExisting tutorials for writing Lua in Neovim~\n\nA few tutorials have already been written to help people write plugins\nin Lua. Some of them helped quite a bit when writing this guide. Many\nthanks to their authors.\n\n-  teukka.tech - From init.vim to init.lua:\nhttps://teukka.tech/luanvim.html\n-  dev.to - How to write neovim plugins in Lua:\nhttps://dev.to/2nit/how-to-write-neovim-plugins-in-lua-5cca\n-  dev.to - How to make UI for neovim plugins in Lua:\nhttps://dev.to/2nit/how-to-make-ui-for-neovim-plugins-in-lua-3b6e\n-  ms-jpq - Neovim Async Tutorial:\nhttps://github.com/ms-jpq/neovim-async-tutorial\n-  oroques.dev - Neovim 0.5 features and the switch to init.lua:\nhttps://oroques.dev/notes/neovim-init/\n-  Building A Vim Statusline from Scratch - jdhao's blog:\nhttps://jdhao.github.io/2019/11/03/vim_custom_statusline/\n-  Configuring Neovim using Lua: https://icyphox.sh/blog/nvim-lua/\n-  Devlog | Everything you need to know to configure neovim using lua:\nhttps://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/\n\nCompanion plugins~\n\n-  Vimpeccable: https://github.com/svermeulen/vimpeccable  - Plugin to\nhelp write your .vimrc in Lua\n-  plenary.nvim: https://github.com/nvim-lua/plenary.nvim  - All the\nlua functions I don't want to write twice\n-  popup.nvim: https://github.com/nvim-lua/popup.nvim  - An implementation\nof the Popup API from vim in Neovim\n-  nvim_utils: https://github.com/norcalli/nvim_utils\n-  nvim-luadev: https://github.com/bfredl/nvim-luadev  - REPL/debug\nconsole for nvim lua plugins\n-  nvim-luapad: https://github.com/rafcamlet/nvim-luapad  - Interactive\nreal time neovim scratchpad for embedded lua engine\n-  nlua.nvim: https://github.com/tjdevries/nlua.nvim  - Lua Development\nfor Neovim\n-  BetterLua.vim: https://github.com/euclidianAce/BetterLua.vim  -\nBetter Lua syntax highlighting in Vim/NeoVim\n\n==============================================================================\nWHERE TO PUT LUA FILES\n                                               *luaguide-where-to-put-lua-files*\n\ninit.lua~\n\nNeovim supports loading an `init.lua` file for configuration instead of\nthe usual `init.vim`.\n\nNote: `init.lua` is of course _completely_ optional. Support\nfor `init.vim` is not going away and is still a valid option for\nconfiguration. Do keep in mind that some features are not 100% exposed\nto Lua yet.\n\nSee also:\n- |config|\n\nModules~\n\nLua modules are found inside a `lua/` folder in your `'runtimepath'`\n(for most users, this will mean `~/.config/nvim/lua` on \\*nix systems\nand `~/AppData/Local/nvim/lua` on Windows). You can `require()` files\nin this folder as Lua modules.\n\nLet's take the following folder structure as an example:\n\n    >\n    📂 ~/.config/nvim\n    ├── 📁 after\n    ├── 📁 ftplugin\n    ├── 📂 lua\n    │  ├── 🌑 myluamodule.lua\n    │  └── 📂 other_modules\n    │     ├── 🌑 anothermodule.lua\n    │     └── 🌑 init.lua\n    ├── 📁 pack\n    ├── 📁 plugin\n    ├── 📁 syntax\n    └── 🇻 init.vim\n<\n\nThe following Lua code will load `myluamodule.lua`:\n\n    >\n    require('myluamodule')\n<\n\nNotice the absence of a `.lua` extension.\n\nSimilarly, loading `other_modules/anothermodule.lua` is done like so:\n\n    >\n    require('other_modules.anothermodule')\n    -- or\n    require('other_modules/anothermodule')\n<\n\nPath separators are denoted by either a dot `.` or a slash `/`.\n\nA folder containing an `init.lua` file can be required directly, without\nhaving to specify the name of the file.\n\n    >\n    require('other_modules') -- loads other_modules/init.lua\n<\n\nRequiring a nonexistent module or a module which contains syntax errors\naborts the currently executing script.\n`pcall()` may be used to prevent errors.\n\n    >\n    local ok, _ = pcall(require, 'module_with_error')\n    if not ok then\n      -- not loaded\n    end\n<\n\nSee also:\n- |lua-require|\n\nTips~\n\nSeveral Lua plugins might have identical filenames in their `lua/`\nfolder. This could lead to namespace clashes.\n\nIf two different plugins have a `lua/main.lua` file, then doing\n`require('main')` is ambiguous: which file do we want to source?\n\nIt might be a good idea to namespace your config or your plugin with a\ntop-level folder, like so: `lua/plugin_name/main.lua`\n\nRuntime files~\n\nMuch like Vimscript files, Lua files can be loaded automatically from\nspecial folders in your `runtimepath`. Currently, the following folders\nare supported:\n\n- `colors/`\n- `compiler/`\n- `ftplugin/`\n- `ftdetect/`\n- `indent/`\n- `plugin/`\n- `syntax/`\n\nNote: in a runtime directory, all `*.vim` files are sourced before\n`*.lua` files.\n\nSee also:\n- |'runtimepath'|\n- |load-plugins|\n\nTips~\n\nSince runtime files aren't based on the Lua module system, two plugins\ncan have a `plugin/main.lua` file without it being an issue.\n\n==============================================================================\nUSING LUA FROM VIMSCRIPT\n                                             *luaguide-using-lua-from-vimscript*\n\n:lua~\n\nThis command executes a chunk of Lua code.\n\n    >\n    :lua require('myluamodule')\n<\n\nMulti-line scripts are possible using heredoc syntax:\n\n    >\n    echo \"Here's a bigger chunk of Lua code\"\n\n    lua << EOF\n    local mod = require('mymodule')\n    local tbl = {1, 2, 3}\n\n    for k, v in ipairs(tbl) do\n        mod.method(v)\n    end\n\n    print(tbl)\n    EOF\n<\n\nNote: each `:lua` command has its own scope and variables declared with\nthe `local` keyword are not accessible outside of the command. This\nwon't work:\n\n    >\n    :lua local foo = 1\n    :lua print(foo)\n    \" prints 'nil' instead of '1'\n<\n\nNote 2: the `print()` function in Lua behaves similarly to the `:echomsg`\ncommand. Its output is saved in the message-history and can be suppressed\nby the `:silent` command.\n\nSee also:\n\n- |:lua|\n- |:lua-heredoc|\n\n:luado~\n\nThis command executes a chunk of Lua code that acts on a range of lines\nin the current buffer. If no range is specified, the whole buffer is\nused instead. Whatever string is `return`ed from the chunk is used to\ndetermine what each line should be replaced with.\n\nThe following command would replace every line in the current buffer\nwith the text `hello world`:\n\n    >\n    :luado return 'hello world'\n<\n\nTwo implicit `line` and `linenr` variables are also provided. `line`\nis the text of the line being iterated upon whereas `linenr` is its\nnumber. The following command would make every line whose number is\ndivisible by 2 uppercase:\n\n    >\n    :luado if linenr % 2 == 0 then return line:upper() end\n<\n\nSee also:\n\n- |:luado|\n\nSourcing Lua files~\n\nNeovim provides 3 Ex commands to source Lua files\n\n- `:luafile`\n- `:source`\n- `:runtime`\n\n`:luafile` and `:source` are very similar:\n\n    >\n    :luafile ~/foo/bar/baz/myluafile.lua\n    :luafile %\n    :source ~/foo/bar/baz/myluafile.lua\n    :source %\n<\n\n`:source` also supports ranges, which can be useful to only execute part\nof a script:\n\n    >\n    :1,10source\n<\n\n`:runtime` is a little different: it uses the `'runtimepath'` option to\ndetermine which files to source. See |:runtime| for more details.\n\nSee also:\n\n- |:luafile|\n- |:source|\n- |:runtime|\n\nSourcing a lua file vs calling require():~\n\nYou might be wondering what the difference between calling the `require()`\nfunction and sourcing a Lua file is and whether you should prefer one\nway over the other. They have different use cases:\n\n- `require()`:\n    - is a built-in Lua function. It allows you to take advantage of\n    Lua's module system\n    - searches for modules in `lua/` folders in your `'runtimepath'`\n    - keeps track of what modules have been loaded and prevents a script\n    from being parsed and executed a second time. If you change the file\n    containing the code for a module and try to `require()` it a second\n    time while Neovim is running, the module will not actually update\n- `:luafile`, `:source` and `:runtime`:\n    - are Ex commands. They do not support modules\n    - execute the contents of a script regardless of whether it has been\n    executed before\n    - `:luafile` and `:source` take a path that is either absolute or\n    relative to the working directory of the current window\n    - `:runtime` uses the `'runtimepath'` option to find files\n\nFiles sourced via `:source`, `:runtime` or automatically from runtime\ndirectories will also show up in `:scriptnames` and `--startuptime`\n\nluaeval()~\n\nThis built-in Vimscript function evaluates a Lua expression string\nand returns its value. Lua data types are automatically converted to\nVimscript types (and vice versa).\n\n    >\n    \" You can store the result in a variable\n    let variable = luaeval('1 + 1')\n    echo variable\n    \" 2\n    let concat = luaeval('\"Lua\"..\" is \"..\"awesome\"')\n    echo concat\n    \" 'Lua is awesome'\n\n    \" List-like tables are converted to Vim lists\n    let list = luaeval('{1, 2, 3, 4}')\n    echo list[0]\n    \" 1\n    echo list[1]\n    \" 2\n    \" Note that unlike Lua tables, Vim lists are 0-indexed\n\n    \" Dict-like tables are converted to Vim dictionaries\n    let dict = luaeval('{foo = \"bar\", baz = \"qux\"}')\n    echo dict.foo\n    \" 'bar'\n\n    \" Same thing for booleans and nil\n    echo luaeval('true')\n    \" v:true\n    echo luaeval('nil')\n    \" v:null\n\n    \" You can create Vimscript aliases for Lua functions\n    let LuaMathPow = luaeval('math.pow')\n    echo LuaMathPow(2, 2)\n    \" 4\n    let LuaModuleFunction = luaeval('require(\"mymodule\").myfunction')\n    call LuaModuleFunction()\n\n    \" It is also possible to pass Lua functions as values to Vim functions\n    lua X = function(k, v) return string.format(\"%s:%s\", k, v) end\n    echo map([1, 2, 3], luaeval(\"X\"))\n<\n\n`luaeval()` takes an optional second argument that allows you to pass\ndata to the expression. You can then access that data from Lua using\nthe magic global `_A`:\n\n    >\n    echo luaeval('_A[1] + _A[2]', [1, 1])\n    \" 2\n\n    echo luaeval('string.format(\"Lua is %s\", _A)', 'awesome')\n    \" 'Lua is awesome'\n<\n\nSee also:\n- |luaeval()|\n\nv:lua~\n\nThis global Vim variable allows you to call Lua functions in the global\nnamespace   `_G`: https://www.lua.org/manual/5.1/manual.html#pdf-_G\ndirectly from Vimscript. Again, Vim data types are converted to Lua\ntypes and vice versa.\n\n    >\n    call v:lua.print('Hello from Lua!')\n    \" 'Hello from Lua!'\n\n    let scream = v:lua.string.rep('A', 10)\n    echo scream\n    \" 'AAAAAAAAAA'\n\n    \" How about a nice statusline?\n    lua << EOF\n    function _G.statusline()\n        local filepath = '%f'\n        local align_section = '%='\n        local percentage_through_file = '%p%%'\n        return string.format(\n            '%s%s%s',\n            filepath,\n            align_section,\n            percentage_through_file\n        )\n    end\n    EOF\n\n    set statusline=%!v:lua.statusline()\n\n    \" Also works in expression mappings\n    lua << EOF\n    function _G.check_back_space()\n        local col = vim.api.nvim_win_get_cursor(0)[2]\n        return (col == 0 or vim.api.nvim_get_current_line():sub(col,\n        col):match('%s')) and true\n    end\n    EOF\n\n    inoremap <silent> <expr> <Tab>\n        \\ pumvisible() ? \"\\<C-N>\" :\n        \\ v:lua.check_back_space() ? \"\\<Tab>\" :\n        \\ completion#trigger_completion()\n\n    \" Call a function from a Lua module by using single quotes and\n    omitting parentheses:\n    call v:lua.require'module'.foo()\n<\n\nSee also:\n- |v:lua|\n- |v:lua-call|\n\nCaveats~\n\nThis variable can only be used to call functions. The following will\nalways throw an error:\n\n    >\n    \" Aliasing functions doesn't work\n    let LuaPrint = v:lua.print\n\n    \" Accessing dictionaries doesn't work\n    echo v:lua.some_global_dict['key']\n\n    \" Using a function as a value doesn't work\n    echo map([1, 2, 3], v:lua.global_callback)\n<\n\nTips~\n\nYou can get Lua syntax highlighting inside .vim files by putting `let\ng:vimsyn_embed = 'l'` in your configuration file. See |g:vimsyn_embed|\nfor more on this option.\n\n==============================================================================\nTHE VIM NAMESPACE\n                                                    *luaguide-the-vim-namespace*\n\nNeovim exposes a global `vim` variable which serves as an entry point\nto interact with its APIs from Lua. It provides users with an extended\n\"standard library\" of functions as well as various sub-modules.\n\nSome notable functions and modules include:\n\n- `vim.inspect`: transform Lua objects into human-readable strings\n(useful for inspecting tables)\n- `vim.regex`: use Vim regexes from Lua\n- `vim.api`: module that exposes API functions (the same API used by\nremote plugins)\n- `vim.ui`: overridable UI functions that can be leveraged by plugins\n- `vim.loop`: module that exposes the functionality of Neovim's event-loop\n(using LibUV)\n- `vim.lsp`: module that controls the built-in LSP client\n- `vim.treesitter`: module that exposes the functionality of the\ntree-sitter library\n\nThis list is by no means comprehensive. If you wish to know more about what's\nmade available by the `vim` variable, |lua-stdlib| and |lua-vim| are the way\nto go. Alternatively, you can do `:lua print(vim.inspect(vim))` to get a list\nof every module. API functions are documented under |api-global|.\n\nTips~\n\nWriting `print(vim.inspect(x))` every time you want to inspect the\ncontents of an object can get pretty tedious. It might be worthwhile\nto have a global wrapper function somewhere in your configuration (in\nNeovim 0.7.0+, this function is built-in, see |vim.pretty_print()|:\n\n    >\n    function _G.put(...)\n      local objects = {}\n      for i = 1, select('#', ...) do\n        local v = select(i, ...)\n        table.insert(objects, vim.inspect(v))\n      end\n\n      print(table.concat(objects, '\\n'))\n      return ...\n    end\n<\n\nYou can then inspect the contents of an object very quickly in your code\nor from the command-line:\n\n    >\n    put({1, 2, 3})\n<\n\n    >\n    :lua put(vim.loop)\n<\n\nAlternatively, you can use the `:lua` command to pretty-print a Lua\nexpression by prefixing it with `=` (Neovim 0.7+ only):\n    >\n    :lua =vim.loop\n<\n\nAdditionally, you may find that built-in Lua functions are sometimes\nlacking compared to what you would find in other languages (for example\n`os.clock()` only returns a value in seconds, not milliseconds). Be\nsure to look at the Neovim stdlib (and `vim.fn`, more on that later),\nit probably has what you're looking for.\n\n==============================================================================\nUSING VIMSCRIPT FROM LUA\n                                             *luaguide-using-vimscript-from-lua*\n\nvim.api.nvim_eval()~\n\nThis function evaluates a Vimscript expression string and returns its\nvalue. Vimscript data types are automatically converted to Lua types\n(and vice versa).\n\nIt is the Lua equivalent of the `luaeval()` function in Vimscript\n\n    >\n    -- Data types are converted correctly\n    print(vim.api.nvim_eval('1 + 1')) -- 2\n    print(vim.inspect(vim.api.nvim_eval('[1, 2, 3]'))) -- { 1, 2, 3 }\n    print(vim.inspect(vim.api.nvim_eval('{\"foo\": \"bar\", \"baz\": \"qux\"}')))\n    -- { baz = \"qux\", foo = \"bar\" }\n    print(vim.api.nvim_eval('v:true')) -- true\n    print(vim.api.nvim_eval('v:null')) -- nil\n<\n\nCaveats~\n\nUnlike `luaeval()`, `vim.api.nvim_eval()` does not provide an implicit\n`_A` variable to pass data to the expression.\n\nvim.api.nvim_exec()~\n\nThis function evaluates a chunk of Vimscript code. It takes in a string\ncontaining the source code to execute and a boolean to determine whether\nthe output of the code should be returned by the function (you can then\nstore the output in a variable, for example).\n\n    >\n    local result = vim.api.nvim_exec(\n    [[\n    let s:mytext = 'hello world'\n\n    function! s:MyFunction(text)\n        echo a:text\n    endfunction\n\n    call s:MyFunction(s:mytext)\n    ]],\n    true)\n\n    print(result) -- 'hello world'\n<\n\nCaveats~\n\n`nvim_exec` does not support script-local variables (`s:`) prior to\nNeovim 0.6.0\n\nvim.api.nvim_command()~\n\nThis function executes an ex command. It takes in a string containing\nthe command to execute.\n\n    >\n    vim.api.nvim_command('new')\n    vim.api.nvim_command('wincmd H')\n    vim.api.nvim_command('set nonumber')\n    vim.api.nvim_command('%s/foo/bar/g')\n<\n\nvim.cmd()~\n\nAlias for `vim.api.nvim_exec()`. Only the command argument is needed,\n`output` is always set to `false`.\n\n    >\n    vim.cmd('buffers')\n    vim.cmd([[\n    let g:multiline_list = [\n                \\ 1,\n                \\ 2,\n                \\ 3,\n                \\ ]\n\n    echo g:multiline_list\n    ]])\n<\n\nTips~\n\nSince you have to pass strings to these functions, you often end up\nhaving to escape backslashes:\n\n    >\n    vim.cmd('%s/\\\\Vfoo/bar/g')\n<\n\nDouble bracketed strings are easier to use as they do not require\nescaping characters:\n\n    >\n    vim.cmd([[%s/\\Vfoo/bar/g]])\n<\n\nvim.api.nvim_replace_termcodes()~\n\nThis API function allows you to escape terminal codes and Vim keycodes.\n\nYou may have come across mappings like this one:\n\n    >\n    inoremap <expr> <Tab> pumvisible() ? \"\\<C-N>\" : \"\\<Tab>\"\n<\n\nTrying to do the same in Lua can prove to be a challenge. You might be\ntempted to do it like this:\n\n    >\n    function _G.smart_tab()\n        return vim.fn.pumvisible() == 1 and [[\\<C-N>]] or [[\\<Tab>]]\n    end\n\n    vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr =\n    true, noremap = true})\n<\n\nonly to find out that the mapping inserts `\\<Tab>` and `\\<C-N>`\nliterally...\n\nBeing able to escape keycodes is actually a Vimscript feature. Aside\nfrom the usual escape sequences like `\\r`, `\\42` or `\\x10` that are\ncommon to many programming languages, Vimscript `expr-quotes` (strings\nsurrounded with double quotes) allow you to escape the human-readable\nrepresentation of Vim keycodes.\n\nLua doesn't have such a feature built-in. Fortunately, Neovim\nhas an API function for escaping terminal codes and keycodes:\n`nvim_replace_termcodes()`\n\n    >\n    print(vim.api.nvim_replace_termcodes('<Tab>', true, true, true))\n<\n\nThis is a little verbose. Making a reusable wrapper can help:\n\n    >\n    -- The function is called `t` for `termcodes`.\n    -- You don't have to call it that, but I find the terseness convenient\n    local function t(str)\n        -- Adjust boolean arguments as needed\n        return vim.api.nvim_replace_termcodes(str, true, true, true)\n    end\n\n    print(t'<Tab>')\n<\n\nComing back to our earlier example, this should now work as expected:\n\n    >\n    local function t(str)\n        return vim.api.nvim_replace_termcodes(str, true, true, true)\n    end\n\n    function _G.smart_tab()\n        return vim.fn.pumvisible() == 1 and t'<C-N>' or t'<Tab>'\n    end\n\n    vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.smart_tab()', {expr =\n    true, noremap = true})\n<\n\nThis is not necessary with `vim.keymap.set()` as it automatically\ntransforms vim keycodes returned by Lua functions in `expr` mappings\nby default:\n\n    >\n    vim.keymap.set('i', '<Tab>', function()\n        return vim.fn.pumvisible() == 1 and '<C-N>' or '<Tab>'\n    end, {expr = true})\n<\n\nSee also:\n\n- |keycodes|\n- |expr-quote|\n- |nvim_replace_termcodes()|\n\n==============================================================================\nMANAGING VIM OPTIONS\n                                                 *luaguide-managing-vim-options*\n\nUsing api functions~\n\nNeovim provides a set of API functions to either set an option or get\nits current value:\n\n- Global options:\n    - |nvim_set_option()|\n    - |nvim_get_option()|\n- Buffer-local options:\n    - |nvim_buf_set_option()|\n    - |nvim_buf_get_option()|\n- Window-local options:\n    - |nvim_win_set_option()|\n    - |nvim_win_get_option()|\n\nThey take a string containing the name of the option to set/get as well\nas the value you want to set it to.\n\nBoolean options (like `(no)number`) have to be set to either `true` or\n`false`:\n\n    >\n    vim.api.nvim_set_option('smarttab', false)\n    print(vim.api.nvim_get_option('smarttab')) -- false\n<\n\nUnsurprisingly, string options have to be set to a string:\n\n    >\n    vim.api.nvim_set_option('selection', 'exclusive')\n    print(vim.api.nvim_get_option('selection')) -- 'exclusive'\n<\n\nNumber options accept a number:\n\n    >\n    vim.api.nvim_set_option('updatetime', 3000)\n    print(vim.api.nvim_get_option('updatetime')) -- 3000\n<\n\nBuffer-local and window-local options also need a buffer number or\na window number (using `0` will set/get the option for the current\nbuffer/window):\n\n    >\n    vim.api.nvim_win_set_option(0, 'number', true)\n    vim.api.nvim_buf_set_option(10, 'shiftwidth', 4)\n    print(vim.api.nvim_win_get_option(0, 'number')) -- true\n    print(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4\n<\n\nUsing meta-accessors~\n\nA few meta-accessors are available if you want to set options in a more\n\"idiomatic\" way. They essentially wrap the above API functions and allow\nyou to manipulate options as if they were variables:\n\n- |vim.o|: behaves like `:let &{option-name}`\n- |vim.go|: behaves like `:let &g:{option-name}`\n- |vim.bo|: behaves like `:let &l:{option-name}` for buffer-local options\n- |vim.wo|: behaves like `:let &l:{option-name}` for window-local options\n\n    >\n    vim.o.smarttab = false -- let &smarttab = v:false\n    print(vim.o.smarttab) -- false\n    vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname =\n    &isfname .. ',@-@'\n    print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'\n\n    vim.bo.shiftwidth = 4\n    print(vim.bo.shiftwidth) -- 4\n<\n\nYou can specify a number for buffer-local and window-local options. If\nno number is given, the current buffer/window is used:\n\n    >\n    vim.bo[4].expandtab = true -- same as vim.api.nvim_buf_set_option(4,\n    'expandtab', true)\n    vim.wo.number = true -- same as vim.api.nvim_win_set_option(0,\n    'number', true)\n<\n\nThese wrappers also have more sophisticated `vim.opt*` variants that\nprovide convenient mechanisms for setting options in Lua. They're similar\nto what you might be used to in your `init.vim`:\n\n- `vim.opt`: behaves like `:set`\n- `vim.opt_global`: behaves like `:setglobal`\n- `vim.opt_local`: behaves like `:setlocal`\n\n    >\n    vim.opt.smarttab = false\n    print(vim.opt.smarttab:get()) -- false\n<\n\nSome options can be set using Lua tables:\n\n    >\n    vim.opt.completeopt = {'menuone', 'noselect'}\n    print(vim.inspect(vim.opt.completeopt:get())) -- { \"menuone\",\n    \"noselect\" }\n<\n\nWrappers for list-like, map-like and set-like options also come with\nmethods and metamethods that work similarly to their `:set+=`, `:set^=`\nand `:set-=` counterparts in Vimscript.\n\n    >\n    vim.opt.shortmess:append({ I = true })\n    -- alternative form:\n    vim.opt.shortmess = vim.opt.shortmess + { I = true }\n\n    vim.opt.whichwrap:remove({ 'b', 's' })\n    -- alternative form:\n    vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' }\n<\n\nBe sure to look at |vim.opt| for more information.\n\nSee also:\n- |lua-vim-options|\n\n==============================================================================\nMANAGING VIM INTERNAL VARIABLES\n                                      *luaguide-managing-vim-internal-variables*\n\nUsing api functions~\n\nMuch like options, internal variables have their own set of API functions:\n\n- Global variables (`g:`):\n    - |nvim_set_var()|\n    - |nvim_get_var()|\n    - |nvim_del_var()|\n- Buffer variables (`b:`):\n    - |nvim_buf_set_var()|\n    - |nvim_buf_get_var()|\n    - |nvim_buf_del_var()|\n- Window variables (`w:`):\n    - |nvim_win_set_var()|\n    - |nvim_win_get_var()|\n    - |nvim_win_del_var()|\n- Tabpage variables (`t:`):\n    - |nvim_tabpage_set_var()|\n    - |nvim_tabpage_get_var()|\n    - |nvim_tabpage_del_var()|\n- Predefined Vim variables (`v:`):\n    - |nvim_set_vvar()|\n    - |nvim_get_vvar()|\n\nWith the exception of predefined Vim variables, they can also be deleted\n(the `:unlet` command is the equivalent in Vimscript). Local variables\n(`l:`), script variables (`s:`) and function arguments (`a:`) cannot\nbe manipulated as they only make sense in the context of a Vim script,\nLua has its own scoping rules.\n\nIf you are unfamiliar with what these variables do, |internal-variables|\ndescribes them in detail.\n\nThese functions take a string containing the name of the variable to\nset/get/delete as well as the value you want to set it to.\n\n    >\n    vim.api.nvim_set_var('some_global_variable', { key1 = 'value', key2 =\n    300 })\n    print(vim.inspect(vim.api.nvim_get_var('some_global_variable'))) --\n    { key1 = \"value\", key2 = 300 }\n    vim.api.nvim_del_var('some_global_variable')\n<\n\nVariables that are scoped to a buffer, a window or a tabpage also\nreceive a number (using `0` will set/get/delete the variable for the\ncurrent buffer/window/tabpage):\n\n    >\n    vim.api.nvim_win_set_var(0, 'some_window_variable', 2500)\n    vim.api.nvim_tab_set_var(3, 'some_tabpage_variable', 'hello world')\n    print(vim.api.nvim_win_get_var(0, 'some_window_variable')) -- 2500\n    print(vim.api.nvim_buf_get_var(3, 'some_tabpage_variable')) --\n    'hello world'\n    vim.api.nvim_win_del_var(0, 'some_window_variable')\n    vim.api.nvim_buf_del_var(3, 'some_tabpage_variable')\n<\n\nUsing meta-accessors~\n\nInternal variables can be manipulated more intuitively using these\nmeta-accessors:\n\n- |vim.g|: global variables\n- |vim.b|: buffer variables\n- |vim.w|: window variables\n- |vim.t|: tabpage variables\n- |vim.v|: predefined Vim variables\n- |vim.env|: environment variables\n\n    >\n    vim.g.some_global_variable = {\n        key1 = 'value',\n        key2 = 300\n    }\n\n    print(vim.inspect(vim.g.some_global_variable)) -- { key1 = \"value\",\n    key2 = 300 }\n\n    -- target a specific buffer/window/tabpage (Neovim 0.6+)\n    vim.b[2].myvar = 1\n<\n\nSome variable names may contain characters that cannot be used for\nidentifiers in Lua. You can still manipulate these variables by using\nthis syntax: `vim.g['my#variable']`.\n\nTo delete one of these variables, simply assign `nil` to it:\n\n    >\n    vim.g.some_global_variable = nil\n<\n\nSee also:\n- |lua-vim-variables|\n\nCaveats~\n\nYou cannot add/update/delete keys from a dictionary stored in one of\nthese variables. For example, this snippet of Vimscript code does not\nwork as expected:\n\n    >\n    let g:variable = {}\n    lua vim.g.variable.key = 'a'\n    echo g:variable\n    \" {}\n<\n\nYou can use a temporary variable as a workaround:\n\n    >\n    let g:variable = {}\n    lua << EOF\n    local tmp = vim.g.variable\n    tmp.key = 'a'\n    vim.g.variable = tmp\n    EOF\n    echo g:variable\n    \" {'key': 'a'}\n<\n\nThis is a known issue:\n\n-  Issue #12544: https://github.com/neovim/neovim/issues/12544\n\n==============================================================================\nCALLING VIMSCRIPT FUNCTIONS\n                                          *luaguide-calling-vimscript-functions*\n\nvim.fn.{function}()~\n\n`vim.fn` can be used to call a Vimscript function. Data types are\nconverted back and forth from Lua to Vimscript.\n\n    >\n    print(vim.fn.printf('Hello from %s', 'Lua'))\n\n    local reversed_list = vim.fn.reverse({ 'a', 'b', 'c' })\n    print(vim.inspect(reversed_list)) -- { \"c\", \"b\", \"a\" }\n\n    local function print_stdout(chan_id, data, name)\n        print(data[1])\n    end\n\n    vim.fn.jobstart('ls', { on_stdout = print_stdout })\n<\n\nHashes (`#`) are not valid characters for identifiers in Lua, so autoload\nfunctions have to be called with this syntax:\n\n    >\n    vim.fn['my#autoload#function']()\n<\n\nThe functionality of `vim.fn` is identical to `vim.call`, but allows a\nmore Lua-like syntax.\n\nIt is distinct from `vim.api.nvim_call_function` in that converting\nVim/Lua objects is automatic: `vim.api.nvim_call_function` returns a\ntable for floating point numbers and does not accept Lua closures while\n`vim.fn` handles these types transparently.\n\nSee also:\n- |vim.fn|\n\nTips~\n\nNeovim has an extensive library of powerful built-in functions that are very\nuseful for plugins. See |vim-function| for an alphabetical list and\n|function-list| for a list of functions grouped by topic.\n\nNeovim API functions can be used directly through `vim.api.{..}`. See\n|api| for information.\n\nCaveats~\n\nSome Vim functions that should return a boolean return `1` or `0`\ninstead. This isn't a problem in Vimscript as `1` is truthy and `0`\nfalsy, enabling constructs like these:\n\n    >\n    if has('nvim')\n        \" do something...\n    endif\n<\n\nIn Lua however, only `false` and `nil` are considered falsy, numbers\nalways evaluate to `true` no matter their value. You have to explicitly\ncheck for `1` or `0`:\n\n    >\n    if vim.fn.has('nvim') == 1 then\n        -- do something...\n    end\n<\n\n==============================================================================\nDEFINING MAPPINGS\n                                                    *luaguide-defining-mappings*\n\nAPI functions~\n\nNeovim provides a list of API functions to set, get and delete mappings:\n\n- Global mappings:\n    - |nvim_set_keymap()|\n    - |nvim_get_keymap()|\n    - |nvim_del_keymap()|\n- Buffer-local mappings:\n    - |nvim_buf_set_keymap()|\n    - |nvim_buf_get_keymap()|\n    - |nvim_buf_del_keymap()|\n\nLet's start with `vim.api.nvim_set_keymap()` and\n`vim.api.nvim_buf_set_keymap()`\n\nThe first argument passed to the function is a string containing the\nname of the mode for which the mapping will take effect:\n\n| String value           | Help page     | Affected modes                           | Vimscript equivalent |\n| ---------------------- | ------------- | ---------------------------------------- | -------------------- |\n| `''` (an empty string) | `mapmode-nvo` | Normal, Visual, Select, Operator-pending | `:map`               |\n| `'n'`                  | `mapmode-n`   | Normal                                   | `:nmap`              |\n| `'v'`                  | `mapmode-v`   | Visual and Select                        | `:vmap`              |\n| `'s'`                  | `mapmode-s`   | Select                                   | `:smap`              |\n| `'x'`                  | `mapmode-x`   | Visual                                   | `:xmap`              |\n| `'o'`                  | `mapmode-o`   | Operator-pending                         | `:omap`              |\n| `'!'`                  | `mapmode-ic`  | Insert and Command-line                  | `:map!`              |\n| `'i'`                  | `mapmode-i`   | Insert                                   | `:imap`              |\n| `'l'`                  | `mapmode-l`   | Insert, Command-line, Lang-Arg           | `:lmap`              |\n| `'c'`                  | `mapmode-c`   | Command-line                             | `:cmap`              |\n| `'t'`                  | `mapmode-t`   | Terminal                                 | `:tmap`              |\n\nThe second argument is a string containing the left-hand side of the\nmapping (the key or set of keys that trigger the command defined in the\nmapping). An empty string is equivalent to `<Nop>`, which disables a key.\n\nThe third argument is a string containing the right-hand side of the\nmapping (the command to execute).\n\nThe final argument is a table containing boolean options for the mapping\nas defined in |:map-arguments|. Since Neovim 0.7.0, you can also pass a\n`callback` option to invoke a Lua function instead of the right-hand\nside when executing the mapping.\n\nBuffer-local mappings also take a buffer number as their first argument\n(`0` sets the mapping for the current buffer).\n\n    >\n    vim.api.nvim_set_keymap('n', '<Leader><Space>', ':set hlsearch!<CR>',\n    { noremap = true, silent = true })\n    -- :nnoremap <silent> <Leader><Space> :set hlsearch<CR>\n    vim.api.nvim_set_keymap('n', '<Leader>tegf',  [[<Cmd>lua\n    require('telescope.builtin').git_files()<CR>]], { noremap = true,\n    silent = true })\n    -- :nnoremap <silent> <Leader>tegf <Cmd>lua\n    require('telescope.builtin').git_files()<CR>\n\n    vim.api.nvim_buf_set_keymap(0, '', 'cc', 'line(\".\") == 1 ? \"cc\" :\n    \"ggcc\"', { noremap = true, expr = true })\n    -- :noremap <buffer> <expr> cc line('.') == 1 ? 'cc' : 'ggcc'\n\n    vim.api.nvim_set_keymap('n', '<Leader>ex', '', {\n        noremap = true,\n        callback = function()\n            print('My example')\n        end,\n        -- Since Lua function don't have a useful string representation,\n        you can use the \"desc\" option to document your mapping\n        desc = 'Prints \"My example\" in the message area',\n    })\n<\n\n`vim.api.nvim_get_keymap()` takes a string containing the shortname of\nthe mode for which you want the list of mappings (see table above). The\nreturn value is a table containing all global mappings for the mode.\n\n    >\n    print(vim.inspect(vim.api.nvim_get_keymap('n')))\n    -- :verbose nmap\n<\n\n`vim.api.nvim_buf_get_keymap()` takes an additional buffer number as\nits first argument (`0` will get mapppings for the current bufffer)\n\n    >\n    print(vim.inspect(vim.api.nvim_buf_get_keymap(0, 'i')))\n    -- :verbose imap <buffer>\n<\n\n`vim.api.nvim_del_keymap()` takes a mode and the left-hand side of\na mapping.\n\n    >\n    vim.api.nvim_del_keymap('n', '<Leader><Space>')\n    -- :nunmap <Leader><Space>\n<\n\nAgain, `vim.api.nvim_buf_del_keymap()`, takes a buffer number as its\nfirst argument, with `0` representing the current buffer.\n\n    >\n    vim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')\n    -- :iunmap <buffer> <Tab>\n<\n\nvim.keymap~\n\nWARNING: The functions discussed in this section are only available in\nNeovim 0.7.0+\n\nNeovim provides two functions to set/del mappings:\n- |vim.keymap.set()|\n- |vim.keymap.del()|\n\nThese are similar to the above API functions with added syntactic sugar.\n\n`vim.keymap.set()` takes a string as its first argument. It can also be\na table of strings to define mappings for multiple modes at once:\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>lua vim.notify(\"Example\n    1\")<CR>')\n    vim.keymap.set({'n', 'c'}, '<Leader>ex2', '<Cmd>lua\n    vim.notify(\"Example 2\")<CR>')\n<\n\nThe second argument is the left-hand side of the mapping.\n\nThe third argument is the right-hand side of the mapping, which can\neither be a string or a Lua function:\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>')\n    vim.keymap.set('n', '<Leader>ex2', function() print(\"Example 2\") end)\n    vim.keymap.set('n', '<Leader>pl1', require('plugin').plugin_action)\n    -- To avoid the startup cost of requiring the module, you can wrap\n    it in a function to require it lazily when invoking the mapping:\n    vim.keymap.set('n', '<Leader>pl2', function()\n    require('plugin').plugin_action() end)\n<\n\nThe fourth (optional) argument is a table of options that correspond to\nthe options passed to `vim.api.nvim_set_keymap()`, with a few additions\n(see |vim.keymap.set()|.\n\n    >\n    vim.keymap.set('n', '<Leader>ex1', '<Cmd>echomsg \"Example 1\"<CR>',\n    {buffer = true})\n    vim.keymap.set('n', '<Leader>ex2', function() print('Example 2')\n    end, {desc = 'Prints \"Example 2\" to the message area'})\n<\n\nDefining keymaps with a Lua function is different from using a string. The\nusual way to show information about a keymap like `:nmap <Leader>ex1`\nwill not output useful information (the string itself), but instead\nonly show `Lua function`. It is recommended to add a `desc` key to\ndescribe the behavior of your keymap. This is especially important for\ndocumenting plugin mappings so users can understand the usage of the\nkeymap more easily.\n\nAn interesting feature of this API is that it irons out some historical\nquirks of Vim mappings:\n- Mappings are `noremap` by default, except when the `rhs` is a `<Plug>`\nmapping. This means you rarely have to think about whether a mapping\nshould be recursive or not:\n    ```lua\n    vim.keymap.set('n', '<Leader>test1', '<Cmd>echo \"test\"<CR>')\n    -- :nnoremap <Leader>test <Cmd>echo \"test\"<CR>\n\n    -- If you DO want the mapping to be recursive, set the \"remap\"\n    option to \"true\"\n    vim.keymap.set('n', '>', ']', {remap = true})\n    -- :nmap > ]\n\n    -- <Plug> mappings don't work unless they're recursive,\n    vim.keymap.set() handles that for you automatically\n    vim.keymap.set('n', '<Leader>plug', '<Plug>(plugin)')\n    -- :nmap <Leader>plug <Plug>(plugin)\n    ```\n- In `expr` mappings, `nvim_replace_termcodes()` is automatically applied\nto strings returned from Lua functions:\n    ```lua\n    vim.keymap.set('i', '<Tab>', function()\n        return vim.fn.pumvisible == 1 and '<C-N>' or '<Tab>'\n    end, {expr = true})\n    ```\n\nSee also:\n- |recursive_mapping|\n\n`vim.keymap.del()` works the same way but deletes mappings instead:\n\n    >\n    vim.keymap.del('n', '<Leader>ex1')\n    vim.keymap.del({'n', 'c'}, '<Leader>ex2', {buffer = true})\n<\n\n==============================================================================\nDEFINING USER COMMANDS\n                                               *luaguide-defining-user-commands*\n\nWARNING: The API functions discussed in this section are only available\nin Neovim 0.7.0+\n\nNeovim provides API functions for user-defined commands:\n\n- Global user commands:\n    - |nvim_create_user_command()|\n    - |nvim_del_user_command()|\n- Buffer-local user commands:\n    - |nvim_buf_create_user_command()|\n    - |nvim_buf_del_user_command()|\n\nLet's start with `vim.api.nvim_create_user_command()`\n\nThe first argument passed to this function is the name of the command\n(which must start with an uppercase letter).\n\nThe second argument is the code to execute when invoking said command. It\ncan either be:\n\nA string (in which case it will be executed as Vimscript). You can use\nescape sequences like `<q-args>`, `<range>`, etc. like you would with\n`:command`\n    >\n    vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)',\n    { nargs = 1 })\n    -- :command! -nargs=1 Upper echo toupper(<q-args>)\n\n    vim.cmd('Upper hello world') -- prints \"HELLO WORLD\"\n<\n\nOr a Lua function. It receives a dictionary-like table that\ncontains the data normally provided by escape sequences (see\n|nvim_create_user_command()|\n    >\n    vim.api.nvim_create_user_command(\n        'Upper',\n        function(opts)\n            print(string.upper(opts.args))\n        end,\n        { nargs = 1 }\n    )\n<\n\nThe third argument lets you pass command attributes as a table (see\n|command-attributes|`. Since you can already define buffer-local user commands\nwith |nvim_buf_create_user_command()|, `-buffer` is not a valid attribute.\n\nTwo additional attributes are available:\n- `desc` allows you to control what gets displayed when you run `:command\n{cmd}` on a command defined as a Lua callback. Similarly to keymaps, it\nis recommended to add a `desc` key to commands defined as Lua functions.\n- `force` is equivalent to calling `:command!` and replaces a command\nif one with the same name already exists. It is true by default, unlike\nits Vimscript equivalent.\n\nThe `-complete` attribute can take a Lua function in addition to the\nattributes listed in |:command-complete|.\n\n    >\n    vim.api.nvim_create_user_command('Upper', function() end, {\n        nargs = 1,\n        complete = function(ArgLead, CmdLine, CursorPos)\n            -- return completion candidates as a list-like table\n            return { 'foo', 'bar', 'baz' }\n        end,\n    })\n<\n\nBuffer-local user commands also take a buffer number as their first\nargument. This is an advantage over `-buffer` which can only define a\ncommand for the current buffer.\n\n    >\n    vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})\n<\n\n`vim.api.nvim_del_user_command()` takes a command name.\n\n    >\n    vim.api.nvim_del_user_command('Upper')\n    -- :delcommand Upper\n<\n\nAgain, `vim.api.nvim_buf_del_user_command()`, takes a buffer number as\nits first argument, with `0` representing the current buffer.\n\n    >\n    vim.api.nvim_buf_del_user_command(4, 'Upper')\n<\n\nSee also:\n- |nvim_create_user_command()|\n- |40.2|\n- |command-attributes|\n\nCaveats~\n\nThe `-complete=custom` attribute automatically filters completion\ncandidates and has built-in wildcard (|wildcard| support:\n\n    >\n    function! s:completion_function(ArgLead, CmdLine, CursorPos) abort\n        return join([\n            \\ 'strawberry',\n            \\ 'star',\n            \\ 'stellar',\n            \\ ], \"\\n\")\n    endfunction\n\n    command! -nargs=1 -complete=custom,s:completion_function Test echo\n    <q-args>\n    \" Typing `:Test st[ae]<Tab>` returns \"star\" and \"stellar\"\n<\n\nPassing a Lua function to `complete` makes it behave like `customlist`\nwhich leaves filtering up to the user:\n\n    >\n    vim.api.nvim_create_user_command('Test', function() end, {\n        nargs = 1,\n        complete = function(ArgLead, CmdLine, CursorPos)\n            return {\n                'strawberry',\n                'star',\n                'stellar',\n            }\n        end,\n    })\n\n    -- Typing `:Test z<Tab>` returns all the completion results because\n    the list was not filtered\n<\n\n==============================================================================\nDEFINING AUTOCOMMANDS\n                                                *luaguide-defining-autocommands*\n\n(this section is a work in progress)\n\nNeovim 0.7.0 has API functions for autocommands. See `:help api-autocmd`\nfor details\n\n-  Pull request #14661: https://github.com/neovim/neovim/pull/14661   lua:\nautocmds take 2\n\n==============================================================================\nDEFINING HIGHLIGHTS\n                                                  *luaguide-defining-highlights*\n\n(this section is a work in progress)\n\nNeovim 0.7.0 has API functions for highlight groups. See also:\n\n- |nvim_set_hl()|\n- |nvim_get_hl_by_id()|\n- |nvim_get_hl_by_name()|\n\n==============================================================================\nGENERAL TIPS AND RECOMMENDATIONS\n                                     *luaguide-general-tips-and-recommendations*\n\nReloading cached modules~\n\nIn Lua, the `require()` function caches modules. This is a good thing\nfor performance, but it can make working on plugins a bit cumbersome\nbecause modules are not updated on subsequent `require()` calls.\n\nIf you'd like to refresh the cache for a particular module, you have to\nmodify the `package.loaded` global table:\n\n    >\n    package.loaded['modname'] = nil\n    require('modname') -- loads an updated version of module 'modname'\n<\n\nThe  nvim-lua/plenary.nvim:\nhttps://github.com/nvim-lua/plenary.nvim  plugin has a  custom function:\nhttps://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/reload.lua\nthat does this for you.\n\nDon't pad Lua strings!~\n\nWhen using double bracketed strings, resist the temptation to pad\nthem! While it is fine to do in contexts where spaces are ignored,\nit can cause hard to debug issues when whitespace is significant:\n\n    >\n    vim.api.nvim_set_keymap('n', '<Leader>f', [[ <Cmd>call foo()<CR>\n    ]], {noremap = true})\n<\n\nIn the above example, `<Leader>f` is mapped to `<Space><Cmd>call\nfoo()<CR><Space>` instead of `<Cmd>call foo()<CR>`.\n\nNotes about Vimscript <-> Lua type conversion~\n\nConverting a variable creates a copy:~\nYou can't directly interact with the reference to a Vim object from Lua\nor a Lua object from Vimscript.\nFor example, the `map()` function in Vimscript modifies a variable\nin place:\n\n    >\n    let s:list = [1, 2, 3]\n    let s:newlist = map(s:list, {_, v -> v * 2})\n\n    echo s:list\n    \" [2, 4, 6]\n    echo s:newlist\n    \" [2, 4, 6]\n    echo s:list is# s:newlist\n    \" 1\n<\n\nUsing this function from Lua creates a copy instead:\n\n    >\n    local tbl = {1, 2, 3}\n    local newtbl = vim.fn.map(tbl, function(_, v) return v * 2 end)\n\n    print(vim.inspect(tbl)) -- { 1, 2, 3 }\n    print(vim.inspect(newtbl)) -- { 2, 4, 6 }\n    print(tbl == newtbl) -- false\n<\n\nConversion is not always possible~\nThis mostly affects functions and tables:\n\nLua tables that are a mix between a List and a Dictionary can't be\nconverted:\n\n    >\n    print(vim.fn.count({1, 1, number = 1}, 1))\n    -- E5100: Cannot convert given lua table: table should either have\n    a sequence of positive integer keys or contain only string keys\n<\n\nWhile you can call Vim functions in Lua with `vim.fn`, you can't hold\nreferences to them. This can cause surprising behaviors:\n\n    >\n    local FugitiveHead = vim.fn.funcref('FugitiveHead')\n    print(FugitiveHead) -- vim.NIL\n\n    vim.cmd(\"let g:test_dict = {'test_lambda': {-> 1}}\")\n    print(vim.g.test_dict.test_lambda) -- nil\n    print(vim.inspect(vim.g.test_dict)) -- {}\n<\n\nPassing Lua functions to Vim functions is OK, storing them in Vim\nvariables is not (fixed in Neovim 0.7.0+):\n\n    >\n    -- This works:\n    vim.fn.jobstart({'ls'}, {\n        on_stdout = function(chan_id, data, name)\n            print(vim.inspect(data))\n        end\n    })\n\n    -- This doesn't:\n    vim.g.test_dict = {test_lambda = function() return 1 end} -- Error:\n    Cannot convert given lua type\n<\n\nNote however that doing the same from Vimscript with `luaeval()`\n**does** work:\n\n    >\n    let g:test_dict = {'test_lambda': luaeval('function() return 1 end')}\n    echo g:test_dict\n    \" {'test_lambda': function('<lambda>4714')}\n<\n\nVim booleans~\nA common pattern in Vim scripts is to use `1` or `0` instead of proper\nbooleans. Indeed, Vim did not have a separate boolean type until version\n7.4.1154.\n\nLua booleans are converted to actual booleans in Vimscript, not numbers:\n\n    >\n    lua vim.g.lua_true = true\n    echo g:lua_true\n    \" v:true\n    lua vim.g.lua_false = false\n    echo g:lua_false\n    \" v:false\n<\n\nSetting up linters/language servers~\n\nIf you're using linters and/or language servers to get diagnostics and\nautocompletion for Lua projects, you may have to configure Neovim-specific\nsettings for them. Here are a few recommended settings for popular tools:\n\nluacheck~\n\nYou can get  luacheck: https://github.com/mpeterv/luacheck/  to recognize\nthe `vim` global by putting this configuration in `~/.luacheckrc`  or\n`$XDG_CONFIG_HOME/luacheck/.luacheckrc` :\n\n    >\n    globals = {\n        \"vim\",\n    }\n<\n\nThe  Alloyed/lua-lsp: https://github.com/Alloyed/lua-lsp/  language\nserver uses `luacheck` to provide linting and reads the same file.\n\nFor more information on how to configure `luacheck`, please refer to\nits  documentation: https://luacheck.readthedocs.io/en/stable/config.html\n\nsumneko/lua-language-server~\n\nThe  nvim-lspconfig: https://github.com/neovim/nvim-lspconfig/  repository\ncontains  instructions to configure sumneko/lua-language-server:\nhttps://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua\nthe example uses the built-in LSP client but the configuration should\nbe identical for other LSP client implementations .\n\nFor more information on how to configure  sumneko/lua-language-server:\nhttps://github.com/sumneko/lua-language-server/  see  \"Setting\":\nhttps://github.com/sumneko/lua-language-server/wiki/Setting\n\ncoc.nvim~\n\nThe  rafcamlet/coc-nvim-lua: https://github.com/rafcamlet/coc-nvim-lua/\ncompletion source for  coc.nvim: https://github.com/neoclide/coc.nvim/\nprovides completion items for the Neovim stdlib.\n\nDebugging Lua code~\n\nYou can debug Lua code running in a separate Neovim\ninstance with  jbyuki/one-small-step-for-vimkind:\nhttps://github.com/jbyuki/one-small-step-for-vimkind\n\nThe plugin uses the  Debug Adapter Protocol:\nhttps://microsoft.github.io/debug-adapter-protocol/ . Connecting to\na debug adapter requires a DAP client like  mfussenegger/nvim-dap:\nhttps://github.com/mfussenegger/nvim-dap/  or  puremourning/vimspector:\nhttps://github.com/puremourning/vimspector/ .\n\nDebugging Lua mappings/commands/autocommands~\n\nThe `:verbose` command allows you to see where a\nmapping/command/autocommand was defined:\n\n    >\n    :verbose map m\n<\n\n    >\n    n  m_          * <Cmd>echo 'example'<CR>\n            Last set from ~/.config/nvim/init.vim line 26\n<\n\nBy default, this feature is disabled in Lua for performance reasons. You\ncan enable it by starting Neovim with a verbose level greater than 0:\n\n    >\n    nvim -V1\n<\n\nSee also:\n- |'verbose'|\n- |-V|\n-  neovim/neovim#15079: https://github.com/neovim/neovim/pull/15079\n\nTesting Lua code~\n\n-  plenary.nvim: test harness:\nhttps://github.com/nvim-lua/plenary.nvim/#plenarytest_harness\n-  notomo/vusted: https://github.com/notomo/vusted\n\nUsing Luarocks packages~\n\n wbthomason/packer.nvim: https://github.com/wbthomason/packer.nvim\n supports Luarocks packages. Instructions for\n how to set this up are available in the  README:\n https://github.com/wbthomason/packer.nvim/#luarocks-support\n\n==============================================================================\nMISCELLANEOUS\n                                                        *luaguide-miscellaneous*\n\nvim.loop~\n\n`vim.loop` is the module that exposes the LibUV API. Some resources:\n\n-  Official documentation for LibUV: https://docs.libuv.org/en/v1.x/\n-  Luv documentation: https://github.com/luvit/luv/blob/master/docs.md\n-  teukka.tech - Using LibUV in Neovim:\nhttps://teukka.tech/posts/2020-01-07-vimloop/\n\nSee also:\n- |vim.loop|\n\nvim.lsp~\n\n`vim.lsp` is the module that controls the built-in LSP client. The\nneovim/nvim-lspconfig: https://github.com/neovim/nvim-lspconfig/\nrepository contains default configurations for popular language servers.\n\nThe behavior of the client can be configured using \"lsp-handlers\". For\nmore information:\n- |lsp-handler|\n-  neovim/neovim#12655: https://github.com/neovim/neovim/pull/12655\n-  How to migrate from diagnostic-nvim:\nhttps://github.com/nvim-lua/diagnostic-nvim/issues/73#issue-737897078\n\nYou may also want to take a look at  plugins built around the LSP client:\nhttps://github.com/rockerBOO/awesome-neovim#lsp\n\nSee also:\n- |lsp|\n\nvim.treesitter~\n\n`vim.treesitter` is the module that controls the integration of the\nTree-sitter: https://tree-sitter.github.io/tree-sitter/  library in\nNeovim. If you want to know more about Tree-sitter, you may be interested\nin this  presentation  38:37 : https://www.youtube.com/watch?v=Jes3bD6P0To\n.\n\nThe  nvim-treesitter: https://github.com/nvim-treesitter/  organisation\nhosts various plugins taking advantage of the library.\n\nSee also:\n- |lua-treesitter|\n\nTranspilers~\n\nOne advantage of using Lua is that you don't actually have to write Lua\ncode! There is a multitude of transpilers available for the language.\n\n-  Moonscript: https://moonscript.org/\n\nProbably one of the most well-known transpilers for\nLua. Adds a lots of convenient features like classes, list\ncomprehensions or function literals. The  svermeulen/nvim-moonmaker:\nhttps://github.com/svermeulen/nvim-moonmaker  plugin allows you to write\nNeovim plugins and configuration directly in Moonscript.\n\n-  Fennel: https://fennel-lang.org/\n\nA lisp that compiles to Lua. You can write configuration\nand plugins for Neovim in Fennel with the  Olical/aniseed:\nhttps://github.com/Olical/aniseed  or the  Hotpot:\nhttps://github.com/rktjmp/hotpot.nvim  plugin. Additionally, the\nOlical/conjure: https://github.com/Olical/conjure  plugin provides an\ninteractive development environment that supports Fennel  among other\nlanguages .\n\n-  Teal: https://github.com/teal-language/tl\n\nThe name Teal comes from pronouncing TL  typed lua .  This is exactly\nwhat it tries to do - add strong typing to lua while otherwise\nremaining close to standard lua syntax.  The  nvim-teal-maker:\nhttps://github.com/svermeulen/nvim-teal-maker  plugin can be used to\nwrite Neovim plugins or configuration files directly in Teal\n\nOther interesting projects:\n-  TypeScriptToLua/TypeScriptToLua:\nhttps://github.com/TypeScriptToLua/TypeScriptToLua\n-  Haxe: https://haxe.org/\n-  SwadicalRag/wasm2lua: https://github.com/SwadicalRag/wasm2lua\n-  hengestone/lua-languages: https://github.com/hengestone/lua-languages\n\nvim:tw=78:ts=8:noet:ft=help:norl:\n"
  },
  {
    "path": "scripts/docgen.sh",
    "content": "#!/usr/bin/env sh\n\n./to_vimdoc.sed ../README.md | fmt -s | ./sections_tags.awk > ../doc/nvim-lua-guide.txt\n./to_vimdocja.sed ../README.ja.md | fmt -s | ./sections_tags.awk > ../doc/nvim-lua-guide.jax\n"
  },
  {
    "path": "scripts/sections_tags.awk",
    "content": "#!/usr/bin/awk -f\n{\n    if (lastline ~ /^=+$/) {\n        tag = tolower($0)\n        gsub(/[^A-Za-z]/, \"-\", tag)\n        print $0\n        printf(\"%80s\", \"*\" \"luaguide-\" tag \"*\")\n        print \"\"\n    }\n    else {\n        print\n    }\n}\n\n{ lastline = $0 }\n"
  },
  {
    "path": "scripts/to_vimdoc.sed",
    "content": "#!/bin/sed -f\n\n# Title\n/^# / {\n    s/# /*nvim-lua-guide.txt*  /\n}\n\n# Sections\n/^## / {\n    s/[a-z]/\\u&/g\n    s/## //\n    i==============================================================================\n}\n\n# Sub-sections, tips and caveats\n/^####\\? / {\n    s/####\\? //\n    s/.*/&~/\n}\n\n# Help links\ns/\\[`vim\\.api\\.\\(.*\\)`\\](.*)/|\\1|/\ns/\\[`:help \\(.*\\)`\\](.*)/|\\1|/\ns/\\[`\\(.*\\)`\\](.*)/|\\1|/\n\n# Markdown links\n/\\[.*\\](http.*)/ {\n    y/[]()/ :  /\n}\n\n# Todos\ns/\\*\\*TODO\\*\\*: /\\t*Todo\\t/g\n\n# Warnings\ns/\\*\\*\\(WARNING\\)\\*\\*/\\1/\n\n# Code blocks\n/^```.*$/,/^```$/{\n    s/.*/    &/\n    s/```.\\+/>/\n    s/\\s*```$/</\n}\n\n# Trim trailing whitespace\ns/\\s\\+$//\n\n$a\\\n\\\nvim:tw=78:ts=8:noet:ft=help:norl:\n"
  },
  {
    "path": "scripts/to_vimdocja.sed",
    "content": "#!/bin/sed -f\n\n# Title\n/^# / {\n    s/# /*nvim-lua-guide.txt*  /\n}\n\n# Sections\n/^## / {\n    s/## //\n    i==============================================================================\n}\n\n# Sub-sections, tips and caveats\n/^####\\? / {\n    s/####\\? //\n    s/.*/&~/\n}\n\n# Markdown links\n/\\[.*\\](http.*)/ {\n    y/[]()/ :  /\n}\n\n# Todos\ns/\\*\\*TODO\\*\\*:/\\t*Todo\\ttasks:/g\n\n# Warnings\ns/\\*\\*\\(WARNING\\)\\*\\*/\\1/\n\n# Code blocks\n/^```.*$/,/^```$/{\n    s/.*/    &/\n    s/```.\\+/>/\n    s/\\s*```$/</\n}\n\n# Help links\ns/- `:help \\(.*\\)`/- |\\1|/\n\n# Trim trailing whitespace\ns/\\s\\+$//\n\n$a\\\n\\\nvim:tw=78:ts=8:noet:ft=help:norl:\n"
  }
]