What should I use vim Visual mode for?

前提是你 提交于 2019-12-05 13:34:54

If you see CTRL-CCTRL-V and recognise what it does, you should use visual mode.

If, like me, you see A:esc0df:$p$x as an edit command, don't bother :-)

When I use visual mode, it's to select whole lines or blocks. For example you can do [esc][shift+v][y] to copy the currently line I'm on. Here's more information.

Visual mode allows you to perform an operation on a block of text. It is the only way to perform an operation on a block in Vim.

A simple example of this would be copying or moving text.

A more advanced example would be sorting the lines in a certain part of a file. You can do this by entering visual mode, selecting a block of text, pressing Esc to enter command mode, and typing !sort. You can see more details about his example and how it works here: http://www.oualline.com/vim-cook.html#sorting_visual

I actually just did a screencast showing off great uses for visual mode. You can check it out at http://lococast.net/archives/241

As other's have said, it's great for doing any sorts of editing (edit, remove, search/replace) withing a specific range of code.

  • Insert a column of commas.
  • Delete a column of commas.
  • Act on rectangular selections.
  • Act on a section of text that is not a line or word.

Several good examples have already been given. Here are some others. I also use visual mode:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!