我有这个代码片段。我想用一个空格替换所有空格。 在 IntelliJ 中,我只需使用多光标,跳转到
--
,使用 option
+ shift
+ left arrow
,然后使用 right arrow
选择所有空格并输入 space
来替换它们。
我是 vim 新手,还没有找到任何解决方案来实现这一点。
vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore
vim.opt.showtabline = 2 -- always show tabs
vim.opt.smartcase = true -- smart case
vim.opt.splitbelow = true -- force all horizontal splits to go below current window
vim.opt.splitright = true -- force all vertical splits to go to the right of current window
vim.opt.swapfile = false -- creates a swapfile
vim.opt.termguicolors = true -- set term gui colors (most terminals support this)
vim.opt.timeoutlen = 1000 -- time to wait for a mapped sequence to complete (in milliseconds)
vim.opt.undofile = true -- enable persistent undo
vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it
谢谢。
在我半全新安装的 Intellij IDEA CE 中,正确的顺序是:
<place cursor>
<option><option>
<down>
<down>
<down>
<down>
<down>
<down>
<down>
<down>
<down>
<option-shift-left>
<(option-shift-)right>
<space>
<escape>
在 Vim 中,你可以简单地使用多光标插件,有几个,或者这样做......
替换后:
vip
:'<,'>s/ \{2,}/ /<CR>
哪里…
vip
直观地选择当前“段落”,请参阅 :help v
和 :help text-objects
。'<,'>
是要执行以下命令的行的 :help :range
。您可以通过在进入命令行模式之前选择行范围来显式或隐式指示范围。这就是我们在这里所做的,Vim 自动插入相应的范围:'<,'>
。s/ \{2,}/ /
是替换 \{2,}
匹配 2 个连续空格或更多。
是,嗯……一个空间。<CR>
是 Enter 键。用“点公式”:
/ \{2,}<CR>
cgn<space>
.
.
.
.
.
.
.
.
.
哪里…
/ \{2,}<CR>
搜索下一个包含 2 个或更多空格的序列。在这种情况下,我们只是为下一个命令做准备。cgn<space>
将当前或下一个搜索匹配替换为 <space>
,请参阅 :help c
和 :help gn
。.
重复上一个命令九次,参见:help .
。FWIW,我有自定义映射,可以在
.
之前使用计数:
nnoremap . :<C-u>execute "norm! " . repeat(".", v:count1)<CR>
这大大缩短了上面的命令,但代价是计算行数,所以 YMMV:
/ \{2,}<CR>
cgn<space>
9.
哲学思考:
<down>
和<left>
之后,但它最终会在你身上成长。