2012年3月25日星期日

vim note from ChinaUnix

自己最近总结了下关于VI的一些基本用法阿 ,献给大家阿~~

1.*关于退出:*
:wq! ----强制保存退出
:wq  ---- 保存退出
:  x   ----- 作用和:wq 一样
ZZ  ---- 作用和:wq一样,(注意Z是大写的,并且不是在命令模式)
:q  ---- 退出
:q! ---  强制退出
========================================================
2.*关于移动:*
h : 在当前行向左移动一个字符
j: 移动到下一行
k:移动到上一行
l:在当前行向右移动一个字符
Ctrl +f: 向前滚动一页
Ctrl +b:向后滚动一页
:n   将光标定位到第n行
:   $   将光标定位到最后一行
0    将光标定位到本行的行首
$    将光标定位到本行的行尾
G    将光标定位到本文章的最后一行,与:   $功能相同。
H    将光标定位到屏幕的顶端
M    将光标定位到屏幕的中间
L     将光标定位到屏幕的底端
=============================================================
3.*关于搜索:*
/: 后面跟要查找的东西,在文件中向前搜索
?:后面跟要查找的东西,在文件中向后搜索
n: 向前重复搜索
N: 向后重复搜索
=============================================================
4.*关于复制*
yy: 复制光标当前行
nyy: 复制光标当前行到当前行以下的n-1行
:1,100 co 200 将1~100的内容复制到第200行。
:100,102 co $ 将100~102行的内容复制到最后一行。
==============================================================
5.*关于粘贴:*
p :   粘贴到当前行的下一行
P(大) :   粘贴到当前行的 上一行
==============================================================
6.*关于删除.剪切:*
dd  删除当前行
ndd  与nyy相似
dw  删除一个单词
ndw  与ndd相似
x    删除一个字符
nx   删除n个字符
dG   删除当前光标到文件末尾的所有内容。
d0   删除当前光标到本行行首的所有内容
d$   删除当前光标到本行行尾的所有内容
:1,100d  删除1~100
:100d    删除第100行
:1,100 mo $  将1~100行的内容移动到最后一行。
======================================================
7.*关于插入:*
i:  在当前位置的字符前面进入插入模式
I: 在当前行的开头进行插入
a: 在当前位置的字符后面进入插入模式
A: 在当前行的结尾进行插入
o:  在当前行下面打开一个新行进行插入
O:在当前行上面打开一个新行进行插入
======================================================
8.*关于撤销:*
u: 撤销上一次的更改
=======================================================
9.*关于替换:
r*egexp:是要匹配的式样
replacement: 是要替换的字符串*
*:s /regexp/replacement  -------------------------替换当前行出现的第一个式样
:s/regexp/replacement/g-------------------------替换当前行所有的匹配
:%s/regexp/replacement/g-----------------------替换文件中所有匹配式样
==========================================================

*PS: 还有一个重要的命令就是"." 命令,这个命令是用来重复上一命令的*

2012年3月21日星期三

strtok.c Apple Implementation

strtok.c   [plain text]


/*
 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
 *
 * @APPLE_LICENSE_HEADER_START@
 * 
 * The contents of this file constitute Original Code as defined in and
 * are subject to the Apple Public Source License Version 1.1 (the
 * "License").  You may not use this file except in compliance with the
 * License.  Please obtain a copy of the License at
 * http://www.apple.com/publicsource and read it before using this file.
 * 
 * This Original Code and all software distributed under the License are
 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * @APPLE_LICENSE_HEADER_END@
 */
/*
 * Copyright (c) 1988, 1993
 * The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 * This product includes software developed by the University of
 * California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */


#include <stddef.h>
#include <string.h>

char *
strtok(s, delim)
 register char *s;
 register const char *delim;
{
 register char *spanp;
 register int c, sc;
 char *tok;
 static char *last;


 if (s == NULL && (s = last) == NULL)
  return (NULL);

 /*
  * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
  */
cont:
 c = *s++;
 for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
  if (c == sc)
   goto cont;
 }

 if (c == 0) {  /* no non-delimiter characters */
  last = NULL;
  return (NULL);
 }
 tok = s - 1;

 /*
  * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
  * Note that delim must have one NUL; we stop if we see that, too.
  */
 for (;;) {
  c = *s++;
  spanp = (char *)delim;
  do {
   if ((sc = *spanp++) == c) {
    if (c == 0)
     s = NULL;
    else
     s[-1] = 0;
    last = s;
    return (tok);
   }
  } while (sc != 0);
 }
 /* NOTREACHED */
}