﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-beautykingdom-随笔分类-vi</title><link>http://www.cppblog.com/beautykingdom/category/13011.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 12 Sep 2011 06:38:41 GMT</lastBuildDate><pubDate>Mon, 12 Sep 2011 06:38:41 GMT</pubDate><ttl>60</ttl><item><title>vim configuration</title><link>http://www.cppblog.com/beautykingdom/archive/2011/05/01/145468.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Sun, 01 May 2011 10:31:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2011/05/01/145468.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/145468.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2011/05/01/145468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/145468.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/145468.html</trackback:ping><description><![CDATA[set showcmd&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Show (partial) command in status line.<br />set showmatch&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Show matching brackets.<br />set ignorecase&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Do case insensitive matching<br />set smartcase&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Do smart case matching<br />set incsearch&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Incremental search<br />set autowrite&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Automatically save before commands like :next and :make<br />set hidden&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " Hide buffers when they are abandoned<br />set mouse=a&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" Enable mouse usage (all modes)<br />set nu&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;" set line no on each line&nbsp;<span style="widows: 2; text-transform: none; background-color: rgb(245,247,248); text-indent: 0px; letter-spacing: normal; font: 12px/15px 宋体, Arial; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"> <br />
<p style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt"></span>&nbsp;</p>
<ul style="list-style: disc none outside; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; padding-top: 0px" type="disc"><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">使用<span style="line-height: 1.5">ctrl + r&nbsp;</span>可以搜索历史命令并执行</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">使用<span style="line-height: 1.5">history</span>显示历史，<span style="line-height: 1.5">!!</span>执行上一条命令，<span style="line-height: 1.5">!num</span>执行第<span style="line-height: 1.5">num</span>条命令</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">使用<span style="line-height: 1.5">vi</span>时，<span style="line-height: 1.5">q</span>！调出编辑历史</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">到行首<span style="line-height: 1.5">0</span>，行尾<span style="line-height: 1.5">$</span>，第一个非空格<span style="line-height: 1.5">^</span></span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">不退出<span style="line-height: 1.5">vi</span>能直接执行命令，如<span style="line-height: 1.5">make</span></span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">V</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">模式：正常（<span style="line-height: 1.5">v</span>），行模式<span style="line-height: 1.5">(</span>大写<span style="line-height: 1.5">V)</span>，<span style="line-height: 1.5">block</span>模式（<span style="line-height: 1.5">Ctrl + v</span>）</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">V</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">模式下，<span style="line-height: 1.5">&lt;&gt;</span>缩进所有</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">u</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">撤销，<span style="line-height: 1.5">ctrl+r</span>反撤销</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">ctrl+a</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">跳到命令行首，<span style="line-height: 1.5">ctrl+e</span>跳到命令行尾</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">:s/src/dest/(g)&nbsp;</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">替换当前行第一个或所有</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">:%s/src/dest/g&nbsp;&nbsp;</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">替换全局第一个或所有、</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">bn,bp,bf,bl</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">用于切换缓冲区，<span style="line-height: 1.5">bd</span>删除缓冲区</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">*</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">（<span style="line-height: 1.5">#</span>）用于查找光标位置处的缓冲区</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">ctrl+], ctrl+T</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">用于跳转定义与声明</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">ctrl+p</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">，<span style="line-height: 1.5">ctrl+n</span>用于单词补全</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">ctrl+o</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">，<span style="line-height: 1.5">ctrl+i</span>用于鼠标前后位置跳转</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">!command</span><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">在<span style="line-height: 1.5">vi</span>中执行外部命令</span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">调整窗口，<span style="line-height: 1.5">ctrl+w |</span>宽度最大化，加减宽度<span style="line-height: 1.5">&lt;&gt;</span></span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">调整宽口，<span style="line-height: 1.5">ctrl+w _</span>高度最大化，加减高度<span style="line-height: 1.5">+-</span></span></li><li style="list-style: disc none outside; text-align: left; padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 2em; padding-right: 0px; color: black; padding-top: 0px"><span style="line-height: 1.5; font-family: 宋体; font-size: 12pt">调整窗开，<span style="line-height: 1.5">Ctrl+w =,</span>使窗口等宽</span></li></ul></span><br /><br /><img src ="http://www.cppblog.com/beautykingdom/aggbug/145468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2011-05-01 18:31 <a href="http://www.cppblog.com/beautykingdom/archive/2011/05/01/145468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> vim大小写转换</title><link>http://www.cppblog.com/beautykingdom/archive/2010/09/17/126900.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 17 Sep 2010 10:01:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2010/09/17/126900.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/126900.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2010/09/17/126900.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/126900.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/126900.html</trackback:ping><description><![CDATA[<div class="blogstory" style="float: left; width: 823px; font-size: 14px; line-height: 21px; font-family: verdana, sans-serif; "><div id="art" width="560" style="margin-top: 15px; margin-right: 15px; margin-bottom: 15px; margin-left: 15px; "><font size="2"><br>vim中大小写转化的命令是<br>gu或者gU<br>形象一点的解释就是小u意味着转为小写；大U意味着转为大写.<br><br>剩下的就是对这两个命令的限定（限定操作的行，字母，单词）等等<br><br>1、整篇文章大写转化为小写<br>&nbsp; 打开文件后，无须进入命令行模式。键入:ggguG&nbsp;<br><br></font><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(152, 164, 127); border-right-color: rgb(152, 164, 127); border-bottom-color: rgb(152, 164, 127); border-left-color: rgb(152, 164, 127); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(245, 245, 245); font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; "><font size="2">解释一下：ggguG分作三段gg gu G<br>gg=光标到文件第一个字符<br>gu=把选定范围全部小写<br>G=到文件结束<br></font></blockquote><font size="2">2、整篇文章小写转化为大写<br>&nbsp; 打开文件后，无须进入命令行模式。键入:gggUG&nbsp;<br><br></font><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(152, 164, 127); border-right-color: rgb(152, 164, 127); border-bottom-color: rgb(152, 164, 127); border-left-color: rgb(152, 164, 127); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(245, 245, 245); font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; "><font size="2">解释一下：gggUG分作三段gg gU G<br>gg=光标到文件第一个字符<br>gU=把选定范围全部大写<br>G=到文件结束<br></font></blockquote><font size="2">3、只转化某个单词<br></font><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(152, 164, 127); border-right-color: rgb(152, 164, 127); border-bottom-color: rgb(152, 164, 127); border-left-color: rgb(152, 164, 127); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(245, 245, 245); font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; "><font size="2">guw 、gue<br>gUw、gUe<br>这样，光标后面的单词便会进行大小写转换<br>想转换5个单词的命令如下：<br>gu5w、gu5e<br>gU5w、gU5e<br></font></blockquote><font size="2">4、转换几行的大小写<br>将光标定位到想转换的行上，键入：1gU 从光标所在行 往下一行都进行小写到大写的转换<br>10gU，则进行11行小写到大写的转换<br>以此类推，就出现其他的大小写转换命令<br>gU0 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ：从光标所在位置到行首，都变为大写<br>gU$&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ：从光标所在位置到行尾，都变为大写<br>gUG&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ：从光标所在位置到文章最后一个字符，都变为大写<br>gU1G&nbsp;&nbsp;&nbsp; &nbsp; ：从光标所在位置到文章第一个字符，都变为大写</font></div><div id="art" width="560" style="margin-top: 15px; margin-right: 15px; margin-bottom: 15px; margin-left: 15px; "><font size="2">from:</font></div><div id="art" width="560" style="margin-top: 15px; margin-right: 15px; margin-bottom: 15px; margin-left: 15px; "><font size="2"><a href="http://blog.csdn.net/guowake/archive/2008/03/25/2217086.aspx">http://blog.csdn.net/guowake/archive/2008/03/25/2217086.aspx</a></font></div></div>
<img src ="http://www.cppblog.com/beautykingdom/aggbug/126900.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2010-09-17 18:01 <a href="http://www.cppblog.com/beautykingdom/archive/2010/09/17/126900.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vi know-hows</title><link>http://www.cppblog.com/beautykingdom/archive/2010/03/16/109825.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Tue, 16 Mar 2010 07:04:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2010/03/16/109825.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/109825.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2010/03/16/109825.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/109825.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/109825.html</trackback:ping><description><![CDATA[Moving around<br>These commands help you move around in a file:<br>h<br>Move left one character on the current line<br>j<br>Move down to the next line<br>k<br>Move up to the previous line<br>l<br>Move right one character on the current line<br>w<br>Move to the next word on the current line<br>e<br>Move to the next end of word on the current line<br>b<br>Move to the previous beginning of the word on the current line<br>Ctrl-f<br>Scroll forward one page<br>Ctrl-b<br>Scroll backward one page<br>If you type a number before any of these commands, then the command will be<br>executed that many times. This number is called a repetition count or simply count.<br>For example, 5h will move left five characters. You can use repetition counts with<br>many vi commands.<br><br>Moving to lines<br>The following commands help you move to specific lines in your file:<br>G<br>Moves to a specific line in your file. For example, 3G moves to line 3. With no<br>parameter, G moves to the last line of the file.<br>H<br>Moves relative to the top line on the screen. For example, 3H moves to the line<br>currently 3rd from the top of your screen.<br>L<br>Is like H, except that movement is relative to the last line on screen. Thus, 2L<br>moves to the second-to-last line on your screen.<br><br>Getting out of vi<br>One of the most useful things to know about a new editor is how to get out of it<br>before you do anything you shouldn't do, such as destroying an important<br>configuration file. You can get out of vi by saving or abandoning your changes, or by<br>restarting from the beginning. If these commands don't seem to work for you, you<br>may be in insert mode, which you will learn about in a moment. If in doubt, pressing<br>Esc will leave insert mode and return you to command mode where these<br>commands should work.<br>:q!<br>Quit editing the file and abandon all changes. This is a very common idiom for<br>getting out of trouble.<br>:w!<br>Write the file (whether modified or not). Attempt to overwrite existing files or<br>read-only or other unwritable files. You may give a filename as a parameter,<br>and that file will be written instead of the one your started with. It's generally<br>safer to omit the ! unless you know what you're doing here.<br>ZZ<br>Write the file if it has been modified. Then exit. This is a very common idiom for<br>normal vi exit.<br>:e!<br>Edit the current disk copy of the file. This will reload the file, abandoning<br>changes you have made. You may also use this if the disk copy has changed<br>for some other reason and you want the latest version.<br>:!<br>Run a shell command. Type the command and press Enter. When the<br>command completes, you will see the output and a prompt to return to vi<br>editing.<br>Notes:<br>1. When you type the colon (:), your cursor will move to the bottom line of<br>your screen where you can type in the command and any parameters.<br>2. If you omit the exclamation point from the above commands, you may<br>receive an error message such as one saying changes have not been<br>saved, or the output file cannot be written (for example, you are editing a<br>read-only file).<br>3. The : commands have longer forms (:quit, :write, :edit), but the longer<br>forms are seldom used.<br>vi modes<br>The vi editor has two modes of operation:<br>Command mode<br>In command mode, you move around the file and perform editing operations<br>such as searching for text, deleting text, changing text, and so on. You usually<br>start in command mode.<br>Insert mode<br>In insert mode, you type new text into the file at the insertion point. To return to<br>command mode, press the Esc (Escape) key.<br>These two modes determine the way the editor behaves. Anything you type in insert<br>mode is considered text to be inserted into the file. If you are trying to type a<br>command and nothing happens, or the character appears under the cursor, then you<br>probably forgot to press Esc to escape from insert mode.<br>Editing text<br>Now that you can open a file in vi, move around it and get out, it's time to learn how<br>to edit the text in the file.<br>Modifying text<br>Use the following commands when you need to insert, delete, or modify text. Note<br>that some of these commands have an uppercase form that is similar to the<br>lowercase form; see the descriptions below.<br>i<br>Enter insert mode before the character at the current position. Type your text<br>and press Esc to return to command mode. Use I to insert at the beginning of<br>the current line.<br>a<br>Enter insert mode after the character at the current position. Type your text and<br>press Esc to return to command mode. Use A to insert at the end of the current<br>line.<br>c<br>Use c to change the current character and enter insert mode to type<br>replacement characters.<br>o<br>Open a new line for text insertion below the current line. Use O to open a line<br>above the current line.<br>cw<br>Delete the remainder of the current word and enter insert mode to replace it.<br>Use a repetition count to replace multiple words. Use c$ to replace to end of<br>line.<br>dw<br>Same as for cw (and c$) above, except that insert mode is not entered.<br>dd<br>Delete the current line. Use a repetition count to delete multiple lines.<br>x<br>Delete the character at the cursor position. Use a repetition count to delete<br>multiple characters.<br>p<br>Put the last deleted text after the current character. Use P to put it before the<br>current character.<br>xp<br>This combination of x and p is a useful idiom. This swaps the character at the<br>cursor position with the one on its right.<br>Searching text<br>You can search for text in your file using regular expressions:<br>/<br>Use / followed by a regular expression to search forward in your file.<br>?<br>Use ? followed by a regular expression to search backward in your file.<br>n<br>Use n to repeat the last search in either direction.<br>You may precede any of the above search commands with a number indicating a<br>repetition count. So 3/x will find the third occurrence of x from the current point, as<br>will /x followed by 2n. Similarly, 2/^e will find the second line from the current position<br>that starts with e.<br>Note that search will wrap around to the top once the bottom of file is reached.<br>Getting help<br>Another useful command in vi is the help command, which you invoke by typing<br>:help. Help will open inside vi; use the :q command to leave help and go back to<br>your work. If you want help on some particular topic, say wrapping of lines, try<br>adding a word after the :help command, for example: :help wrap.<br>Putting it together<br>We began by wanting to add a line to our count1.sh file. To keep the original and<br>save the modified version as count2.sh, we could use these vi commands once we<br>open the file with vi. Note that &lt;Esc&gt; means to press the Esc key.<br>Listing 3. Editor commands to add a line to count1.sh<br>1G<br>O<br>sleep 20&lt;Esc&gt;<br>:w! count2.sh<br>:q<br>These commands do the following:<br>1G<br>Move to the first line of the file<br>O<br>Open a new line above it and enter insert mode<br>sleep 20<br>The new text that you want to add<br>&lt;Esc&gt;<br>Press the Esc key to return to command mode<br>:w! count2.sh<br>Write the file to disk<br>:q<br>Close vi<br>Simple when you know how.<br>This is the last article for Exam 101 - Topic 103: GNU and UNIX commands. See our<br>series roadmap for a description of and link to other articles in this series.<br><br>from：<br>IBM Developer works<br><img src ="http://www.cppblog.com/beautykingdom/aggbug/109825.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2010-03-16 15:04 <a href="http://www.cppblog.com/beautykingdom/archive/2010/03/16/109825.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VIM技巧</title><link>http://www.cppblog.com/beautykingdom/archive/2010/02/26/108519.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 26 Feb 2010 14:49:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2010/02/26/108519.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/108519.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2010/02/26/108519.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/108519.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/108519.html</trackback:ping><description><![CDATA[自动排版:&nbsp; gg=G<br>&nbsp;&nbsp;&nbsp;&nbsp; 在粘贴了一些代码之后，vim变得比较乱，只要执行gg=G就能搞定<br><br style="font-weight: bold;">输入不了中文怎么办<br>&nbsp;&nbsp;&nbsp; 要把vi的encoding设置成同系统的编码一样的，通常将其设置成utf8 , set encoding=utf8<br><br>如何弥补vi不能够有多个标签页显示<br>&nbsp;&nbsp;&nbsp; 非常习惯editplus的多标签页，可以同时打开多个文件，vi不支持标签页，但是vi有buffer功能，vi也可以打开多个文件，当然一次只能看到一个文件，在命令行模式下使用:ls 命令，可以看到打开的在buffer里的所有的文件名。例如：<br>&nbsp; 1 #h&nbsp;&nbsp; "control.c"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 1<br>&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "queue.c"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 0<br>&nbsp; 3 %a + "workcrew.c"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 161<br><br>每个文件都有一个标号，如果你想编辑queue.c文件，记住它的标号是2 ，在命令行模式下输入<br>&nbsp;:e #2<br>就可以编辑queue.c这个文件了，好像很麻烦，不过还有简单的方法，可以将这一系列的输入映射到一个键，<br>例如 F5 , 在命令行模式下输入 :<br>&nbsp;:map &lt;F5&gt; :ls&lt;CR&gt;:e #<br>然后按下F5看看是什么效果，可以很简单的选择要编辑的文件了，是不是也挺方便，<br>把上面的 map语句 放入 .vimrc文件， 这样每次启动vi，F5就都生效了<br>Vi在默认的情况下在buffer里的文件切换的过程中，必须要保存当前文件，才能切换到其它文件，这样不太方便，可以用如下的命令搞定：<br>:set hidden<br>这样就同editplus的标签页差不多了。<br><br>忽略大小写<br>vim的查找功能是在命令行下输入 :/待查的字符串，默认vim的查找是区分大小写的，其实大多数情况下都是想进行忽略大小写的查找， 可以使用如下命令：<br>:set ignorecase<br>这样vim在查找时就会忽略大小写了， 可以将其加入.vimrc ,就不用每次都输入了。<br><br style="font-weight: bold;">如何在vim中编译程序<br>原来编程序，我都是在vim下编辑，然后在另外的一个终端窗口中进行 make ,其实在vim中就可以完成make,而且可以将编译的结果也显示在vim里，先执行 :copen 命令，将结果输出的窗口打开，然后执行 :make<br>编译后的结果就显示在了copen打开的小窗口里了，而且用鼠标双击错误信息，就会跳转到发生错误的行。<br><br>vi中的快速编辑： <br><font class="f14" id="zoom"><font color="#000000">在通常模式下:<br>/ 向下查找<br>?
向上查找<br>* 向下查找当前光标下的单词<br># 向上查找当前光标下的单词.<br>f{char}
跳到当前行,当前位置右边的{char}的位置. 如<br>using namespace std;<br>用f; 将会跳到;所在的位置.<br>F{char}
类似f{char},不过,是左边.<br>t{char} 类似f{char},不过,把光标放在{char}的前一个位置.<br>T{char}
类似t{char},不过,是左边.<br>; 重复t T f T 指令<br>, 朝相反方向重复t T f T 指令<br><br>其
实，你在使用*和#的时候，是替换为 /和?来实现的。</font></font><br>from：<br>http://blog.csdn.net/coofive/archive/2006/04/17/666598.aspx
<br><br> <img src ="http://www.cppblog.com/beautykingdom/aggbug/108519.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2010-02-26 22:49 <a href="http://www.cppblog.com/beautykingdom/archive/2010/02/26/108519.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vim奇技淫巧</title><link>http://www.cppblog.com/beautykingdom/archive/2009/11/25/101908.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Wed, 25 Nov 2009 07:50:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2009/11/25/101908.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/101908.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2009/11/25/101908.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/101908.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/101908.html</trackback:ping><description><![CDATA[<span style="border-collapse: collapse; font-family: song,Verdana; font-size: 12px;">总结一下自己经常用vim的一些技巧和操作，很基本的就不写了，很高深的还有待以后补充：<br style="font: 12px song,Verdana;">
<ul>
    <li>替换</li>
</ul>
:%s/abc/abcc/gc<br style="font: 12px song,Verdana;">c表示询问<br style="font: 12px song,Verdana;">:$s/abc/abcc/ge<br style="font: 12px song,Verdana;">e表示即使整个文件没找到一个匹配的目标也不要报错<br style="font: 12px song,Verdana;">:.,$s/yes/no<br style="font: 12px song,Verdana;">.表示当前行，$表示最后一行。总体的语句表示从当前行到最后一样进行匹配<br style="font: 12px song,Verdana;">:s+one/two+one or two+g<br style="font: 12px song,Verdana;">用+替换/<br style="font: 12px song,Verdana;">:s/good\|nice/handsome/g&nbsp;&nbsp;<br style="font: 12px song,Verdana;">把good或nice替换成handsome<br style="font: 12px song,Verdana;">:s/aaa/bbb/g4&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">只替换4行<br style="font: 12px song,Verdana;">:4,9s/\d\+/\=submatch(0)+1/<br style="font: 12px song,Verdana;">第4到9行的数字加一<br style="font: 12px song,Verdana;">:%s/^\w/\=toupper(submatch(0))/g<br style="font: 12px song,Verdana;">首字母大写<br style="font: 12px song,Verdana;">:%s/^/\=line(".").". "/g<br style="font: 12px song,Verdana;">加行号<br style="font: 12px song,Verdana;">
<ul>
    <li>跳转</li>
</ul>
/^abc&nbsp;<br style="font: 12px song,Verdana;">转到以abc开始的行<br style="font: 12px song,Verdana;">ctrl+-&gt; /&nbsp; ctrl + &lt;-&nbsp;&nbsp;<br style="font: 12px song,Verdana;">一次移动一个单词<br style="font: 12px song,Verdana;">30+ /&nbsp; 30-&nbsp;&nbsp;<br style="font: 12px song,Verdana;">向前/向后移动30行<br style="font: 12px song,Verdana;">ctrl+o / ctrl_i&nbsp;&nbsp;<br style="font: 12px song,Verdana;">跳到更老的位置/跳到更新的位置<br style="font: 12px song,Verdana;">{&nbsp;<br style="font: 12px song,Verdana;">跳到上一段&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">} 跳到下一段<br style="font: 12px song,Verdana;">&#8216;&#8220;&nbsp;<br style="font: 12px song,Verdana;">跳到上次关闭文件时，在NOMAL模式下的光标所在行<br style="font: 12px song,Verdana;">&#8217;^&nbsp;<br style="font: 12px song,Verdana;">跳到上次关闭文件时，在INSERT模式下的光标所在行<br style="font: 12px song,Verdana;">
<ul>
    <li>宏</li>
</ul>
qa&nbsp;<br style="font: 12px song,Verdana;">开始记录宏（这里的a可以用任意一个字母代替）<br style="font: 12px song,Verdana;">q&nbsp;&nbsp;<br style="font: 12px song,Verdana;">结束宏记录<br style="font: 12px song,Verdana;">@a&nbsp;<br style="font: 12px song,Verdana;">执行名字为a的宏<br style="font: 12px song,Verdana;">
<ul>
    <li>标记</li>
</ul>
ma&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">标记此行为a<br style="font: 12px song,Verdana;">&#8216;a&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">移到标记为a的行<br style="font: 12px song,Verdana;">mA/'A&nbsp;&nbsp;<br style="font: 12px song,Verdana;">可以跨文件进行标记<br style="font: 12px song,Verdana;">
<ul>
    <li>补全</li>
</ul>
Insert模式下,ctrl+n&nbsp; / ctrl+p&nbsp;&nbsp;<br style="font: 12px song,Verdana;">补全<br style="font: 12px song,Verdana;">ctrl+a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">重复上次在Insert模式下的动作<br style="font: 12px song,Verdana;">Insert模式下，ctrl+y / ctrl+e&nbsp;&nbsp;<br style="font: 12px song,Verdana;">重复上一行/下一行光标处的字符<br style="font: 12px song,Verdana;">:iab xl xulei&nbsp;<br style="font: 12px song,Verdana;">当键入xl(空格)时，会被替换成xulei<br style="font: 12px song,Verdana;">ctrl+x ctrl+n<br style="font: 12px song,Verdana;">在文件中补全以前出现过的单词<br style="font: 12px song,Verdana;">ctrl+x ctrl+p<br style="font: 12px song,Verdana;">在文件中补全以前出现过的单词<br style="font: 12px song,Verdana;">ctrl+x ctrl+l<br style="font: 12px song,Verdana;">在文件中补全以前出现过的一行<br style="font: 12px song,Verdana;">ctrl+x ctrl+f<br style="font: 12px song,Verdana;">补全文件名<br style="font: 12px song,Verdana;">ctrl+x ctrl+k<br style="font: 12px song,Verdana;">单词补全<br style="font: 12px song,Verdana;">ctrl+x ctrl+t<br style="font: 12px song,Verdana;">同义词补全<br style="font: 12px song,Verdana;">
<ul>
    <li>其他</li>
</ul>
用v选中多行， 然后 !sort&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">可以实现排序<br style="font: 12px song,Verdana;">g ctrl+G(先按g然后按ctrl+G) &nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">统计字数（或先用v选中部分需要统计的文字）<br style="font: 12px song,Verdana;">将光标移到一个函数上，K（大写）&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">将自动man此函数<br style="font: 12px song,Verdana;">在一个vim文件中:grep abc *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">将匹配到所有包好abc的文件 :cn下一个&nbsp; :cp上一个&nbsp; :cl文件列表<br style="font: 12px song,Verdana;">vim `grep -l abc *`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">打开包含abc的所有文件<br style="font: 12px song,Verdana;">ctrl+c=esc<br style="font: 12px song,Verdana;">:history&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">命令记录<br style="font: 12px song,Verdana;">q:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">打开命令行历史窗口<br style="font: 12px song,Verdana;">q/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">打开查找历史窗口<br style="font: 12px song,Verdana;">:w filename &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">另存为<br style="font: 12px song,Verdana;">：1，3w filename&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">1-3行另存为<br style="font: 12px song,Verdana;">Insert模式下，ctrl+w&nbsp;&nbsp;<br style="font: 12px song,Verdana;">删除前一个单词<br style="font: 12px song,Verdana;">Insert模式下，ctrl+u&nbsp;&nbsp;<br style="font: 12px song,Verdana;">删除此行光标前所有单词<br style="font: 12px song,Verdana;">:set showmatch&nbsp;&nbsp;<br style="font: 12px song,Verdana;">当键入if(i&gt;0)的)的时候，光标会跳到(处停留1/10秒，再回来<br style="font: 12px song,Verdana;">:set cindent shiftwidth=4&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">设置缩进<br style="font: 12px song,Verdana;">=a{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="font: 12px song,Verdana;">调整{}之间的缩进格式<br style="font: 12px song,Verdana;">gu&nbsp;&nbsp;<br style="font: 12px song,Verdana;">变小写&nbsp;&nbsp;<br style="font: 12px song,Verdana;">gU&nbsp;<br style="font: 12px song,Verdana;">变大写<br style="font: 12px song,Verdana;">光标定位在数字上ctrl+a&nbsp;<br style="font: 12px song,Verdana;">增1<br><br><br><br></span>
<div><font face="song, verdana" size="3"><span style="border-collapse: collapse; font-size: 12px;">转自：</span></font></div>
<div><font face="song, verdana" size="3"><span style="border-collapse: collapse; font-size: 12px;"><a href="http://blog.chinaunix.net/u2/86590/showart.php?id=2087339">http://blog.chinaunix.net/u2/86590/showart.php?id=2087339</a></span></font></div><img src ="http://www.cppblog.com/beautykingdom/aggbug/101908.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2009-11-25 15:50 <a href="http://www.cppblog.com/beautykingdom/archive/2009/11/25/101908.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>