17. vi 环境选项 Solaris ksh
noautoindent nomodelines noshowmode
autoprint nonumber noslowopen
noautowrite nonovice tabstop=8
nobeautify nooptimize taglength=0
directory=/var/tmp paragraphs=IPLPPPQPP LIpplpipnpbtags=tags /usr/lib/tags
noedcompatible prompt tagstack
noerrorbells noreadonly term=vt100
noexrc redraw noterse
flash remap timeout
hardtabs=8 report=5 ttytype=vt100
noignorecase scroll=11 warn
nolisp sections=NHSHH HUuhsh+c window=23
nolist shell=/bin/ksh wrapscan
magic shiftwidth=8 wrapmargin=0
mesg noshowmatch nowriteany
For C-Shell:
setenv EXINIT "set nu"
For Bourne or Korn Shell:
EXINIT="set nu"; export EXINIT
For Korn Shell Only (alternate method):
typeset -x EXINIT="set nu"
在 .profile 里设置 vi 的环境选项 , 以上均测试过
18.标记文本
mchar 用字母char标记当前光标的位置
`char 移至char所标记处
'char 移至char标记所在行的开头处
" 移至当前行上一次所在位置(在光标移动之后)――一个双引号
'' 移至当前行上第一次所在位置的行的开头处(在光标移动之后)――两个单引号
19.
同时vi多个文件时,CTRL-SHIFT-6回到上一个文件,在本次vi的文件和上次vi的文件之间切换。
但是我发现一个BUG:在用CTRL-SHIFT-6切换到上一个文件后,用:args查看多文件vi状态时,
屏幕底部仍然显示目前vi的是刚才的文件。
(在HP-UX,Solaris,AIX上通过)
也可以使用:
:e#
进行切换
20.
sco 下VI 要在文本前同样的字符加用
%s/^/要加的内容/g 要在文本后同样的字符加
%s/$/要加的内容/g
21.
如何去掉文本中的 ^M 硬回车?不必用binary传回去再ascii传回来的方式,用shell或者unix语句实现。
cat filename |tr -d '\015' >newfile
不同的unix系统还存在一些其他不同的命令,如:doscp
sed 也可以实现这个功能.
dos2unix filename filename2
反之
unix2dos filename filename2
在vi 中用:$s/^M//g
^是crtl-V crtl-M
22.如何在“unix命令行”下将一个文件的某字符串用另一个串换掉
sed 's/string1/string2/gp' file1 > file2
23.将/etc/hosts下所有的地址都ping 2次
1 #/usr/bin/sh
2 #grad /etc/hosts and ping each address
3 cat /etc/hosts|grep -v '^#' | while read LINE
4 do
5 ADDR=`awk '{print $1}'`
6 for MACHINE in $ADDR
7 do
8 ping $MACHINE -n 2
9 done
10 done |
| |