## 詳細 以下のようなパスがあり、`local` の上にカーソルがあったとする。 ``` /user/local/bin/hoge.sh ``` `di/` としたら以下のようになってほしい。 ``` /user//bin/hoge.sh ``` - [[Neovim]]が[[テキストオブジェクト]]としてサポートしている文字は対象外 - `/` はあくまで一例であり、任意の文字を扱いたい ## 方法 [[nvim-surround]]と[[ns-textobject.nvim]]を使う。 ### nvim-surroundの設定 以下のように[[テキストオブジェクト]]として利用したい文字ごとに定義を追加する。 ```lua { "kylechui/nvim-surround", event = "VeryLazy", opts = { surrounds = { ["/"] = { add = { "/", "/" }, find = "()%/[^/\n]*%/()", }, ["*"] = { add = { "*", "*" }, find = "()%*[^*\n]*%*()", }, ["_"] = { add = { "_", "_" }, find = "()_[^_\n]*_()", }, ["-"] = { add = { "-", "-" }, find = "()-[^%-\n]*-()", }, }, }, } ``` ### ns-textobject.nvim の設定 特別な設定は不要。`dependencies` への追加だけ。 ```lua return { "XXiaoA/ns-textobject.nvim", event = "VeryLazy", dependencies = { "kylechui/nvim-surround" }, opts = {}, } ``` ## 参考 - [ChatGPT - nvim-surround シングルライン設定](https://chatgpt.com/share/678b7eb5-71ac-800a-a684-70069f82ab33)