文本处理(grep, vim)

grep
参考: http://www.panix.com/~elflord/unix/grep.html
regexp in grep: \ 添加或删除special meaning
hello.gif         #match hello.gif, helloxgif
hello\.gif        #only match hello.gif            \ has escape special meaning of .
bugg\?           #match bug, bugg                \ add special meaning on ?
Fred\(eric\)    #group eric                            \ add special
[Hh]ello          #pre-define character class: [[:alpha:]]=[a-zA-Z]
"[[:digit:]]\{4\}"    #match 1234
"^hello$"            #begin with h & end with $
"this\|that"        #this or that
"<\(h[1-6]\)>[^<]*</\1>"    #<h1>xx</h1>or <h2>xxx</h2> but never <h1>xx</h2>. using back reference \N(N is a number)
"$HOME"         #actually /home/me
'$HOME'           #no special meaning

grep & egrep
grep               egrep
a\+                  a+
a\?                  a?
this\|that        this|that
\(group\)        (group)
\{m,n\}            {m,n}

 

vim使用

tab设定:

set tabstop=4
set softtabstop=4
set shiftwidth=4

 

other setting:

set number | set nonumber      #set line number

 

常用命令:http://www.tuxfiles.org/linuxhelp/vimcheat.html

 

整理自vimtutor

ctr-O                                   #go back
ctr-I                                    #go forward

:s/regex/replace/gic            #substitute on current line. g - replace all. i - ignore case. c - confirm
:1,10s/regex/replace/         #substitute from line 1~10
:%s/regex/replace/             #substitute whole file

:!pwd                                  #execute external command


:w FILENAME                       #write the file to FILENAME

:r FILE                                 #append FILE content at cursor
:r !ls                                    #execute command and append output at cursor

%             #find match ) ] }
10G          #go to line 10
R              #replace mode
yw           #copy a word
y$            #copy until line
v              #visual mode
v->select->:w PART                #save part that is selected

:set xxx            #set some function
:set ic               #ignore case when search
:set noic           
/regex\c            #ignore case for this time

:set hls             #highlight search
:set nohls

ctrl+w -> j|k        #jump up or down to another window

:help or F1        #get help
:help w
:help user-manual

word completion using ctrl+D & TAB
:set nocp            #make sure vim is not in compatible
:!l(press ctrl+D or TAB)
:ed(press ctrl+D or TAB)
:help .(press ctrl+D)

 

vim as python editor

 

add auto complete in vim for python

  •  download python completion vim script :Python Omni Completion
  •  put in ~/.vim/autoload or /usr/share/vim/addons/autoload
  •  add following 2 line to .vimrc

au Syntax python set omnifunc=pythoncomplete#Complete
au Syntax python set completefunc=pythoncomplete#Complete

  •  use ctrl+x, ctrl+o when writing python program

 

 

 

 

你可能感兴趣的:(c,python,unix,vim,Go)