发信人: flea (boyibolomi), 信区: Java
标 题: 随笔--刚入行的程序员如何提升技术修养
发信站: 水木社区 (Sun Aug 20 00:23:19 2006), 站内
想象把程序员放到水中,需要学习的东西会在两个层次上,
水底下的是基础知识,水面上的是应用知识。
基础知识:Java语言本身的方方面面,OOP的模式和理论,等。
基础知识扎实是进入最顶尖的IT公司作研发的必要条件。
把基础知识放在水底,因为掌握足够多的基础知识需要有耐心,俗称沉得下去。
应用知识:是关于工作所需的工具、组件、框架、容器、规范的知识,
了解这些知识,到达能够应用的程度,表面看来可能技术含量不高。
我看有些技术培训,就是把学员教到这样的水平: 知道Eclipse怎么用,spring怎么配置,hibernate怎么配置。
在BBS上看到比较多的讨论的话题,也是关于各种基础知识点,或者是应用的经验。大学毕业生通常能够有一些基础知识和应用知识,不过距离企业的需要还有一定的差距。
要做一个合格的程序员,还需要大量的练习和实践,学会写出优美的代码。
这里只讨论和技术,编码有关的事情,所以沟通能力、协作思想就不扯了。
技术发展到今天,各种框架的出现简化了程序员的工作,也降低了程序员掌握牢固的基础知识的要求。也使得一些朋友感叹:没有技术含量,只剩体力劳动。
感叹没有技术含量,说明朋友们还是希望提升自身技术修养。
个人认为比较适当的不断提高技术水平的途径,可以采用“带着问题学习”的方法。
个人的体验,这是一个波动的过程:不断的潜入水底,又浮出水面,如此往复。
基础知识涉及到方方面面,很难一下两下完全掌握,往往越学越觉得茫然。
为了掌握基础知识而专门潜水,不容易成功,要么是小有所成就浮起来,要么是看不到修成正果的一天而放弃。
水面上的应用知识和问题往往是很好的学习的起点,如果仅仅满足于知其然,很难成为高手,如果多问几个为什么,那么答案通常就在水底。
例如,为什么出现spring?为何叫做轻量级应用框架?为什么要写单元测试?为什么会有AOP?
技术是为应用服务的,在水面上最容易发现问题,通过不断的发现问题和解答,也就是不断的潜水和浮起,时间越长,自然功力越深。
基础知识不好,不值得自卑;应用知识很丰富,不值得炫耀。大家都在不断的学习中进步,只是先后的不同吧。
--
可爱的(免费的)向日葵小秘书 qq: 345313746 msn: sunflower.alloky@hotmail.com
http://www.alloky.com - 全方位软件服务
2008-03-21
2008-03-17
my back is just killing me!
没衔接好,又一次错过P bus,tnnd!
提着重重的三个bag,中途歇了几次好容易到家了。
还没喘口气,心里又惦记中午出发时候看到的那个TV,不知还在否?
下去一看,还在那里waiting,二话不说,move之。
我起...嗯?没动静,我再起...Faint,这么重的啊,这简直就是悟空的定海神针好不好?
谁叫我贪念过重呢,要不说人的潜能是无限的呢,谁想到我这么柔弱女子就硬生生的把它给弄回来了,过程中如此如此艰辛暂且不表。
回家急不可耐的调试,搞不定,只能等我家的修理工xiaogg回来看看了。
现在本人状态:习惯性驼背,有点儿那次京西草原骑马后的症状了。
提着重重的三个bag,中途歇了几次好容易到家了。
还没喘口气,心里又惦记中午出发时候看到的那个TV,不知还在否?
下去一看,还在那里waiting,二话不说,move之。
我起...嗯?没动静,我再起...Faint,这么重的啊,这简直就是悟空的定海神针好不好?
谁叫我贪念过重呢,要不说人的潜能是无限的呢,谁想到我这么柔弱女子就硬生生的把它给弄回来了,过程中如此如此艰辛暂且不表。
回家急不可耐的调试,搞不定,只能等我家的修理工xiaogg回来看看了。
现在本人状态:习惯性驼背,有点儿那次京西草原骑马后的症状了。
2008-03-14
Programming in C
# tutorial
http://www.72up.com/c/
http://www.72up.com/c/chapter_1.htm
..
http://www.72up.com/c/chapter_11.htm
http://www.72up.com/c/
http://www.72up.com/c/chapter_1.htm
..
http://www.72up.com/c/chapter_11.htm
2008-03-13
Programming in Fortran
# real -> integer
ceiling -> +inf
floor -> -inf
aint (dint) -> 0
anint (dnint) -> round off
nint (idnint) -> round off
atan2(y,x) ! atan(y/x) in [-pi,pi]
shape ! dimension
size ! nr. of elements
dot_product(v1, v2) ! dot product
dprod(x,y) ! double-precision product
matmul(m1, m2) ! matrix multiply
pi = dacos(-1d0)
pi = acos(-1e0)
Compaq Visual Fortran
File - New - Projects - Fortran Console Application
File - New - Fortran
Project - Setting - Fortran - -optimize:5
Build - Set Active Configuration - Win32 Release/Debug
Compile
Debug
Profile
! keyboard
Build
Compile
Execute
ceiling -> +inf
floor -> -inf
aint (dint) -> 0
anint (dnint) -> round off
nint (idnint) -> round off
atan2(y,x) ! atan(y/x) in [-pi,pi]
shape ! dimension
size ! nr. of elements
dot_product(v1, v2) ! dot product
dprod(x,y) ! double-precision product
matmul(m1, m2) ! matrix multiply
pi = dacos(-1d0)
pi = acos(-1e0)
Compaq Visual Fortran
File - New - Projects - Fortran Console Application
File - New - Fortran
Project - Setting - Fortran - -optimize:5
Build - Set Active Configuration - Win32 Release/Debug
Compile
Debug
Profile
! keyboard
Build
Compile
Execute
2008-03-12
Programming in matlab
cf.
http://neural.cs.nthu.edu.tw/jang/books/matlabProgramming4beginner/cdrom/matlabProgramming4beginner/slide/
# command-line mode: similar to bash emacs mode
C-P/N navigate in the command history
C-A/E start/end of line
C-B/F backward/forward
C-U kill the line (not kill to the start)
C-K kill to the end of line
C-R search
C-H/D backspace/delete
# external
!cmd
[status, result] = UNIX('cmd')
getenv('name')
# example
!which plot # search "plot" in $PATH
which plot # the location of file/function "plot"
# round
round, ceil, floor
# timer
tic
...
toc
# string
strcmp(A, B [,n]) % 字符串比较 (前n个字符)
strmatch('substr', StrMatrix) % 匹配测试
findstr('string', 'substr') % 子串查找
strrep('string', 'sub', 'rep') % 子串替换
# special matrix
zeros(2, 3) # all 0
ones(1, 3) # all 1
eye(3) # elementary
linspace(x0, xN, npoints) # default: npoints = 100
reshape, repmat, diag
upper, lower
svd
# matrix, vector
size, length
det, norm
rank
sum
mean # average
var # variance
std # std. deviation
max/min
inv(X) # inverse matrix
eig(X) # vector of eigenvalues
[V, D] = eig(X) # X V = V D
# matrix function
sqrtm, expm, logm
find(A gt 0)
eq(A,B) neq lt le gt ge
all any exist
for i=1:7
i
end
if (i gt 0)
positive
elseif i lt 0
negative
else
0
end
while (i gt 0)
..
end
function [out1, out2] = myfunction(input1, input2)
# plot
figure # new figure
axis([xmin xmax ymin ymax])
axis equal/normal/image
xlabel('radians')
ylabel('sin value')
title('dummy')
legend('sin', 'cos')
subplot(m, n, c); # mxn, c is the current
hold on/off
grid on/off
box on/off
plot
loglog
semilogx
semilogy
plotyy # double-y
fplot('function', [xmin, xmax])
polar(theta, r)
# color
b: blue
g: green
k: black
r: red
w: white
http://neural.cs.nthu.edu.tw/jang/books/matlabProgramming4beginner/cdrom/matlabProgramming4beginner/slide/
# command-line mode: similar to bash emacs mode
C-P/N navigate in the command history
C-A/E start/end of line
C-B/F backward/forward
C-U kill the line (not kill to the start)
C-K kill to the end of line
C-R search
C-H/D backspace/delete
# external
!cmd
[status, result] = UNIX('cmd')
getenv('name')
# example
!which plot # search "plot" in $PATH
which plot # the location of file/function "plot"
# round
round, ceil, floor
# timer
tic
...
toc
# string
strcmp(A, B [,n]) % 字符串比较 (前n个字符)
strmatch('substr', StrMatrix) % 匹配测试
findstr('string', 'substr') % 子串查找
strrep('string', 'sub', 'rep') % 子串替换
# special matrix
zeros(2, 3) # all 0
ones(1, 3) # all 1
eye(3) # elementary
linspace(x0, xN, npoints) # default: npoints = 100
reshape, repmat, diag
upper, lower
svd
# matrix, vector
size, length
det, norm
rank
sum
mean # average
var # variance
std # std. deviation
max/min
inv(X) # inverse matrix
eig(X) # vector of eigenvalues
[V, D] = eig(X) # X V = V D
# matrix function
sqrtm, expm, logm
find(A gt 0)
eq(A,B) neq lt le gt ge
all any exist
for i=1:7
i
end
if (i gt 0)
positive
elseif i lt 0
negative
else
0
end
while (i gt 0)
..
end
function [out1, out2] = myfunction(input1, input2)
# plot
figure # new figure
axis([xmin xmax ymin ymax])
axis equal/normal/image
xlabel('radians')
ylabel('sin value')
title('dummy')
legend('sin', 'cos')
subplot(m, n, c); # mxn, c is the current
hold on/off
grid on/off
box on/off
plot
loglog
semilogx
semilogy
plotyy # double-y
fplot('function', [xmin, xmax])
polar(theta, r)
# color
b: blue
g: green
k: black
r: red
w: white
2008-03-11
读书笔记: Perl 语言入门
Learning Perl
Perl 语言入门 (第四版)
Errata
pp.37 "2.1.1 defined 函数", 应为 "2.11"
pp.37 "If ($defined ($madonna))", 应为 If ( defined ($madonna) )
Perl 语言入门 (第四版)
Errata
pp.37 "2.1.1 defined 函数", 应为 "2.11"
pp.37 "If ($defined ($madonna))", 应为 If ( defined ($madonna) )
Programming in Perl
# 避免 undefined 警告
$foo = bar unless defined ($foo);
# 生成一个等差数列
perl -e 'for ($i=1; $i<=3; $i++) { printf "%5i\n", $i; }'; }'
$foo = bar unless defined ($foo);
# 生成一个等差数列
perl -e 'for ($i=1; $i<=3; $i++) { printf "%5i\n", $i; }'; }'
2008-03-10
Programming in MPI
http://www.hpc.sfu.ca/bugaboo/mpi.html
http://www-unix.mcs.anl.gov/mpi/mpi-standard/mpi-report-1.1/mpi-report.htm
# mpich manual
http://www-unix.mcs.anl.gov/mpi/mpich1/docs.html
http://www-unix.mcs.anl.gov/mpi/www/
http://www-unix.mcs.anl.gov/mpi/mpi-standard/mpi-report-1.1/mpi-report.htm
# mpich manual
http://www-unix.mcs.anl.gov/mpi/mpich1/docs.html
http://www-unix.mcs.anl.gov/mpi/www/
2008-03-06
From "Hot water" to "Betsy Ross and American Flag"
一转眼半年时间就这样过去了,渐渐适应了这里的生活。英语还是有进步的,从当初在飞机上try to answer: hot water,到今天自信的做完Presentation,老师评价:Clearly,Excellent!相信这半年的辛苦学习没有白费啊。Luda,Helen还有Gong in都说我今天Good job!呵呵,又小小满足了一下。在此感谢老公不厌其烦的幕后支持,想想昨晚老公帮我练习,帮我纠正错误的时候,我还冲他发脾气说不练了。结果老公好说歹说,硬是哄着我练完。连续两天晚上,老公都耐心的给我讲解和纠正,从之前晦涩的手稿,蹩脚的发音,到今早清晰明了的Presentation,老公功不可没!现在想想,真是有些不好意思,嘻嘻。做老公的老不容易了哈。明天给你做炒面,炖排骨汤慰劳一下,嘿嘿。
2008-03-05
Compiler
# Open MPI
http://www.open-mpi.org/
# MPICH
http://www-unix.mcs.anl.gov/mpi/mpich1/
# LAM MPI
http://www.lam-mpi.org/
mpich
# new-style
export FC=ifort
export F90=ifort
export F77=ifort
export CC=icc
export CXX=icpc
export RSHCOMMAND=ssh
./configure --prefix=$HOME/program/mpich/intel
# old-style
./configure --prefix=$HOME/program/mpich/intel \
-f90=ifort -fc=ifort \
-cc=icc -c++=icpc -rsh=ssh
make
# test
make testing # cd examples/test && make testing
# or
cd examples/basic
make cpi
../../bin/mpirun -np 4 cpi
make install
Intel Compiler
# Non-Commercial Intel Compiler Download
http://www.intel.com/cd/software/products/asmo-na/eng/340679.htm
# Compiler Diagnostics
http://www.intel.com/support/performancetools/c/windows/sb/CS-007735.htm
# Vectorization
http://softwarecommunity.intel.com/articles/eng/3418.htm
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
# or
source ifortvars.sh
source iccvars.sh
# compiler options
CFLAGS='-O3 -x[X] -i[X]'
CXXFLAGS='-O3 -x[X] -i[X]'
FFLAGS='-O3 -x[X] -i[X]'
# ia64-*-linux*
CC=icc
CFLAGS=-O3 -openmp -fno-alias
# x86_64-*-linux* For Intel
CC=icc
CFLAGS=-O3 -openmp -fno-alias -xW (for SSE2)
CFLAGS=-O3 -openmp -fno-alias -xP (for SSE3)
# x86_64-*-linux* For AMD
CC=gcc
CFLAGS=-O3 -msse2 (for SSE2)
CFLAGS=-O3 -msse2 -msse3 (for SSE3)
http://www.open-mpi.org/
# MPICH
http://www-unix.mcs.anl.gov/mpi/mpich1/
# LAM MPI
http://www.lam-mpi.org/
mpich
# new-style
export FC=ifort
export F90=ifort
export F77=ifort
export CC=icc
export CXX=icpc
export RSHCOMMAND=ssh
./configure --prefix=$HOME/program/mpich/intel
# old-style
./configure --prefix=$HOME/program/mpich/intel \
-f90=ifort -fc=ifort \
-cc=icc -c++=icpc -rsh=ssh
make
# test
make testing # cd examples/test && make testing
# or
cd examples/basic
make cpi
../../bin/mpirun -np 4 cpi
make install
Intel Compiler
# Non-Commercial Intel Compiler Download
http://www.intel.com/cd/software/products/asmo-na/eng/340679.htm
# Compiler Diagnostics
http://www.intel.com/support/performancetools/c/windows/sb/CS-007735.htm
# Vectorization
http://softwarecommunity.intel.com/articles/eng/3418.htm
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
# or
source ifortvars.sh
source iccvars.sh
# compiler options
CFLAGS='-O3 -x[X] -i[X]'
CXXFLAGS='-O3 -x[X] -i[X]'
FFLAGS='-O3 -x[X] -i[X]'
# ia64-*-linux*
CC=icc
CFLAGS=-O3 -openmp -fno-alias
# x86_64-*-linux* For Intel
CC=icc
CFLAGS=-O3 -openmp -fno-alias -xW (for SSE2)
CFLAGS=-O3 -openmp -fno-alias -xP (for SSE3)
# x86_64-*-linux* For AMD
CC=gcc
CFLAGS=-O3 -msse2 (for SSE2)
CFLAGS=-O3 -msse2 -msse3 (for SSE3)
2008-03-04
ASCII Characters
cf.
http://web.cs.mun.ca/~michael/c/ascii-table.html
Char Dec Oct Hex
--------------------
(sp) 32 0040 0x20
! 33 0041 0x21
" 34 0042 0x22
# 35 0043 0x23
$ 36 0044 0x24
% 37 0045 0x25
& 38 0046 0x26
' 39 0047 0x27
( 40 0050 0x28
) 41 0051 0x29
* 42 0052 0x2a
+ 43 0053 0x2b
, 44 0054 0x2c
- 45 0055 0x2d
. 46 0056 0x2e
/ 47 0057 0x2f
0 48 0060 0x30
1 49 0061 0x31
2 50 0062 0x32
3 51 0063 0x33
4 52 0064 0x34
5 53 0065 0x35
6 54 0066 0x36
7 55 0067 0x37
8 56 0070 0x38
9 57 0071 0x39
: 58 0072 0x3a
; 59 0073 0x3b
< 60 0074 0x3c
= 61 0075 0x3d
> 62 0076 0x3e
? 63 0077 0x3f
Char Dec Oct Hex
--------------------
@ 64 0100 0x40
A 65 0101 0x41
B 66 0102 0x42
C 67 0103 0x43
D 68 0104 0x44
E 69 0105 0x45
F 70 0106 0x46
G 71 0107 0x47
H 72 0110 0x48
I 73 0111 0x49
J 74 0112 0x4a
K 75 0113 0x4b
L 76 0114 0x4c
M 77 0115 0x4d
N 78 0116 0x4e
O 79 0117 0x4f
P 80 0120 0x50
Q 81 0121 0x51
R 82 0122 0x52
S 83 0123 0x53
T 84 0124 0x54
U 85 0125 0x55
V 86 0126 0x56
W 87 0127 0x57
X 88 0130 0x58
Y 89 0131 0x59
Z 90 0132 0x5a
[ 91 0133 0x5b
\ 92 0134 0x5c
] 93 0135 0x5d
^ 94 0136 0x5e
_ 95 0137 0x5f
Char Dec Oct Hex
-------------------
` 96 0140 0x60
a 97 0141 0x61
b 98 0142 0x62
c 99 0143 0x63
d 100 0144 0x64
e 101 0145 0x65
f 102 0146 0x66
g 103 0147 0x67
h 104 0150 0x68
i 105 0151 0x69
j 106 0152 0x6a
k 107 0153 0x6b
l 108 0154 0x6c
m 109 0155 0x6d
n 110 0156 0x6e
o 111 0157 0x6f
p 112 0160 0x70
q 113 0161 0x71
r 114 0162 0x72
s 115 0163 0x73
t 116 0164 0x74
u 117 0165 0x75
v 118 0166 0x76
w 119 0167 0x77
x 120 0170 0x78
y 121 0171 0x79
z 122 0172 0x7a
{ 123 0173 0x7b
| 124 0174 0x7c
} 125 0175 0x7d
~ 126 0176 0x7e
(del) 127 0177 0x7f
http://web.cs.mun.ca/~michael/c/ascii-table.html
Char Dec Oct Hex
--------------------
(sp) 32 0040 0x20
! 33 0041 0x21
" 34 0042 0x22
# 35 0043 0x23
$ 36 0044 0x24
% 37 0045 0x25
& 38 0046 0x26
' 39 0047 0x27
( 40 0050 0x28
) 41 0051 0x29
* 42 0052 0x2a
+ 43 0053 0x2b
, 44 0054 0x2c
- 45 0055 0x2d
. 46 0056 0x2e
/ 47 0057 0x2f
0 48 0060 0x30
1 49 0061 0x31
2 50 0062 0x32
3 51 0063 0x33
4 52 0064 0x34
5 53 0065 0x35
6 54 0066 0x36
7 55 0067 0x37
8 56 0070 0x38
9 57 0071 0x39
: 58 0072 0x3a
; 59 0073 0x3b
< 60 0074 0x3c
= 61 0075 0x3d
> 62 0076 0x3e
? 63 0077 0x3f
Char Dec Oct Hex
--------------------
@ 64 0100 0x40
A 65 0101 0x41
B 66 0102 0x42
C 67 0103 0x43
D 68 0104 0x44
E 69 0105 0x45
F 70 0106 0x46
G 71 0107 0x47
H 72 0110 0x48
I 73 0111 0x49
J 74 0112 0x4a
K 75 0113 0x4b
L 76 0114 0x4c
M 77 0115 0x4d
N 78 0116 0x4e
O 79 0117 0x4f
P 80 0120 0x50
Q 81 0121 0x51
R 82 0122 0x52
S 83 0123 0x53
T 84 0124 0x54
U 85 0125 0x55
V 86 0126 0x56
W 87 0127 0x57
X 88 0130 0x58
Y 89 0131 0x59
Z 90 0132 0x5a
[ 91 0133 0x5b
\ 92 0134 0x5c
] 93 0135 0x5d
^ 94 0136 0x5e
_ 95 0137 0x5f
Char Dec Oct Hex
-------------------
` 96 0140 0x60
a 97 0141 0x61
b 98 0142 0x62
c 99 0143 0x63
d 100 0144 0x64
e 101 0145 0x65
f 102 0146 0x66
g 103 0147 0x67
h 104 0150 0x68
i 105 0151 0x69
j 106 0152 0x6a
k 107 0153 0x6b
l 108 0154 0x6c
m 109 0155 0x6d
n 110 0156 0x6e
o 111 0157 0x6f
p 112 0160 0x70
q 113 0161 0x71
r 114 0162 0x72
s 115 0163 0x73
t 116 0164 0x74
u 117 0165 0x75
v 118 0166 0x76
w 119 0167 0x77
x 120 0170 0x78
y 121 0171 0x79
z 122 0172 0x7a
{ 123 0173 0x7b
| 124 0174 0x7c
} 125 0175 0x7d
~ 126 0176 0x7e
(del) 127 0177 0x7f
2008-03-03
Vim 技巧翻译 (ZZ)
发信人: microwind (星空,晴天,微风), 信区: VIM
标 题: Vim 技巧翻译(ZZ)
发信站: 水木社区 (Sun Jun 18 13:45:46 2006), 站内
翻译 by Yunt,原文参见
http://my.opera.com/yunt/blog/show.dml/221171
English version:
http://www.rayninfo.co.uk/vimtips.html
__开始__
------------------------------------------------------------------------------
" 搜索
/joe/e : 设置光标到匹配"joe"的末尾
/joe/e+1 : 设置光标到匹配"joe"的末尾再后移一位
/joe/s-2 : 设置光标到匹配"joe“的开头再前移两位
/^joe.*fred.*bill/ : 匹配以'j'开头且"joe"到"fred"到"bill"之间至少有一个字符
/^[A-J]\+/ : 搜索'A'到’J‘重复两次以上的开头行
/begin\_.*end : 多行匹配
/fred\_s*joe/i : 可以是任何空白字符包括\n,\t等等
/fred\|joe : 搜索fred或者joe
/.*fred\&.*joe : 搜索同时包括fred跟joe的行
/\/i : 搜索独立的单词fred
/\<\d\d\d\d\> : 搜索独立的4位数字
/\D\d\d\d\d\D : 搜索6位字符串中间4位数字前后两位不能为数字
/\<\d\{4}\> : 同/\<\d\d\d\d\>
" 查找空行
/^\n\{3} : 匹配三连续的空行
" 使用正则表达式组查找
/\(fred\).*\(joe\).*\2.*\1
" 正则表达式重复
/^\([^,]*,\)\{8}
" visual searching
:vmap // y/" : visually模式下的键盘映射,把//映射成匹配当前选中的文本
:vmap // y/=escape(@", '\\/.*$^~[]') : 包括空白字符
" \zs 和 \ze 匹配原 :h /\zs
/<\zs[^>]*\ze> : 匹配尖括号中的内容
" 零宽度匹配 :h /\@=
/<\@<=[^>]*>\@= : search for tag contents, ignoring chevrons
/<\@<=\_[^>]*>\@= : search for tags across possible multiple lines
" 多行查找 \_ 的意思是包括换行符
/ : 匹配结尾的所有内容
/fred\_s*joe/i : 匹配fred开始到joe,之间一定得是空白字符
/bugs\(\_.\)*bunny : 匹配所有bugs到bunny的字符串
:h \_ : help
" 查找函数声明,nmap为normal模式下的键盘映射
:nmap gx yiw/^\(sub\function\)\s\+"
" 查找多个文件
:bufdo /searchstr/ : 在多个文件缓冲区里执行查找
" 更好的多文件查找定位方法
:bufdo %s/searchstr/&/gic : 在多个文件缓冲区里查找,按下n停止
" 怎样不使用 / 来查找网址
?http://www.vim.org/ : 向后查找
" 查找指定字符以外的字符串
/\c\v([^aeiou]&\a){4} : 查找4个辅音字母
----------------------------------------
#替换
:%s/fred/joe/igc : 普通替换命令
:%s/\r//g : 删除 DOS 的换行符 ^M
" 你的文本文件是否乱七八糟的排成一行?使用如下命令
:%s/\r/\r/g : 转换 DOS 回车符 ^M 为真正的回车符
:%s= *$== : 删除行尾空白
:%s= \+$== : 同上
:%s#\s*\r\?$## : 删除尾部空白和dos换行符
:%s#\s*\r*$## : 同上
" 删除空行
:%s/^\n\{3}// : 删除连续3个空行
:%s/^\n\+/\r/ : 压缩空行,多个替换为一个
%s#<[^>]\+>##g : 删除html的tag部分
" IF YOU ONLY WANT TO KNOW ONE THING
:'a,'bg/fred/s/dick/joe/igc : 非常有用
# 译释:''a,''b指定一个范围:mark a ~ mark b
# g//用一个正则表达式指出了进行操作的行必须可以被fred匹配
# 看后面,g//是一个全局显示命令
# s/dick/joe/igc则对于这些满足条件的行进行替换
" 复制列
:%s= [^ ]\+$=&&= : 复制最后一列
:%s= \f\+$=&&= : 一样
:%s= \S\+$=&& : 晕,还一样!
" 记忆(反向引用)
:s/\(.*\):\(.*\)/\2 : \1/ : 将两个字段颠倒
:%s/^\(.*\)\n\1$/\1/ : 删除重复行
" 非贪婪匹配 \{-}
:%s/^.\{-}pdf/new.pdf/ : 删除第一个pdf
" use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&#gc : lowercase with optional leading characters
" 跨越尽量多的行
:%s/// : 删除多行注释
:help /\{-} : 查看非贪婪匹配的更多帮助
" 使用寄存器替换
:s/fred/a/g : 将fred替换为寄存器a里的内容
:s/fred/asome_texts/g
:s/fred/\=@a/g : better alternative as register not displayed
" 在一行里写多种命令
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
:%s/a/but/gie|:update|:next : 当使用 @: 来重复
" 或运算
:%s/suck\|buck/loopy/gc : 替换suck或者buck(这里|不是管道)
" 调用vim函数
:s/__date__/\=strftime("%c")/ : 将__date__替换成当前日期,使用strftime函数
" 处理列,替换所有在第三列中的str1
:%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:
" 交换第一列跟第四列
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:
" 过滤form中的内容放在寄存器里
:redir @*|sil exec 'g#<\(input\|select\|textarea\|/\=form\)\>#p'|redir END
:nmap ,z :redir @*sil exec 'g@<\(input\select\>textarea\/\=form\)\>@p'redir END
" 两位以上的数字减三(带进位。这个命令挺有趣)
:%s/\d\+/\=(submatch(0)-3)/
" 包含loc或者functions的行中的数字加6
:g/loc\|function/s/\d/\=submatch(0)+6/
" 比上面更好的方法
:%s#txtdev\zs\d#\=submatch(0)+1#g
:h /\zs 查看帮助
" 前缀为gg的数字加6
:%s/\(gg\)\@<=\d\+/\=submatch(0)+6/
:h zero-width 查看帮助
" 替换一个特定字符串为数字
:let i=10 | 'a,'bg/Abc/s/yy/\=i/ |let i=i+1 # 将yy转换成10,11,12等等
" 比上面的更精确
:let i=10 | 'a,'bg/Abc/s/xx\zsyy\ze/\=i/ |let i=i+1 # 将xxyy 转换成 xx11,xx12,xx13
" find replacement text, put in memory, then use \zs to simplify substitute
:%s/"\([^.]\+\).*\zsxx/\1/
" Pull word under cursor into LHS of a substitute
:nmapz :%s#\<=expand("")\>#
" Pull Visually Highlighted text into LHS of a substitute
:vmapz :%s/\<*\>/
----------------------------------------
" all following performing similar task, substitute within substitution
" Multiple single character substitution in a portion of line only
:%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER "all/"
" Same thing
:s#all/\zs.*#\=substitute(submatch(0), '/', '_', 'g')#
" Substitute by splitting line, then re-joining
:s#all/#&^M#|s#/#_#g|-j!
" Substitute inside substitute
:%s/.*/\='cp '.submatch(0).' all/'.substitute(submatch(0),'/','_','g')/
----------------------------------------
" 全局显示命令
:g/gladiolli/# : 查找并显示匹配的行号
:g/fred.*joe.*dick/ : 显示所有含有 fred,joe & dick的行
:g/\/ : 显示单一单词fred
:g/^\s*$/d : 删除所有空行
:g!/^dd/d : 删除不含字符串''dd''的行
:v/^dd/d : 同上
:g/fred/,/joe/d : 删除所有的从fred到joe
:g/-------/.-10,.d : 以-------为标记删除之前的10行
:g/{/ ,/}/- s/\n\+/\r/g : 删除 {...}之间的空行
:v/\S/d : Delete empty lines (both types)
:v/./,/./-j : 压缩空行
:g/^$/,/./-j : 同上
:g/:g/^/put_ : 双倍行宽 (pu = put)
:g/^/m0 : 颠倒文件 (m = move)
:'a,'bg/^/m'b : 颠倒选中的 a 到 b
:g/^/t. : 重复行
:g/fred/t$ : 拷贝行从fred到结尾
:g/stage/t'a : 拷贝行从stage 到 marker a(a为标记的位置)
:g/\(^I[^^I]*\)\{80}/d : 删除最少包含80个tab的行
" perform a substitute on every other line
:g/^/ if line('.')%2|s/^/zz /
" match all lines containing "somestr" between markers a & b
" copy after line containing "otherstr"
:'a,'bg/somestr/co/otherstr/ : co(py) or mo(ve)
" as above but also do a substitution
:'a,'bg/str1/s/str1/&&&/|mo/str2/
:%norm jdd : 隔行删除
" 增加数字 (键入)
:.,$g/^\d/exe "norm! \": 增加从当前行首到结尾的数字
:'a,'bg/\d\+/norm! ^A : 增加数字
" 保存全局命令的结果 (注意必须使用添加模式) 你需要使用 qaq 清空寄存器a.
"save results to a register/paste buffer 存储结果到 寄存器/粘贴 到 a
:g/fred/y A : 添加配备行到寄存器到 a
:g/fred/y A | :let @*=@a : 放入复制缓冲区
:let @a=''|g/Barratt/y A |:let @*=@a
:'a,'b g/^Error/ . w >> errors.txt
" 复制每一行,然后在复制出来的每一行两侧加上一个 print '复制出来的内容'
:g/./yank|put|-1s/'/"/g|s/.*/Print '&'/
" 用文件中的内容替换字符串,-d 表示删除“标记”
:g/^MARK$/r tmp.ex | -d
" display prettily
:g//z#.5 : display with context
:g//z#.5|echo "==========" : display beautifully
" Combining g// with normal mode commands
:g/|/norm 2f|r* : replace 2nd | with a star
"send output of previous global command to a new window
:nmap :redir @a:g//:redir END:new:put! a
----------------------------------------
" 全局命令和替换命令联姻 (强大的编辑能力)
:'a,'bg/fred/s/joe/susan/gic : 可以使用反向引用来匹配
:g/fred/,/joe/s/fred/joe/gic : non-line based (ultra)
----------------------------------------
" 先找fred,然后找joe
:/fred/;/joe/-2,/sid/+3s/sally/alley/gIC
----------------------------------------
" create a new file for each line of file eg 1.txt,2.txt,3,txt etc
:g/^/exe ".w ".line(".").".txt"
----------------------------------------
" Absolutely essential
----------------------------------------
* # g* g# : 查找当前光标下的单词(单个单词) () (向前/向后)
% : 匹配括号 {}[]()
. : 重复上次操作
@: : 重复上次的命令
matchit.vim : 适%能匹配
标 题: Vim 技巧翻译(ZZ)
发信站: 水木社区 (Sun Jun 18 13:45:46 2006), 站内
翻译 by Yunt,原文参见
http://my.opera.com/yunt/blog
English version:
http://www.rayninfo.co.uk
__开始__
------------------------------
" 搜索
/joe/e : 设置光标到匹配"joe"的末尾
/joe/e+1 : 设置光标到匹配"joe"的末尾再后移一位
/joe/s-2 : 设置光标到匹配"joe“的开头再前移两位
/^joe.*fred.*bill/ : 匹配以'j'开头且"joe"到"fred"到"bill
/^[A-J]\+/ : 搜索'A'到’J‘重复两次以上的开头行
/begin\_.*end : 多行匹配
/fred\_s*joe/i : 可以是任何空白字符包括\n,\t等等
/fred\|joe : 搜索fred或者joe
/.*fred\&.*joe : 搜索同时包括fred跟joe的行
/\
/\<\d\d\d\d\> : 搜索独立的4位数字
/\D\d\d\d\d\D : 搜索6位字符串中间4位数字前后两位不能为数字
/\<\d\{4}\> : 同/\<\d\d\d\d\>
" 查找空行
/^\n\{3} : 匹配三连续的空行
" 使用正则表达式组查找
/\(fred\).*\(joe\).*\2.*\1
" 正则表达式重复
/^\([^,]*,\)\{8}
" visual searching
:vmap // y/
:vmap
" \zs 和 \ze 匹配原 :h /\zs
/<\zs[^>]*\ze> : 匹配尖括号中的内容
" 零宽度匹配 :h /\@=
/<\@<=[^>]*>\@= : search for tag contents, ignoring chevrons
/<\@<=\_[^>]*>\@= : search for tags across possible multiple lines
" 多行查找 \_ 的意思是包括换行符
/ : 匹配结尾的所有内容
/fred\_s*joe/i : 匹配fred开始到joe,之间一定得是空白字符
/bugs\(\_.\)*bunny : 匹配所有bugs到bunny的字符串
:h \_ : help
" 查找函数声明,nmap为normal模式下的键盘映射
:nmap gx yiw/^\(sub\
" 查找多个文件
:bufdo /searchstr/ : 在多个文件缓冲区里执行查找
" 更好的多文件查找定位方法
:bufdo %s/searchstr/&/gic : 在多个文件缓冲区里查找,按下n停止
" 怎样不使用 / 来查找网址
?http://www.vim.org/ : 向后查找
" 查找指定字符以外的字符串
/\c\v([^aeiou]&\a){4} : 查找4个辅音字母
------------------------------
#替换
:%s/fred/joe/igc : 普通替换命令
:%s/\r//g : 删除 DOS 的换行符 ^M
" 你的文本文件是否乱七八糟的排成一行?使用如下命令
:%s/\r/\r/g : 转换 DOS 回车符 ^M 为真正的回车符
:%s= *$== : 删除行尾空白
:%s= \+$== : 同上
:%s#\s*\r\?$## : 删除尾部空白和dos换行符
:%s#\s*\r*$## : 同上
" 删除空行
:%s/^\n\{3}// : 删除连续3个空行
:%s/^\n\+/\r/ : 压缩空行,多个替换为一个
%s#<[^>]\+>##g : 删除html的tag部分
" IF YOU ONLY WANT TO KNOW ONE THING
:'a,'bg/fred/s/dick/joe/igc : 非常有用
# 译释:''a,''b指定一个范围:mark a ~ mark b
# g//用一个正则表达式指出了进行操作的行必须可以被fred匹
# 看后面,g//是一个全局显示命令
# s/dick/joe/igc则对于这些满足条件的行进行替换
" 复制列
:%s= [^ ]\+$=&&= : 复制最后一列
:%s= \f\+$=&&= : 一样
:%s= \S\+$=&& : 晕,还一样!
" 记忆(反向引用)
:s/\(.*\):\(.*\)/\2 : \1/ : 将两个字段颠倒
:%s/^\(.*\)\n\1$/\1/ : 删除重复行
" 非贪婪匹配 \{-}
:%s/^.\{-}pdf/new.pdf/ : 删除第一个pdf
" use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&
" 跨越尽量多的行
:%s/// : 删除多行注释
:help /\{-} : 查看非贪婪匹配的更多帮助
" 使用寄存器替换
:s/fred/
:s/fred/
:s/fred/\=@a/g : better alternative as register not displayed
" 在一行里写多种命令
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
:%s/a/but/gie|:update|:next : 当使用 @: 来重复
" 或运算
:%s/suck\|buck/loopy/gc : 替换suck或者buck(这里|不是管道)
" 调用vim函数
:s/__date__/\=strftime("%c")/ : 将__date__替换成当前日期,使用strftime函数
" 处理列,替换所有在第三列中的str1
:%s:\(\(\w\+\s\+\)\{2}\)str1:
" 交换第一列跟第四列
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)
" 过滤form中的内容放在寄存器里
:redir @*|sil exec 'g#<\(input\|select\|textarea\
:nmap ,z :redir @*
" 两位以上的数字减三(带进位。这个命令挺有趣)
:%s/\d\+/\=(submatch(0)-3)/
" 包含loc或者functions的行中的数字加6
:g/loc\|function/s/\d/\
" 比上面更好的方法
:%s#txtdev\zs\d#\=submatch(0)
:h /\zs 查看帮助
" 前缀为gg的数字加6
:%s/\(gg\)\@<=\d\+/\=submatch
:h zero-width 查看帮助
" 替换一个特定字符串为数字
:let i=10 | 'a,'bg/Abc/s/yy/\=i/ |let i=i+1 # 将yy转换成10,11,12等等
" 比上面的更精确
:let i=10 | 'a,'bg/Abc/s/xx\zsyy\ze/\=i/ |let i=i+1 # 将xxyy 转换成 xx11,xx12,xx13
" find replacement text, put in memory, then use \zs to simplify substitute
:%s/"\([^.]\+\).*\zsxx/\1/
" Pull word under cursor into LHS of a substitute
:nmap
" Pull Visually Highlighted text into LHS of a substitute
:vmap
------------------------------
" all following performing similar task, substitute within substitution
" Multiple single character substitution in a portion of line only
:%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER "all/"
" Same thing
:s#all/\zs.*#\=substitute
" Substitute by splitting line, then re-joining
:s#all/#&^M#|s#/#_#g|-j!
" Substitute inside substitute
:%s/.*/\='cp '.submatch(0).' all/'.substitute(submatch(0),'
------------------------------
" 全局显示命令
:g/gladiolli/# : 查找并显示匹配的行号
:g/fred.*joe.*dick/ : 显示所有含有 fred,joe & dick的行
:g/\
:g/^\s*$/d : 删除所有空行
:g!/^dd/d : 删除不含字符串''dd''的行
:v/^dd/d : 同上
:g/fred/,/joe/d : 删除所有的从fred到joe
:g/-------/.-10,.d : 以-------为标记删除之前的10行
:g/{/ ,/}/- s/\n\+/\r/g : 删除 {...}之间的空行
:v/\S/d : Delete empty lines (both types)
:v/./,/./-j : 压缩空行
:g/^$/,/./-j : 同上
:g/:g/^/put_ : 双倍行宽 (pu = put)
:g/^/m0 : 颠倒文件 (m = move)
:'a,'bg/^/m'b : 颠倒选中的 a 到 b
:g/^/t. : 重复行
:g/fred/t$ : 拷贝行从fred到结尾
:g/stage/t'a : 拷贝行从stage 到 marker a(a为标记的位置)
:g/\(^I[^^I]*\)\{80}/d : 删除最少包含80个tab的行
" perform a substitute on every other line
:g/^/ if line('.')%2|s/^/zz /
" match all lines containing "somestr" between markers a & b
" copy after line containing "otherstr"
:'a,'bg/somestr/co/otherstr/ : co(py) or mo(ve)
" as above but also do a substitution
:'a,'bg/str1/s/str1/&&&/|mo
:%norm jdd : 隔行删除
" 增加数字 (键入
:.,$g/^\d/exe "norm! \
:'a,'bg/\d\+/norm! ^A : 增加数字
" 保存全局命令的结果 (注意必须使用添加模式) 你需要使用 qaq 清空寄存器a.
"save results to a register/paste buffer 存储结果到 寄存器/粘贴 到 a
:g/fred/y A : 添加配备行到寄存器到 a
:g/fred/y A | :let @*=@a : 放入复制缓冲区
:let @a=''|g/Barratt/y A |:let @*=@a
:'a,'b g/^Error/ . w >> errors.txt
" 复制每一行,然后在复制出来的每一行两侧加上一个 print '复制出来的内容'
:g/./yank|put|-1s/'/"/g|s/.*
" 用文件中的内容替换字符串,-d 表示删除“标记”
:g/^MARK$/r tmp.ex | -d
" display prettily
:g/
:g/
" Combining g// with normal mode commands
:g/|/norm 2f|r* : replace 2nd | with a star
"send output of previous global command to a new window
:nmap
------------------------------
" 全局命令和替换命令联姻 (强大的编辑能力)
:'a,'bg/fred/s/joe/susan/gic : 可以使用反向引用来匹配
:g/fred/,/joe/s/fred/joe/gic : non-line based (ultra)
------------------------------
" 先找fred,然后找joe
:/fred/;/joe/-2,/sid/+3s/sally
------------------------------
" create a new file for each line of file eg 1.txt,2.txt,3,txt etc
:g/^/exe ".w ".line(".").".txt"
------------------------------
" Absolutely essential
------------------------------
* # g* g# : 查找当前光标下的单词(单个单词) (
% : 匹配括号 {}[]()
. : 重复上次操作
@: : 重复上次的命令
matchit.vim : 适%能匹配