[mini.ai] Trim extra whitespace between words? #1042
-
If you had a sentence such as this with your cursor at the carat, how would you delete all but one space between the words?
In emacs, I would regularly use require("mini.ai").setup({
custom_textobjects = {
S = { { "^()()[ \t]*()()[^ \t]", "[^ \t]()[ \t]()[ \t]*()()[^ \t]" } },
},
vim.keymap.set({"i", "n"}, "<A-Space>", "<Cmd>normal diS", "Just one space") With the text object, I have both "a" and "i" variants. The "a" selects all spaces, and "i" selects all but one. And, then the mapping is just my shortcut to emulate the emacs behavior I've missed ever since moving to vim. So, is this overkill for my original task at hand? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would say so, yes. I tend yo use |
Beta Was this translation helpful? Give feedback.
I would say so, yes. I tend yo use
ciw<Space><Esc>
, asiw
works on whitespace too. So if you're fine with changing mode (twice) in a mapping, I'd go withvim.keymap.set({"i", "n"}, "<A-Space>", "<Cmd>normal ciw <CR>", { desc = "Just one space" })
. If not, then custom function which executes:normal diw
and then adds single space at cursor seems more understandable to me.