vi

Delete and redirect lines in Vim to another file

做~自己de王妃 提交于 2019-12-07 09:30:27
问题 I want to delete say last 10 lines and move it to another file. What I currently do is: select last 10 lines in visual mode, write these lines by :'<,'>w to other file, and then delete selected lines. Is there any more efficient way I can do this? 回答1: You can use ex commands instead. e.g. :1,10w file.name Write the first ten lines :$-9,$w file.name Write the last ten lines (the dollar sign denotes last line) With the code below in your .vimrc you can use the command :MoveTo file.name

Remove full words containing a string in Vim

假如想象 提交于 2019-12-07 04:40:55
问题 I am trying to remove words from a line if they contain a specific string. Here is an example of the text: host-a, host-b, host-c+test, host-d, host-e+test I want to remove anything that contains +test , to result with: host-a, host-b, host-d Likewise, I need to apply this on a line by line basis, not on all lines in the file. It is going to be used within a macro. How can I do this? 回答1: Something like this, maybe? :%s/\<[-a-z]\++test\>//gc It will ask for each match if you want to replace

Centos7中查看IP命令:IP addr

醉酒当歌 提交于 2019-12-07 03:27:36
转自 https://baijiahao.baidu.com/s?id=1584846175003550177&wfr=spider&for=pc 开机,输入用户名root和上篇文章中设置的密码,(密码在Linux中是看不见的,但确实已经输入了),回车确定,显示时间信息(没有设置时间),表示登陆成功。 在Centos7中,要查看IP地址,不再使用ifconfig命令,而是使用了IP命令。 查看虚拟机IP地址:Ip addr Centos的IP地址是网卡的inet 的值,很明显第一个是本地服务地址,不是我们想要的。第二个没有inet这个属性值。 接下来配置网卡,我的网卡是上图黄色方框中第一行开始的那一部分:eno16777736,你们的可能不一样。使用vi编辑器打开配置文件,注意vi后面有空格: vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 发现默认是不启动网卡的(ONBOOT=no)。然后按J键将光标移动到最后一行,用L键将光标移动到最后一列,再按A键进入到插入模式下,把这一项改为yes(ONBOOT=yes),然后按ESC键退出,再输入命令:wq,再按Enter保存退出到命令行。 然后重启网络服务:service network restart 然后再输入ip addr命令,显示如下图: 我们发现有了IP地址

Vim & Mac: How to copy to clipboard without pbcopy

微笑、不失礼 提交于 2019-12-07 03:09:26
I have a version of vim with both clipboard and xterm_clipboard support. However, "*y or "+y don't copy to the system clipboard. I know I can use :w !pbcopy (and even create a shortcut for it), but I really want the standard way. I saw fakeclip also, but wish to find a solution that is not fake... Moreover, I wish to not need to use "* or "+ and just use y UPDATE: I just checked using the :reg command. I copied some text In another application then in vim ran the :reg command. The text is not there. I then ran MacVim and :reg showed that "* has the copied text. So something wrong with my vim?

Vim replace two words with one another

怎甘沉沦 提交于 2019-12-07 03:01:04
问题 How would one replace all instances of 'foo' with 'bar' and 'bar' with 'foo' in vim? 回答1: Aside from using a temporary word for the change, you could also use abolish plugin like this: :%SubVert/{foo,bar}/{bar,foo}/g 回答2: Take a look at this: how to write only one pattern to exchange two strings in two-ways in vim :s/foo\|bar/\={'foo':'bar','bar':'foo'}[submatch(0)]/g 回答3: :%s/foo/bbaarr/g :%s/bar/foo/g :%s/bbaarr/foo/g It must exist an smartest way to do it, but this one will work for sure !

Replace word with what's ready to put in vi/vim?

China☆狼群 提交于 2019-12-07 02:49:15
问题 For example, I have: rm -f $(NAME).elf $(name).d where the second 'name' is a typo, and should also be 'NAME'. So on 'N', I did y w , and then moved to 'n'. I realised that if I now hit c w to change it, I'll be in insert mode - but I thought ah well, it's only one extra key ( ESC ) and then I can just p the corrected version in. But in that case, p did exactly what u would have done, it put 'name' back. I guess because the 'old text' is loaded into the register on change too, which I didn't

VI (VIM): delete/change right to left?

≡放荡痞女 提交于 2019-12-07 02:11:55
问题 I often use "c-t-$char" change-till-character and "d-t-$char" and would love to be able to do the same thing in reverse. An example: cobbler reposync --only=puppetlabs-6Server-x86_64 If my cursor is at the end of the line and I want to delete backwards to the = char. What brought this on is my wanting to move from BASH emacs mode to vi mode. 回答1: You can use T and F for that. For example cT= or dF= etc. 回答2: d-T-$char deletes from the cursor position backwards without deleting $char , d-F-

如何在VIM中保存编辑的只读文件

荒凉一梦 提交于 2019-12-06 13:02:07
你是否会和我一样经常碰到这样的情景:在VIM中编辑了一个系统配置文件,当需要保存时才发现当前的用户对该文件没有写入的权限。如果已经做了很多修改,放弃保存的确很懊恼,只好先保存在用户的主目录下,再用sudo mv移动到文件的原始位置,并按需要chown。这样做实在太麻烦了,以下的这个技巧就太方便了。当需要保存时,输入以下的命令: :w !sudo tee % 来源: oschina 链接: https://my.oschina.net/u/103999/blog/33916

如何在vi中保存更改过的只读文件

孤者浪人 提交于 2019-12-06 13:01:53
是否会和我一样经常碰到这样的情景:在VIM中编辑了一个系统配置文件,当需要保存时才发现当前的用户对该文件没有写入的权限。如果已经做了很多修改,放弃保存的确很懊恼,只好先保存在用户的主目录下,再用sudo mv移动到文件的原始位置,并按需要chown。这样做实在太麻烦了,以下的这个技巧就太方便了。当需要保存时,输入以下的命令::w !sudo tee % 来源: oschina 链接: https://my.oschina.net/u/103999/blog/35731

render text with escape squence (like a terminal)

孤街醉人 提交于 2019-12-06 12:10:25
Hi, I'm looking for some lib or tool to render text with escape squence chars in a text file. I dont know how to call this, but here is a example: ~$ echo -e "abc\vdef" abc def ~$ ~$ echo -e "abc\vdef" > /tmp/xxxxx ~$ vi /tmp/xxxxx I got abc^Kdef on screen. so i'm searching some tool that can do this for me: ~$ sometool /tmp/xxxxx > /tmp/yyyyy ~$ vi /tmp/yyyyy I can get abc def in vi window. \v is just a example, I need convert \v, \b, \f, etc. to harithski: but what I want is: $~/:sometool /tmp/xxxxx > /tmp/yyyyy in python >>> f=open('/tmp/yyyyyy').readlines() >>> f[0] >>> ['abc\n def'] which