windows 如何在 gVim (Win32) 中缩进选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/318923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:39:16  来源:igfitidea点击:

How to indent a selection in gVim (Win32)

windowsvimindentation

提问by Fredrick

I'd like to indent a block of text.

我想缩进一段文本

I am able to do this in the Linuxbuild of gVim.

我可以在gVim的Linux版本中做到这一点。

I do this in the stateof gVim where I'm not in the insert or visual mode. The bar at the bottom is blank on the left, and the line number and percentage are showing on the right hand side.

我在gVim的状态下执行此操作,我不在插入或可视模式下。底部的栏在左边是空白的,行号和百分比显示在右边。

Then I perform the following procedure: I select a block of text via click and drag. Then I hit Shift+ .. After that, I hit Escand the block of text will move over a tab.

然后我执行以下过程:我通过单击和拖动选择一个文本块。然后我点击Shift+ .。之后,我点击Esc,文本块将移动到一个选项卡上。

If I do this in Windowshowever, it just replaces the block with >.

但是,如果我在Windows中执行此操作,它只会将块替换为>.

I am just running the stock Windows rc fileand version 7.1 of gVim.

我只是在运行现有的 Windows rc 文件和 gVim 7.1 版。

回答by wimh

If you first enter SHIFT-V, and than shift+arrows to select the text, it will indent. You can also use SHIFT-V, and use 'hjkl' to select the block.

如果您首先输入 SHIFT-V,然后使用 shift+箭头选择文本,它将缩进。您也可以使用 SHIFT-V,并使用“hjkl”来选择块。

If you use shift+arrows or the mouse to select a block of text, it does not work and the selection will be replaced with a '>'. This can be changed when you change selectmode;

如果您使用 shift+箭头或鼠标来选择一个文本块,它不起作用并且选择将被替换为“>”。这可以在您更改选择模式时更改;

set selectmode=mouse,key

设置选择模式=鼠标,键

  • default setting after behave mswin
  • 行为 mswin 后的默认设置

set selectmode=key

设置选择模式=键

  • now you can select with the mouse and press '>' to indent
  • 现在您可以用鼠标选择并按“>”缩进

set selectmode=

设置选择模式=

  • now you can select both with the mouse and shifted arrow keys and press '>' to indent
  • 现在您可以同时使用鼠标和移动箭头键进行选择,然后按“>”缩进

If you add this to your vimrc, do it after behave mswin

如果您将此添加到您的 vimrc,请在执行 mswin 之后执行

回答by csexton

Related to this, I use a handy remap for visual mode that allows indenting the text multiple times while keeping your text selected. Similar to how visual studio lets you select and hit tab (or shift-tab) to indent.

与此相关,我使用了一个方便的视觉模式重映射,允许在保持文本被选中的同时多次缩进文本。类似于visual studio如何让您选择并点击tab(或shift-tab)来缩进。

Add the following to your .vimrc

将以下内容添加到您的 .vimrc

" Pressing < or > will let you indent/unident selected lines
vnoremap < <gv
vnoremap > >gv

Also you can use == to have vim try and determine the correct indenting automatically. It will work on any line buy just placing the cursor there and pressing == or you can do fancy stuff like select the entire file and press == to fix all the indenting (works wonders on html generated by wysiwyg editors).

您也可以使用 == 来让 vim 尝试自动确定正确的缩进。它可以在任何行上工作,只需将光标放在那里并按 == 或者你可以做一些花哨的事情,比如选择整个文件并按 == 来修复所有缩进(对所见即所得编辑器生成的 html 产生奇迹)。

回答by EBGreen

Esc-> Shift+V-> Select Lines -> >>

Esc-> Shift+ V-> 选择行 ->>>

回答by Jeremy Bourque

You need to change behave mswinto behave xtermin your vimrc file.

您需要在 vimrc 文件中更改behave mswinbehave xterm

回答by Brian Carper

You can use text objects if you want to avoid visual mode entirely. For example >apin Normal mode indents one paragraph, >aBindents one curly-brace block, etc. See :h text-objects.

如果您想完全避免视觉模式,您可以使用文本对象。例如>ap在普通模式下缩进一个段落,>aB缩进一个大括号块等。请参见:h text-objects