## 事象 以下のようなコードで[[nvim_create_user_command]]を書く。 ```lua vim.api.nvim_create_user_command("Ghostcopy", function() local text = editor.get_visual_selection() vim.notify(text) end, { nargs = 0 }) ``` [[ビジュアルモード]]で範囲選択し、上記コマンドを実行すると以下のエラー。 ```error E481: No range allowed ``` ## 原因 `opts`で`range = true`を設定していないから。 ## 解決方法 以下のように`range = true`を設定する。 ```lua vim.api.nvim_create_user_command("Ghostcopy", function() local text = editor.get_visual_selection() vim.notify(text) end, { nargs = 0, range = true }) ```