Vim 在正常模式下替换到行尾
Vim substitute till end of line in normal mode
我使用 yiw
提取了一些文本。现在,在另一行,我想替换从当前光标位置到行尾的文本,所以我尝试 v$p
。但是,这也会删除我不想发生的行尾的换行符。我该如何解决这个问题?
可以删除到空寄存器然后用"_Dp
粘贴
或者,如果你想保存你正在删除的文本,你可以在普通缓冲区中删除,然后从 0 缓冲区使用 D"0p
我发现注册键很笨重,所以我在我的 .vimrc 中有它们的映射:
" leader means "another option key like cmd or meta, but one you get to choose"
let mapleader = "\<Space>"
" get the yank register, not the thing you just deleted
nnoremap <Leader>p "0p
nnoremap <Leader>P "0P
" don't copy the thing you're gonna delete into the delete register
nnoremap <Leader>d "_d
nnoremap <Leader>D "_D
通过这些绑定,它会变成 Dp
或 D p
,具体取决于您是否要保留已删除的文本。
如果您根本不想弄乱寄存器,总有简单的 PlD
.
您可以:
投放前调整可视区域:
v$hp
如果没有尾随 space,请使用 :help g_
动作:
vg_p
我使用 yiw
提取了一些文本。现在,在另一行,我想替换从当前光标位置到行尾的文本,所以我尝试 v$p
。但是,这也会删除我不想发生的行尾的换行符。我该如何解决这个问题?
可以删除到空寄存器然后用"_Dp
或者,如果你想保存你正在删除的文本,你可以在普通缓冲区中删除,然后从 0 缓冲区使用 D"0p
我发现注册键很笨重,所以我在我的 .vimrc 中有它们的映射:
" leader means "another option key like cmd or meta, but one you get to choose"
let mapleader = "\<Space>"
" get the yank register, not the thing you just deleted
nnoremap <Leader>p "0p
nnoremap <Leader>P "0P
" don't copy the thing you're gonna delete into the delete register
nnoremap <Leader>d "_d
nnoremap <Leader>D "_D
通过这些绑定,它会变成 Dp
或 D p
,具体取决于您是否要保留已删除的文本。
如果您根本不想弄乱寄存器,总有简单的 PlD
.
您可以:
投放前调整可视区域:
v$hp
如果没有尾随 space,请使用
:help g_
动作:vg_p