分享知识的快乐,尊重他人创造的知识 注册 | 登陆
浏览模式: 标准 | 列表全部文章

15年的VI和7年的VIM 使用技巧

Best of Vim Tips:
David Rayner (zzapper) 15 Years of Vi + 7 years of Vim and still learning 14Jan10 : Last Update 

__BEGIN__
" new items marked *N* , corrected items marked *C*" searching
/joe/e                      : cursor set to End of match
/joe/e+1                    : cursor set to End of match plus 1
/joe/s-2                    : cursor set to Start of match minus 2
/joe/+3                     : find joe move cursor 3 lines down
/^joe.*fred.*bill/          : find joe AND fred AND Bill (Joe at start of line)
/^[A-J]/                    : search for lines beginning with one or more A-J
/begin\_.*end               : search over possible multiple lines
/fred\_s*joe/               : any whitespace including newline *C*
fred\|joe                   : Search for FRED OR JOE
/.*fred\&.*joe              : Search for FRED AND JOE in any ORDER
/\<\d\d\d\d\>               : Search for exactly 4 digit numbers
/\D\d\d\d\d\D               : Search for exactly 4 digit numbers

» 阅读全文

Tags: vi, vim

Python的线程

原文:http://shhgs.blogspot.com/2006/10/python.html

转载:

网上down下Norman Matloff and Francis Hsu的Tutorial on Threads Programming with Python。

文档写得不错,不过我没有很仔细地看,主要原因是因为对Py的线程并不陌生。真正让我感兴趣的是,这篇文档对Py线程机制的实现做了点介绍。下面就是我的总结,也不知道对不对。

Py的程序是通过Py的解释器运行的,所以程序员写的多线程Py代码究竟会怎么运行,要取决于解释器。Py的解释器是一个单进程的程序。不过单进程也没有关系,Java的解释器就是单进程的,但是它可以用多线程的方式解释Java的多线程程序,因此当你发现Java程序运行得很慢的时候,或许可以用加CPU的办法来解决问题。但是我们的Py比较弱。它只能以单线程的方式运行。下面是Py Manual关于GIL的描述。 

In order to support multi-threaded Python programs, there's a global lock that must be held by the current thread before it can safely access Python objects. 

-- Py 2.5 Manual, Python/C API Reference Manual 8.1 Thread State and the Global Interpreter Lock

外部的C程序如果要调用Py的解释器,必须先拿到它的GIL。换句话说,就是Py的解释器在解释Py的源代码的时候,只有一条流水线,因此你得先拿到钥匙才能往里面灌水。

这是流水线一头的情形。下面是流水线的另一头。

我们都知道,Py的多线程能提升I/O性能。但这和Py的单线程相矛盾。比方说有一个线程发出了I/O指令,Py解释器交给了底层的OS。I/O操作一般都是block的,因此在OS返回结果之前,整个进程都是block的。这么一来,多线程根本就不可能提升I/O性能了。

我没有看过Py的源代码,但是这里应该猜得不会太离谱。Py解释器在碰到I/O指令的时候,一定是生成一个线程,然后让这个线程去等OS的返回。它自己的解释引擎肯定是不会去等OS的。

这么以来,Py的多线程其实是一个混合实现。解释引擎是单线程的,但是它会以多线程的方式请求OS的服务。因此多线程的I/O能提升性能,但是多加CPU却没用。

很多脚本引擎的多线程实现都是这样。好像Ruby的也是。

» 阅读全文

Tags: python

vim:学习笔记 2010-01-16

周日在家没有无线信号,只好学习了。

vim工具感觉越来越好了。今天又花了一些时间看自带的教程。

笔记如下:

O 上一行写入

3x 连续删除3个字符 3a1 表示添加三个1

U 表示恢复当前行,u表示恢复当前行

:e! 强制重新回来文件的初始化状态
w 单词移动
b 单词后退

e 单词的结尾 E表示非空白单词
ge 后退单词的结尾
f搜索当前行字符;表示继续搜索,表示返回搜索
%匹配搜索相对应的符号
50% 会在文件的中间位置
M 当前屏幕中间 H当前屏幕最上面,L当前屏幕最下面
#和*可以搜索当前的单词
g#和g* 表示搜索当前单词的一部分
/the\> 表示搜索the \>表示结束
:nohlsearch 去除高亮的结果
ma 创建一个标签a. `a 回到a标记 ``上一个命令
 x  stands for  dl  (delete character under the cursor)
 X  stands for  dh  (delete character left of the cursor)
 D  stands for  d$  (delete to end of the line)
 C  stands for  c$  (change to end of the line)
 s  stands for  cl  (change one character)
 S  stands for  cc  (change a whole line)
:1,10y 复制1到10行
:.w newfilename 当前行复制到新文件

» 阅读全文

Tags: vim, 笔记

python mix up string 混淆字符串

有时候需要对一些字符串 加入一些文字。

python在这方面也很好操作。代码如下:

 

» 阅读全文

Tags: python, mix

mysqldump导出数据库结构

mysql导出数据库结构的命令

mysqldump -hhost -uuser -ppass --no-data db_name >file.sql

» 阅读全文

Tags: mysqldump

VIM技巧:关闭最后一个文件,而不退出VIM

I am new to VIM. I use e and w commands to edit and to write a file. It is very convenient. I am not sure if there is "close" command to close the current file without leaving VIM?

I know that q command can be used to close a file. But if it is the last file, the VIM is closed as well(actually on Mac the MacVIM does quit. Only the VIM window is closed and I could use Control-N to open a blank VIM again). I would like the VIM to stay with a blank screen.

我是一个新人,平时使用e 和w 编辑和保存文件,这太方便了。但是遇到一个问题,在最后一个文件是,我使用q命令会退出VIM。我想不退出,保留空白的状态。如何使用命令。

答案:

使用:bd 命令

» 阅读全文

Tags: vim

VIM技巧:快速删除需要的内容

平时操作html 经常需要用到一个功能,将一个标签的一行文字删除。按dw 太慢了

现在有一种快速的办法:

按 d然后再按/ 再输入你要删除内容结束的字符 <Enter> 就可以

如:<p>ie8 真的不好用,老是非法错误退出</p>

要把<p>...</p>里面内容删除的办法:

依次输入:d/<回车 就可以

» 阅读全文

Tags: vim

python RGB颜色值的比较

from PIL import Image
import operator
 
img = Image.open('image.png')
 
upper = (256,40,40)
lower = (190,0,0)
 
print '\n'.join([str(pixel) for pixel in img.getdata() \
                 if False not in map(operator.lt,lower,pixel) \
                 and False not in map(operator.gt,upper,pixel)])
 
# Output:
>>> (210, 13, 7)
(202, 21, 7)
(201, 9, 9)
(198, 11, 11)
(196, 26, 6)
(198, 15, 15)
>>> 

» 阅读全文

Tags: rgb

Records:39912345678910»