VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

Vim、Emacs配置和使用
回复
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#1

帖子 jsjcjsjc » 2010-01-31 13:10

我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
onelynx
帖子: 817
注册时间: 2008-11-13 16:03

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#2

帖子 onelynx » 2010-01-31 14:17

jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s
头像
adagio
论坛版主
帖子: 22110
注册时间: 2008-02-17 23:47
来自: 美丽富饶的那啥星球

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#3

帖子 adagio » 2010-01-31 14:48

%g/\ -\ .*/d
明天就换大三八!
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……

---------------------------------------------------------------------------------
[图片版]新手当自强(续)FAQ
[新手进阶]挂载、fstab、调整linux分区
[图片版]E17桌面环境配置手把手
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#4

帖子 jsjcjsjc » 2010-01-31 14:54

fzq5012 写了:
jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s

谢谢啊 不过我不知道为什么每个单词右面都有一个.mp3~
onelynx
帖子: 817
注册时间: 2008-11-13 16:03

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#5

帖子 onelynx » 2010-01-31 17:17

jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s

谢谢啊 不过我不知道为什么每个单词右面都有一个.mp3~
那里,都没看到
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#6

帖子 jsjcjsjc » 2010-01-31 17:28

fzq5012 写了:
jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s

谢谢啊 不过我不知道为什么每个单词右面都有一个.mp3~
那里,都没看到
我也不了解啊,难道和缓存有关系我刚才在一个文本中再每行最后添加了一个.mp3

但问题是,我重启一下机器后,命令就不行了,显示不匹配,我把文本传上来 帮忙看一下
附件
a.txt
(239.97 KiB) 已下载 33 次
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#7

帖子 jsjcjsjc » 2010-01-31 21:36

不是很好啊 凑合一下吧
%s/^\(\w\+\).*$/\1/g

www.google.com
onelynx
帖子: 817
注册时间: 2008-11-13 16:03

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#8

帖子 onelynx » 2010-01-31 21:50

jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s

谢谢啊 不过我不知道为什么每个单词右面都有一个.mp3~
那里,都没看到
我也不了解啊,难道和缓存有关系我刚才在一个文本中再每行最后添加了一个.mp3

但问题是,我重启一下机器后,命令就不行了,显示不匹配,我把文本传上来 帮忙看一下
附件
one.txt
(26.86 KiB) 已下载 17 次
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#9

帖子 jsjcjsjc » 2010-02-01 22:46

fzq5012 写了:
jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:
fzq5012 写了:
jsjcjsjc 写了:我想做一个纯单词文本,
现在的文本时这样的

代码: 全选

a (an) - ad. one; any; each 
able - v. having the power to do something 
about - ad. almost ("about half"); of or having a relation to ("We talk about the weather.") 
above - ad. at a higher place 
abuse - n. bad treatment causing harm or injury 
accept - v. to agree to receive 
accident - n. something that happens by chance or mistake; an unplanned event 
accuse - v. to say a person is responsible for an act or crime; to make a statement against someone 
across - ad. from side to side; to the other side 
act - v. to do something 
activist - n. one who seeks change through action 
actor - n. someone acting in a play or show 
add - v. to put (something) with another to make it larger; to say more 
administration - n. the executive part of a government, usually headed by a president or prime minister 
admit - v. to accept ("admitted to the United Nations"
但我就想要这样的

代码: 全选

a (an)
able
about
above
abuse
accept
accident
该怎么做着,麻烦大家了
谢谢
用命令行
:g/-.*$/s

谢谢啊 不过我不知道为什么每个单词右面都有一个.mp3~
那里,都没看到
我也不了解啊,难道和缓存有关系我刚才在一个文本中再每行最后添加了一个.mp3

但问题是,我重启一下机器后,命令就不行了,显示不匹配,我把文本传上来 帮忙看一下
谢谢了不过貌似好有很多不理解啊 为什么会带上一个MP3 搞不懂啊
头像
Strange
帖子: 1824
注册时间: 2006-05-19 9:54
来自: Shanghai

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#10

帖子 Strange » 2010-02-02 9:34

jsjcjsjc 写了: 谢谢了不过貌似好有很多不理解啊 为什么会带上一个MP3 搞不懂啊

代码: 全选

:g/-.*$/s
因为这里实际上是用g调用了没有参数的s命令,没参数的s默认替换的是上次替换的东西。如果上次没有替换过,那么就什么都没有。可见lz用vim替换过mp3 :em09

这个问题的话,直接用s就可以了。

代码: 全选

:s/-.*$//
ニンニク入れますか?
x60 with gentoo
jsjcjsjc
帖子: 152
注册时间: 2007-03-03 13:36

Re: VIM怎么批量进行这样这样有规律的删除,进来看一下吧,一时说不清楚啊

#11

帖子 jsjcjsjc » 2010-02-02 21:16

Strange 写了:
jsjcjsjc 写了: 谢谢了不过貌似好有很多不理解啊 为什么会带上一个MP3 搞不懂啊

代码: 全选

:g/-.*$/s
因为这里实际上是用g调用了没有参数的s命令,没参数的s默认替换的是上次替换的东西。如果上次没有替换过,那么就什么都没有。可见lz用vim替换过mp3 :em09

这个问题的话,直接用s就可以了。

代码: 全选

:s/-.*$//

谢谢
回复