有时我想跨多行编辑某个视觉文本块。
例如,我会采用如下所示的文本:
name
comment
phone
email
并让它看起来像这样
vendor_name
vendor_comment
vendor_phone
vendor_email
目前我现在要做的方式是......
- Select all 4 row lines of a block by pressing V and then j four times.
- Indent with >.
- Go back one letter with h.
- Go to block visual mode with Ctrlv.
- Select down four rows by pressing j four times. At this point you have selected a 4x1 visual blocks of whitespace (four rows and one column).
- Press C. Notice this pretty much indented to the left by one column.
- 键入一个
" vendor_"
没有报价。请注意我们必须放回的额外空间。
- Press Esc. This is one of the very few times I use Esc to get out of insert mode. Ctrlc would only edit the first line.
- 重复步骤 1。
- Indent the other way with <.
I don't need to indent if there is at least one column of whitespace before the words. I wouldn't need the whitespace if I didn't have to clear the visual block with c.
但是,如果我必须清除,那么有没有一种方法可以完成我上面执行的操作,而无需创建带有缩进的所需空白?
Also why does editing multiple lines at once only work by exiting out of insert mode with Esc over Ctrlc?
这是一个更复杂的例子:
name = models.CharField( max_length = 135 )
comment = models.TextField( blank = True )
phone = models.CharField( max_length = 135, blank = True )
email = models.EmailField( blank = True )
to
name = models.whatever.CharField( max_length = 135 )
comment = models.whatever.TextField( blank = True )
phone = models.whatever.CharField( max_length = 135, blank = True )
email = models.whatever.EmailField( blank = True )
在此示例中,我将在.
,然后在插入模式下将其重新插入,即键入.whatever.
。希望现在您可以看到此方法的缺点。我仅限于选择一列文本在垂直位置上都是一样的.
- 将光标移至
n
in name
.
- Enter visual block mode (Ctrlv).
- Press j three times (or 3j) to jump down by 3 lines; G (capital g) to jump to the last line
- Press
I
(capital i).
- Type in
vendor_
. Note: It will only update the screen in the first line - until Esc is pressed (6.), at which point all lines will be updated.
- Press Esc.
一个大写I
必须使用小写字母i
,因为小写i
被解释为一个的开始文本对象 http://vimhelp.appspot.com/motion.txt.html#text-objects,它本身就相当有用,例如用于在标签块内选择(it http://vimhelp.appspot.com/motion.txt.html#it):
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)