tce*_*act 1 vim copy-paste indentation paste auto-indent
我在 Vim 中发短信时遇到问题putting。
假设我想将我的/* Comment */行粘贴到该$('table').append行下方...
/* Comment */
for (var i=1; i<=lineLength ; i++) {
$('table').append('<tr></tr>');
for (var j=1; j<=lineLength; j++) {
$('table tr:nth-last-child(1)').append('<td></td>');
}
}
Run Code Online (Sandbox Code Playgroud)
在大多数文本编辑器中,我的工作流程是
/* Comment */,点击剪切。IE
/* Comment */
for (var i=1; i<=lineLength ; i++) {
$('table').append('<tr></tr>');
| <==Pipe is position of cursor before paste; pasted lines are inserted here.
for (var j=1; j<=lineLength; j++) {
$('table tr:nth-last-child(1)').append('<td></td>');
}
}
Run Code Online (Sandbox Code Playgroud)
但对于 vim,我似乎必须这样做:
/* Comment */线上,点击dd。$('table').append线上,点击p。新代码:
for (var i=1; i<=lineLength ; i++) {
$('table').append('<tr></tr>');
/* Comment */. <== Comment is not correctly indented.
for (var j=1; j<=lineLength; j++) {
$('table tr:nth-last-child(1)').append('<td></td>');
}
}
Run Code Online (Sandbox Code Playgroud)
当我用 开始新行时,Vim 自动缩进很好o,所以看起来它也应该处理putting新行......是否有一个命令可以让我put使用正确的缩进来编写新代码行?
您可以使用]p和[p在当前行的缩进级别进行粘贴。请注意,这仅在寄存器的内容是逐行的情况下才有效。看:h ]p
如果你想使用]pand 朋友,但总是希望它是逐行的,那么我建议你看看 Tim Pope 的unimpaired.vim插件。它还提供>p/<p映射,将一层缩进更深/更浅地粘贴,以及=p/=P粘贴然后重新缩进,类似于p='].