在水母上看到的VIM 测试题,面向初学者
发信人: thinelephant (光吃不长), 信区: VIM
标 题: VIM 测试题(给用 VIM 做数据处理的初学者)
发信站: 水木社区 (Thu Oct 27 20:21:50 2005), 站内
以前写的,主要是针对数据处理的,虽然写得不好,不过也发到版上留个备份啦。:-)
VIM 测试题(给用 VIM 做数据处理的初学者)
请回答以下操作所需的步骤或命令:
01. (4) 光标移到最后一行
02. (4) 设置跳格(Tab)宽度为 4
03. (4) 忽略大小写查找字符串 elephant(本题不得使用 GUI)
04. (4) 将所有 elephant 替换为 pig(本题不得使用 GUI)
05. (4) 打开 VIM 关于正则表达式的帮助文档
06. (4) 在阅读 VIM 帮助时遇到链接如何跳转?如何返回?
07. (6) 比较编辑两个内容相近的文件
08. (6) 借助外部命令 sort 将文件的行按字母顺序进行排序
09. (6) 将每一行的第一个字符与第二个字符交换
10. (6) 将当前目录中所有文件的文件名插入到当前文本中
假设文件 data.txt 内容如下:
ACDSee 000001 499.95 ACD Systems, Ltd.
Internet Explorer 000004 1999.50 Microsoft Corp.
Vi IMproved 000015 0.00 Bram Moolenaar
FlashFXP 000204 199.00 CEDsoft
请回答以下操作所需的正则表达式(可查阅帮助,反复尝试):
11. (4) 匹配每行的软件名字段
12. (4) 匹配每行的编号字段
13. (4) 匹配每行的价格字段
14. (4) 匹配每行的开发者字段
请回答以下操作所需的步骤或命令:
15. (6) 交换每行的编号和价格字段
16. (8) 借助外部命令 sort 将文件的行按软件价格进行排序
17. (8) 将连续两个或以上的空格替换为一个跳格字符
18. (6) 删除每行的开发者字段
送分题,写得越多越好:
19. (8) 请写出任何难以用 notepad 完成的并且你会的 VIM 功能。
============================================================================
参考答案
01. G
在 Normal 模式下按 G 快速跳到最后一行,按 gg 跳到第一行,当然,也可以按
Ctrl-Home 和 Ctrl-End。
02. :set tabstop=4
将 Tab 设成大一点的宽度,比如 16,查看数据文件的时候比较有用,对齐清晰。
03. 方法一,先设置忽略大小写,然后查找
:set ignorecase
/elephant
:set noignorecase
方法二,在前面加入 \c 表示忽略大小写
/\celephant
04. :%s/elephant/pig/g
g 表示如果一行有多个 elephant 将全部替换,没有 g 表示只替换每行第一个。
另外还有 i 标志,有 i 表示忽略大小写。i g 这两个标志非常基础!
05. :help pattern
用 :help xxx 看一个东西帮助,提示:在 :help 后面可以尝试按 tab 补全,
比如输入 :help search 然后按 tab(一次或多次),你就可以看到
search-pattern 正是你想要看的。
06. Ctrl-] Ctrl-T
帮助里面用两个 | 括起来高亮的,比如 |pattern| 都是可以跳转的链接,按
Ctrl-](按住 Ctrl 按右中括号)跳进去,再按 Ctrl-T 跳回来。
07. 在命令行下 vim -d file1.txt file2.txt 可以用比较模式查看编辑两个文件,
或者如果在 Windows 下面,可以先选中两个文件,然后鼠标右点菜单,选
“Diff with Vim”。一般在比较某个文件的两个版本(即是一个是以前的,
一个是修改后的)时很有用。
08. :%!sort
表示将整个文件的行用外部命令 sort 过滤一遍,不过要当心 Windows 的 sort
命令在某些条件下会产生错误的排序结果。
09. 方法一,用正则表达式匹配替换每行的前两个字符
:%s/^\(.\)\(.\)/\2\1/
方法二,用块选择
Normal 模式下,先把光标移到第一行第一个字符上,按 Ctrl-V 进入块选择模式,
移动光标到最后一行第一个字符上,这时选中的是每一行的第一列字符,按 d
删除,然后移动光标到第一行第二个字符,按 P(注意是大写)粘贴,刚才删除的
第一列就被粘到第二列上了。
10. :split .
打开当前目录(. 表示当前目录,当然也可以是比如 C:\ ),然后就可以将目录
中的文件名复制粘贴过来了。
请把 :help pattern 那一页帮助内容仔仔细细阅读 99 遍!:-)
11. 软件名字段的特征是:位于行首;由若干个单词组成,单词之间用一个空格分开。
^\S\+\( \S\+\)*
12. 编号字段的特征是:恰好六个数字。
\<\d\{6}\>
13. 价格字段的特征是:若干个数字,一个点,若干个数字。
\d\+\.\d\+
14. 开发者字段的特征跟软件名字段的特征类似,但是位于行末。
\S\+\( \S\+\)*$
15. 同 09 题方法二,用块选择。
16. 用块选择将价格字段换到前面,然后用 :%!sort 排序,然后换回来。
17. :%s/ \+/\t/g (注意这里是两个空格)或者
:%s/ \{2,}/\t/g
18. 用块选择,按 D(大写)删除。块选择后按 d 跟 D 的区别是:d 删除选中的块,
D 删除选中的块以及后面一直到行末的内容。
19. 略。
Comments
Would you be involved in exchanging links?
Posted by: Masako Zysk | July 15, 2012 1:30 PM
Throughout this awesome pattern of things you actually get an A+ with regard to effort. Where exactly you actually confused me was on all the particulars. As it is said, details make or break the argument.. And that could not be much more accurate here. Having said that, let me reveal to you just what exactly did deliver the results. The article (parts of it) is rather powerful which is most likely the reason why I am making the effort to opine. I do not really make it a regular habit of doing that. 2nd, although I can easily see the leaps in logic you come up with, I am not convinced of just how you seem to unite your details which help to make the actual final result. For the moment I will, no doubt yield to your position but hope in the foreseeable future you actually link the facts much better.
Posted by: bache a bulle piscine intex | August 25, 2012 10:08 AM
Thank you, I've just been searching for information approximately this topic for a long time and yours is the greatest I've came upon till now. But, what in regards to the bottom line? Are you certain about the supply?
Posted by: Janyce Sjostrand | September 15, 2012 1:49 PM
My son and i are testing the waters and I'm helping him build a very simple side scroller.
Posted by: Leo Kustes | September 20, 2012 7:29 AM
What i do not understood is in fact how you're now not actually a lot more neatly-preferred than you may be now. You're so intelligent. You understand therefore considerably in the case of this matter, produced me in my opinion consider it from numerous numerous angles. Its like men and women are not interested unless it's something to accomplish with Woman gaga! Your individual stuffs nice. At all times take care of it up!
Posted by: buy viagra | September 21, 2012 4:38 PM
Some genuinely good blog posts on this site, thanks for contribution. "Once, power was considered a masculine attribute. In fact, power has no sex." by Katharine Graham.
Posted by: buy viagra without prescription | September 21, 2012 5:22 PM
Hello. Very cool website!! Man .. Beautiful .. Superb .. I will bookmark your blog and take the feeds additionally...I'm happy to find a lot of useful information here within the article. Thank you for sharing.
Posted by: Vipassana Meditation | September 22, 2012 5:37 PM
Hey amiga!!! I love the dress but... I think the top is SO YOU!! So colorful and free flowing- which is my choice for you. You'll produce a splash in either. I like the Limited but haven't shopped there in the while- many thanks for that reminder. Hugs!!
Posted by: Oswaldo Dobrasz | September 22, 2012 8:28 PM
I have been reading out countless of your posts and i can application skillful pack. I will make definite to bookmark your blog.
Posted by: Myszki | September 25, 2012 4:25 PM
I always was interested in this subject and still am, thanks for posting.
Posted by: Christian Guitar Tabs | September 30, 2012 10:29 PM
Do you have a spam issue on this site; I also am a blogger, and I was curious about your situation; many of us have created some nice methods and we are looking to exchange strategies with others, why not shoot me an email if interested.
Posted by: Hausfrauen Tittenfick | October 3, 2012 8:45 AM
I bought many a VW for my huge family members at Jack Poet VW; six blocks past the Kukamunga Cutoff just south of the Pismo Beach Wrestling Arena in stunning Highland Park The Bronx.
Posted by: Olivia Schlichter | October 7, 2012 5:43 AM
Wohh exactly what I was looking for, thanks for posting . "Be nice to everyone on your way to the top because you pass them all on the way down." by Fred Hufnagel, Sr..
Posted by: durchgefickt | October 8, 2012 12:24 PM
I really appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thanks again!|
Posted by: Monique Alexander | October 9, 2012 6:36 AM
Can you try a E-cig without ever smoking a real cigarette?
Posted by: electronics cigarette karachi | October 11, 2012 9:21 AM
Just wanna say that this is handy , Thanks for taking your time to write this. "Guilt is a rope that wears thin." by Ayn Rand.
Posted by: Christian Guitar Tabs | October 11, 2012 2:08 PM
Thank you, I have recently been hunting for information about this subject matter for ages and yours is the best I have found so far.
Posted by: Learn Even more Here | October 12, 2012 10:03 AM
Hey from across the sea! This is just what I was looking for, and you nailed it. Thankyou
Posted by: reiki attunements | October 15, 2012 1:43 AM
Superior read. I wish i may take advice like that and simply do it. instead unwell think about it for every week then neglect it :( perhaps i can change
Posted by: Great website | October 23, 2012 3:30 AM
Hello, i really enjoy reading your blog. I like the way its put together, and totally dig the design. Is there any way to subscribe to your site?
Posted by: bbw cams | October 26, 2012 1:42 PM
This article has inspired me to start focusing on my own blog
Posted by: http://www.vitaminfaq.net/2012/05/magnesium-malate.html | November 8, 2012 5:23 AM
Thanks for sharing such a superb publish. I'm genuinely amazed how very good of a author you genuinely are. I been active for hrs going thru your materials. Great stuff.
Posted by: Enoch Manzone | November 17, 2012 12:39 AM
Keep working ,great job!
Posted by: diseño | November 22, 2012 7:37 AM
Ways to Find The Optimal Price To Charge For your personal Products
Posted by: Ezra Schipper | November 30, 2012 8:29 AM
take some english classes man.. i cant understand a word what u said
Posted by: Google rankings | December 2, 2012 5:34 PM
I felt that way about the Holiday collection with the puffy.
Posted by: Carson Arre | December 3, 2012 12:53 PM
I really enjoy the blog post. Fantastic.
Posted by: Monica Thomann | December 7, 2012 8:47 AM
I ordered mine last week for $55 and it comes with about a carton of cigarettes worth of cartridges...in some places, a carton of cigarettes cost more than that so I considered it a GREAT deal!
Posted by: Himpled | December 8, 2012 7:27 AM
/*=========================================================================*\
Posted by: http://carb-backloading.com/ | December 8, 2012 8:44 PM
Wowgirls.com launched in 2011 and since then it has offered a new WOW scene of the finest erotic content, girl-girl or solamente beauty shoots. All of the their content is 100% specialized with ultra-fast downloads of photographs and videos or you can stream the videos directly from the site.
Posted by: nude photography | December 9, 2012 11:06 PM
Wowgirls.com launched in 2011 and since then it has offered a new WOW scene of the best erotic content, girl-girl or unicamente beauty shoots. All of the their content is 100% specialized with ultra-fast downloads of photographs and videos or you can flow the videos directly from all the site.
Posted by: erotic teens | December 10, 2012 2:20 PM
It seems like you're creating issues yourself by attempting to solve this concern as a substitute of looking at why their can be a problem to begin with
Posted by: life fashion style | December 11, 2012 1:37 PM
Morgan State, on the corner of Cold Spring and Hillen Rd. or farther north along Hillen. You will find lots of hungry people who never have time and energy to wander each of the way down to the food items court. We're bored with Subway!
Posted by: ephedrine | December 11, 2012 4:51 PM
This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.
Posted by: Gerald Tindall | December 15, 2012 7:27 AM