Home Database Mysql Tutorial Vim进阶简明手册(2)

Vim进阶简明手册(2)

Jun 07, 2016 pm 03:42 PM
vim manual better faster Advanced

第三级– 更好,更强,更快 先恭喜你!你干的很不错。我们可以开始一些更为有趣的事了。在第三级,我们只谈那些和vi可以兼容的命令。 更好 下面,让我们看一下vim是怎么重复自己的: . → (小数点) 可以重复上一次的命令 Ncommand → 重复某个命令N次 下面是

第三级 – 更好,更强,更快

先恭喜你!你干的很不错。我们可以开始一些更为有趣的事了。在第三级,我们只谈那些和vi可以兼容的命令。

更好

下面,让我们看一下vim是怎么重复自己的:

  1. <span>.</span> → (小数点) 可以重复上一次的命令
  2. N → 重复某个命令N次

下面是一个示例,找开一个文件你可以试试下面的命令:

  • 2dd → 删除2行
  • 3p → 粘贴文本3次
  • 100idesu [ESC] → 会写下 “desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu “
  • . → 重复上一个命令—— 100 “desu “.
  • 3. → 重复 3 次 “desu” (注意:不是 300,你看,VIM多聪明啊).
更强

你要让你的光标移动更有效率,你一定要了解下面的这些命令,千万别跳过

  1. NG → 到第 N 行 (陈皓注:注意命令中的G是大写的,另我一般使用 : N 到第N行,如 :137 到第137行)
  2. <span>gg</span> → 到第一行。(陈皓注:相当于1G,或 :1)
  3. <span>G</span> → 到最后一行。
  4. 按单词移动:
    1. <span>w</span> → 到下一个单词的开头。
    2. <span>e</span> → 到下一个单词的结尾。

    > 如果你认为单词是由默认方式,那么就用小写的e和w。默认上来说,一个单词由字母,数字和下划线组成(陈皓注:程序变量)

    > 如果你认为单词是由blank字符分隔符,那么你需要使用大写的E和W。(陈皓注:程序语句)

    Vim进阶简明手册(2)

下面,让我来说说最强的光标移动:

  • <span>%</span> : 匹配括号移动,包括 ({[. (陈皓注:你需要把光标先移到括号上)
  • <span>*</span> 和 #:  匹配光标当前所在的单词,移动光标到下一个(或上一个)匹配单词(*是下一个,#是上一个)

相信我,上面这三个命令对程序员来说是相当强大的。

更快

你一定要记住光标的移动,因为很多命令都可以和这些移动光标的命令连动。很多命令都可以如下来干:

<span><start position><command><end position></end></command></start></span>

例如 0y$ 命令意味着:

  • 0 → 先到行头
  • y → 从这里开始拷贝
  • $ → 拷贝到本行最后一个字符

你可可以输入 ye,从当前位置拷贝到本单词的最后一个字符。

你也可以输入 y2/foo 来拷贝2个 “foo” 之间的字符串。

还有很多时间并不一定你就一定要按y才会拷贝,下面的命令也会被拷贝:

  • <span>d</span> (删除 )
  • v (可视化的选择)
  • <span>gU</span> (变大写)
  • <span>gu</span> (变小写)
  • 等等

(注:可视化选择是一个很有意思的命令,你可以先按v,然后移动光标,你就会看到文本被选择,然后,你可能d,也可y,也可以变大写等)

第四级 – Vim 超能力

你只需要掌握前面的命令,你就可以很舒服的使用VIM了。但是,现在,我们向你介绍的是VIM杀手级的功能。下面这些功能是我只用vim的原因。

在当前行上移动光标: 0 ^ $ f F t T , ;
  • <span>0</span> → 到行头
  • <span>^</span> → 到本行的第一个非blank字符
  • <span>$</span> → 到行尾
  • <span>g_</span> → 到本行最后一个不是blank字符的位置。
  • <strong>f</strong>a → 到下一个为a的字符处,你也可以fs到下一个为s的字符。
  • <strong><span>t</span></strong><span>,</span> → 到逗号前的第一个字符。逗号可以变成其它字符。
  • <span>3f</span><span>a</span> → 在当前行查找第三个出现的a。
  • <span>F</span> 和 <span>T</span> → 和 f 和 t 一样,只不过是相反方向。
    Vim进阶简明手册(2)

还有一个很有用的命令是 <span>dt</span><span>"</span> → 删除所有的内容,直到遇到双引号—— "。

区域选择 <action>a<object></object></action> 或 <action>i<object></object></action>

在visual 模式下,这些命令很强大,其命令格式为

<action>a<object></object></action> 和 <action>i<object></object></action>

  • action可以是任何的命令,如 d (删除), y (拷贝), v (可以视模式选择)。
  • object 可能是: w 一个单词, W 一个以空格为分隔的单词, s 一个句字, p 一个段落。也可以是一个特别的字符:"、 '、 )、 }、 ]。

假设你有一个字符串 (map (+) ("foo")).而光标键在第一个 的位置。

  • vi" → 会选择 foo.
  • va" → 会选择 "foo".
  • vi) → 会选择 "foo".
  • va) → 会选择("foo").
  • v2i) → 会选择 map (+) ("foo")
  • v2a) → 会选择 (map (+) ("foo"))

Vim进阶简明手册(2)

块操作: <c-v></c-v>

块操作,典型的操作: <span>0 </span><span><c-v> <c-d> I</c-d></c-v></span><span>-- </span><span>[ESC]</span>

  • ^ → 到行头
  • <c-v></c-v> → 开始块操作
  • <c-d></c-d> → 向下移动 (你也可以使用hjkl来移动光标,或是使用%,或是别的)
  • I-- [ESC] → I是插入,插入“--”,按ESC键来为每一行生效。

Vim进阶简明手册(2)

在Windows下的vim,你需要使用 <c-q></c-q> 而不是 <c-v></c-v> ,<c-v></c-v> 是拷贝剪贴板。

自动提示: <c-n></c-n> 和 <c-p></c-p>

在 Insert 模式下,你可以输入一个词的开头,然后按 <c-p>或是<c-n>,自动补齐功能就出现了……</c-n></c-p>

Vim进阶简明手册(2)

宏录制: qa 操作序列 q@a@@
  • qa 把你的操作记录在寄存器 a。
  • 于是 @a 会replay被录制的宏。
  • @@ 是一个快捷键用来replay最新录制的宏。

示例

在一个只有一行且这一行只有“1”的文本中,键入如下命令:

  • <span>qa Yp <c-a> q</c-a></span>
    • qa 开始录制
    • Yp 复制行. //Y复制行 p粘贴
    • <c-a></c-a> 增加1.
    • q 停止录制.
  • @a → 在1下面写下 2
  • <span>@@</span> → 在2 正面写下3
  • 现在做 100@@ 会创建新的100行,并把数据增加到 103.

Vim进阶简明手册(2)

可视化选择: v,V,<c-v></c-v>

前面,我们看到了 <c-v></c-v>的示例 (在Windows下应该是),我们可以使用 v 和 V。一但被选好了,你可以做下面的事:

  • <span>J</span> → 把所有的行连接起来(变成一行)
  • <span> 或 </span><span><code>> → 左右缩进
  • = → 自动给缩进 (注:这个功能相当强大,我太喜欢了)

Vim进阶简明手册(2)

在所有被选择的行后加上点东西:

  • <c-v></c-v>
  • 选中相关的行 (可使用 j 或 <c-d></c-d> 或是 /pattern 或是 % 等……)
  • $ 到行最后
  • <span>A</span>, 输入字符串,按 ESC。  (<span>I 是在行前加上点东西  A 是在行后</span>)

Vim进阶简明手册(2)

分屏: :split 和 vsplit.

下面是主要的命令,你可以使用VIM的帮助 :help split. 你可以参考以前的一篇文章VIM分屏。

  • :split → 创建分屏 (<span>:vsplit</span>创建垂直分屏)
  • <c-w><dir></dir></c-w> : dir就是方向,可以是 hjkl 或是 ←↓↑→ 中的一个,其用来切换分屏。
  • <c-w>_</c-w> (或 <c-w>|</c-w>) : 最大化尺寸 (| 垂直分屏)
  • <c-w>+</c-w> (或 <c-w>-</c-w>) : 增加尺寸

Vim进阶简明手册(2)

学习vim就像学弹钢琴一样,一旦学会,受益无穷。

——————————正文结束——————————

这是一个你不需要使用鼠标,不需使用小键盘,只需要使用大键盘就可以完成很多复杂功能文本编辑的编辑器。不然,Visual Studio也不就会有vim的插件了。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add the Escape key to your iPad keyboard How to add the Escape key to your iPad keyboard Apr 16, 2023 pm 01:43 PM

How to Remap CapsLock to ESC on iPad Keyboard Are you ready to make CapsLock the ESC key on your iPad? Here's all you need to do: Open the Settings app on your iPad Go to "General" then go to "Keyboard" Go to "Hardware Keyboard" Select "Modifier Keys" Select "CapsLockKey" and select "Escape" as Modifier Keys Now you're ready to try out the new hardware ESC key on your iPad by pressing CapsLock. Go to any application that uses the Escape key and you can test it immediately, such as vi/vim. Now you can use a physical keyboard from

How to use Vim to delete even or odd lines in Linux How to use Vim to delete even or odd lines in Linux May 22, 2023 pm 05:07 PM

The method of deleting even-numbered lines is as follows: :g/^/+1d The :gbobal command is used above. The gbobal command format is as follows: :[range]global/{pattern}/{command}global command is actually divided into two steps: first Scan all the lines within the range specified by [range] and mark the lines matching {pattern}; then execute the {command} command on the marked lines in sequence. If the marked lines are marked during the command operation on the previous matching lines, If you delete, move or merge, the mark will automatically disappear without executing the {command} command on the line. {command} can be an ex command or separated by |

A brief analysis of 3 methods to install Vim on Alpine Linux A brief analysis of 3 methods to install Vim on Alpine Linux Mar 24, 2023 pm 02:28 PM

In PHP development, using Vim is very common. However, you may encounter some problems installing Vim in Alpine Linux. This article will share how to install Vim on Alpine Linux.

Linux Tips: Cancel automatic indentation when pasting in vim Linux Tips: Cancel automatic indentation when pasting in vim Mar 07, 2024 am 08:30 AM

Preface: vim is a powerful text editing tool, which is very popular on Linux. Recently, I encountered a strange problem when using vim on another server: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred. To use a simple example, the script I wrote locally is as follows: aaabbbcccddd. When I copy the above content and paste it into a blank file on the server, what I get is: aabbbcccddd. Obviously, this is what vim does automatically for us. Format indentation. However, this automatic is a bit unintelligent. Record the solution here. Solution: Set the .vimrc configuration file in our home directory, new

How to save and exit vim How to save and exit vim Aug 01, 2023 am 10:47 AM

How to save and exit vim: 1. Use shortcut keys to save and exit; 2. Use a separate command to save and exit; 3. Use automatic commands to save and exit; 4. Use shortcut keys to save the file.

Learn all aspects of Vim split-screen operation in 5 minutes Learn all aspects of Vim split-screen operation in 5 minutes Aug 03, 2023 pm 03:20 PM

Vim's split-screen function is implemented by splitting windows, which is a great tool for improving work efficiency. Whether we want to display two files at the same time, or display two different locations of a file at the same time, or compare two files side by side, etc., these can be achieved through split screen, which is very convenient for code comparison and copy and paste.

How to make VIM support Nginx .conf file syntax highlighting function How to make VIM support Nginx .conf file syntax highlighting function May 15, 2023 pm 12:10 PM

Manually modify the syntax file for downloading the nginx configuration file: nginx.vimwgethttp://www.vim.org/scripts/download_script.php?src_id=14376-onginx.vimCopy the file to the /usr/share/vim/vim74/syntax directory (It can also be a single-user directory ~/.vim/syntax/). Modify vim/usr/share/vim/vim74/filetype.vim to add aubufread,bufnewfile/etc/nginx/*,/usr/local/n

Detailed introduction to the encryption and decryption methods of Vim text in CentOS Detailed introduction to the encryption and decryption methods of Vim text in CentOS Dec 31, 2023 pm 02:49 PM

CentOS uses vim/vi to encrypt and decrypt files 1. Use vim/vi to encrypt: Advantages: After encryption, if you don’t know the password, you cannot see the plain text, including root users; Disadvantages: It is obvious that others know the encryption , it is easy for others to destroy encrypted files, including content destruction and deletion; I believe everyone is familiar with the vi editor. There is a command in vi to encrypt files. For example: 1) First, in the root master Create an experimental file text.txt under the directory /root/: [root@www~]#vim/vitext.txt2) Enter the editing mode, press ESC after entering the content, and then enter: X (note the capital X), Enter; 3)

See all articles