能不能在 Vim 的命令模式下插入字符?

能不能在 Vim 的命令模式下插入字符?,第1张

1. 可以定义快捷键Ctrl+a,用来在Command模式下在当前光标后面插入一个指定字符:map <C-a>:a_<ESC>r2. 使用o在当前行下面插入一个新行,使用大写的O在当前行的上面插入新行。-----更新------看了本问题的讨论,这个其实见仁见智吧。就按键次数来说确实并没有太多的变化,但是从 *** 作流程来讲,进入Inert模式和进入Command模式是两种截然不同的情境,始终保持在Command模式下, *** 作者的思路不容易打断。当然你如果习惯了这两个模式的切换,就已经不太重要了。这是个小问题,不过充分证明了VIM就是强大,你想咋做就咋做。你甚至可以直接定义一个快捷键在行末插入分号,那就只有两次按键了。

现在假设如是

nc10@your-5554c55be4 ~

$ cat sheet

server 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08

server 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09

server 127.0.0.1 localhost connected no 16-9-09

nc10@your-5554c55be4 ~

$ sed '/^server.*$/s//&test/g' sheet

server 127.0.0.1 localhost connected yes 12-3-08 test

server 127.0.0.1 localhost connected no 12-3-08 test

server 127.0.0.1 localhost connected yes 14-9-09 test

server 127.0.0.1 localhost connected yes 15-9-09 test

server 127.0.0.1 localhost connected no 16-9-09 test

nc10@your-5554c55be4 ~

$

希望没理解错你的意思,呵呵

如果文件这样也可的,因为 /^server/ 限定了 只是行头

server 才在行尾插入字符

user@minix-nb:~$ cat sheet

remote 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08

remote 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09

remote 127.0.0.1 localhost connected no 16-9-09

user@minix-nb:~$ sed '/^server.*$/s//&test/g' sheet

remote 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08 test

remote 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09 test

remote 127.0.0.1 localhost connected no 16-9-09

user@minix-nb:~$

现在假设如是

nc10@your-5554c55be4 ~

$ cat sheet

server 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08

server 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09

server 127.0.0.1 localhost connected no 16-9-09

nc10@your-5554c55be4 ~

$ sed '/^server.*$/s//&test/g' sheet

server 127.0.0.1 localhost connected yes 12-3-08 test

server 127.0.0.1 localhost connected no 12-3-08 test

server 127.0.0.1 localhost connected yes 14-9-09 test

server 127.0.0.1 localhost connected yes 15-9-09 test

server 127.0.0.1 localhost connected no 16-9-09 test

nc10@your-5554c55be4 ~

$

希望没理解错你的意思,呵呵

如果文件这样也可的,因为 /^server/ 限定了 只是行头是

server 才在行尾插入字符

user@minix-nb:~$ cat sheet

remote 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08

remote 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09

remote 127.0.0.1 localhost connected no 16-9-09

user@minix-nb:~$ sed '/^server.*$/s//&test/g' sheet

remote 127.0.0.1 localhost connected yes 12-3-08

server 127.0.0.1 localhost connected no 12-3-08 test

remote 127.0.0.1 localhost connected yes 14-9-09

server 127.0.0.1 localhost connected yes 15-9-09 test

remote 127.0.0.1 localhost connected no 16-9-09

user@minix-nb:~$


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7978357.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存