12月 26th, 2009[分享] Vim小技巧几则

一、中文帮助手册页

Vim7.2中文手册页下载:官方地址    我的Dropbox存档

内有详细的使用帮助和说明,默认vim会自动根据系统的当前locale选择显示语言。

如果要强制使用英文手册页,可以:set helplang=en,或切换中文手册页:set helplang=cn

二、启用拼写检查

:set spell或者:setlocal spell spelllang=en_us

它打开 ’spell’ 选项并指定检查美国英语。

注意:Vim只检查单词的拼写,不做语法检查。

要搜索下一个拼写有问题的单词:

*]s*
]s            移动到光标之后下一个拼写有问题的单词。命令前的计数可以
用来重复。适用 ‘wrapscan’。

*[s*
[s            类似于 “]s” 但反向搜索。寻找光标之前拼写有问题的单词。
不能识别分散在两行的单词,因而可能停在不被高亮为坏词的
单词上。但不会停在行首没有大写开头的单词上。

*]S*
]S            类似于 “]s” 但只检查坏词,不检查偏僻词或其它区域的词。

*[S*
[S            类似于 “]S” 但反向搜索。

要加入词汇到自定义的单词列表:

*zg*
zg            把光标所在的单词作为一个好 (good) 词加入到 ’spellfile’
的第一个名字对应的文件。命令前加上计数指示使用
’spellfile’ 的第几个项目。计数 2 使用第二个项目。

可视模式下把选择的字符序列作为一个单词 (包括空白!)。
如果光标在标为坏词的文本上,使用标注的文本。
否则使用非单词字符分隔的光标所在的单词。

如果该单词在其它拼写文件里被显式标注为坏词,结果无法预
测。

详情继续:help spell,以上内容节选自vim的中文帮助手册页。
三、在vim中快速查字典(Linux only)

该功能需要使用到命令行版的stardict,请安装sdvc

ubuntu用户使用apt-get即可迅速安装sdvc

$ sudo apt-get install sdvc

至此,准备工作结束。

下面开始编辑vim的配置文件在vim中光标移动到单词上,使用shift+f可以新分割出来一个窗口显示单词的翻译。

复制粘贴以下内容到~/.vimrc

———————– 我是分割线开始,不要复制我 ———————————

” 使用F查询光标所在处的单词的中文
function!  Mydict()
let  expl=system(’sdcv  -n  ‘  .
\   expand(”<cword>”))
windo  if
\  expand(”%”)==”diCt-tmp”  |
\  q!|endif
50vsp  diCt-tmp
setlocal  buftype=nofile  bufhidden=hide  noswapfile
1s/^/\=expl/
1
endfunction
nmap  F  :call  Mydict()<cr><C-W><C-W>

———————– 我是分割线结束,不要复制我 ———————————

如果在gvim中使用则在~/.gvimrc中添加:

———————– 我是分割线开始,不要复制我 ———————————

function  Mybln()
let  expl=system(’sdcv  -n  ‘  .
\  v:beval_text  .
\  ‘|fmt  -cstw  40′)
return  expl
endfunction

set  bexpr=Mybln()
set  beval

———————– 我是分割线结束,不要复制我 ———————————

四、在长行中轻松移动

编辑.vimrc,加入以下内容:

———————– 我是分割线开始,不要复制我 ———————————
” 解决超长行移动的困难
” 重新定义<UP> <DOWN>
:nmap <UP> gk
:imap <UP> <ESC>gka

:nmap <DOWN> gj
:imap <DOWN> <ESC>gja
———————– 我是分割线结束,不要复制我 ———————————

以后就可以通过键盘的上、下方向键轻松在一个超长行中移动了。
五、不要显示@@@@@

编辑.vimrc,加入以下内容:

———————– 我是分割线开始,不要复制我 ———————————
set display=lastline
———————– 我是分割线结束,不要复制我 ———————————

后记:Chrome编辑水木blog会导致文章的排版中的回车全部丢失,汗死。。。

ubuntu已经9.10了,我懒得升了,还是9.04,感觉用得还是很顺手的。

1、预备工具 bootchart

$ sudo apt-get install bootchart

2、使用bootchart

安装完后重启系统,即会在/var/log/bootchart目录下生成系统启动过程的时序图我本本的启动时序图见本文最后。

3、禁用bootchart

注意:默认情况下,每次系统启动时bootchartd都会执行,并生成这样一个启动时序图。

禁止自动执行bootchartd的方法很简单,如下:

$ cd /etc/init.d

$ sudo update-rc.d -f stop-bootchart remove

Removing any system startup links for /etc/init.d/stop-bootchart …

/etc/rc2.d/S99stop-bootchart

/etc/rc3.d/S99stop-bootchart

/etc/rc4.d/S99stop-bootchart

/etc/rc5.d/S99stop-bootchart

4、启用bootchart

$ cd /etc/init.d

$ sudo update-rc.d stop-bootchart start 99 2 3 4 5 .

Adding system startup for /etc/init.d/stop-bootchart …

/etc/rc2.d/S99stop-bootchart -> ../init.d/stop-bootchart

/etc/rc3.d/S99stop-bootchart -> ../init.d/stop-bootchart

/etc/rc4.d/S99stop-bootchart -> ../init.d/stop-bootchart

/etc/rc5.d/S99stop-bootchart -> ../init.d/stop-bootchart

 强烈推荐使用牛13的 Dropbox 进行文件同步,注册 Dropbox 并在不同电脑安装 Dropbox 同步程序后,设置一个同步文件夹,就可以让 Dropbox 后台运行了,在该文件夹的任何操作都会同步到其它登录统一帐号的电脑。

Dropbox支持Windows、Linux和Mac OS系统的客户端程序,可以随时随地的同步文件夹,而无需考虑所使用的操作系统。

官方有一个介绍Dropbox功能和使用的短片

修改/etc/apt/source.list,加入以下两行更新源地址:

deb http://linux.getdropbox.com/ubuntu jaunty main
deb-src http://linux.getdropbox.com/ubuntu jaunty main

水木blog贴图不便,找个网上别人的图来展示一下Dropbox吧。

07月 9th, 2009milw0rm最后的打包…

最新milw0rm站点数据镜像下载: Security Tools

PoC has gone with wind…

rar格式的比较好办,rar 3.6以后版本对unicode的支持更加智能化。Linux下使用rar进行压缩/解压缩时,可以使用-scuc,来强制指定文件名用unicode编码进行压缩和解压缩。对于zip格式的需要注意,Windows下创建的zip压缩包默认是使用的本地编码。即如果是简体中文的Win系统,则会使用GBK来存储文件名。此时,在Linux下解压缩包含中文文件名的压缩包时,需要在命令行使用参数-O cp936。同理,在Windows下如果用WinRAR来解压缩zip文件倒是没有这个限制,WinRAR会自动检测文件名的编码方式。不建议在Linux下使用gz/tar格式的压缩文件来给Windows机器共享文件,如果gz/tar压缩包中包含中文文件名会导致winrar解压缩包含中文文件名的文件时失败!

 工具链

  • build-essential              Informational list of build-essential packages

手册页

  • manpages-dev              Manual pages about using GNU/Linux for development
  • glibc-doc                      GNU C Library: Documentation
  • manpages-posix-dev    Manual pages about using a POSIX system for development

以上所有工具/文档统一使用apt-get来安装。
IDE

  • 下载编译vim所依赖的所有libs
    $ sudo apt-get build-dep vim
  • http://clewn.sourceforge.net下载vimgdb
  • 按照vimgdb压缩包中的说明,给vim打补丁,编译生成可执行程序

交叉索引/自动补全

  • ctags
    * 配合vim的code_complete插件实现函数的自动补全
    code_complete的函数自动补全demo
    *配合vim的OmniCppComplete插件实现C结构体成员的自动补全
  • cscope
    * 代码阅读
    * 代码交叉索引查找
    # Find this C symbol
    # Find this global definition
    # Find functions called by this function
    # Find functions calling this function
    # Find this text string
    # Find this egrep pattern
    # Find this file
    # Find files #including this file

我用的Ubuntu发行版本是9.04(jaunty),使用了compiz作为系统的window decorator,显卡是Intel的集成显卡,当在Firefox中使用F11进行全屏浏览切换时,会闪现桌面背景一下然后消失。

经过一番Google之后,找到了问题的解决方法:

System -> Preferences -> CompizConfig Settings Manager -> General,去掉Unredirect Fullscreen Windows前面的勾选,退出后即可。

1.显示器分辨率问题

添加以下内容到/etc/X11/xorg.conf

Section “Monitor”
Identifier    “Configured Monitor”
EndSection

Section “Monitor”
Identifier    “HDMI-1″
Option        “Ignore” “True”
EndSection

Section “Monitor”
Identifier    “HDMI-2″
Option        “Ignore” “True”
EndSection

Section “Screen”
Identifier    “Default Screen”
Monitor        “Configured Monitor”
Device        “Configured Video Device”
DefaultDepth     24
SubSection “Display”
Modes “1280×800” “1024×768″
# The following line was an auto-configuration added by an external VGA projector; you might leave it out to try
# letting the system detect dimensions appropriate for whatever display you happen to use.
Virtual    2432 864
EndSubSection
EndSection

Section “Device”
Identifier    “Configured Video Device”
Driver        “intel”
Option        “monitor-HDMI-1″ “HDMI-1″
Option        “monitor-HDMI-2″ “HDMI-2″
EndSection

2.无线网卡问题

Ubuntu 8.10的更新源中有适用于X200的驱动可以直接识别并加载Intel的无线网卡驱动,在我的机器上的lshw程序输出如下:

$ sudo lshw -C network
*-network
description: Ethernet interface
product: 82567LM Gigabit Network Connection
vendor: Intel Corporation
physical id: 19
bus info: pci@0000:00:19.0
logical name: eth0
version: 03
serial: 00:1f:16:0a:d6:58
size: 100MB/s
capacity: 1GB/s
width: 32 bits
clock: 33MHz
capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=0.3.3.3-k6 duplex=full firmware=1.8-3 ip=118.229.188.151 latency=0 link=yes module=e1000e multicast=yes port=twisted pair speed=100MB/s
*-network
description: Wireless interface
product: PRO/Wireless 5100 AGN [Shiloh] Network Connection
vendor: Intel Corporation
physical id: 0
bus info: pci@0000:03:00.0
logical name: wmaster0
version: 00
serial: 00:21:5d:8a:23:b8
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list logical ethernet physical wireless
configuration: broadcast=yes driver=iwlagn latency=0 module=iwlagn multicast=yes wireless=IEEE 802.11abgn

如果需要从命令行配置无线网卡,可以通过iwconfig命令来完成,包括设定ssid,加密方式等。可能大部分人很熟悉ifconfig命令了,但是设置无线网卡必需通过iwconfig命令,这是唯一需要注意的问题。

3.红色指点杆中键滚屏功能故障

创建文件 /etc/hal/fdi/policy/mouse-wheel.fdi,并添加以下内容到该文件

<match key=”info.product” string=”TPPS/2 IBM TrackPoint”>
<merge key=”input.x11_options.EmulateWheel” type=”string”>true</merge>
<merge key=”input.x11_options.EmulateWheelButton” type=”string”>2</merge>
<merge key=”input.x11_options.YAxisMapping” type=”string”>4 5</merge>
<merge key=”input.x11_options.XAxisMapping” type=”string”>6 7</merge>
<merge key=”input.x11_options.Emulate3Buttons” type=”string”>true</merge>
<merge key=”input.x11_options.EmulateWheelTimeout” type=”string”>200</merge>
</match>

4.VMware Player中的Windows XP出现按下方向键弹出开始菜单的错误键位映射问题

$sudo echo “xkeymap.nokeycodeMap = true” > /etc/vmware/config

参考资源:

  1. http://www.thinkwiki.org/wiki/Installing_Ubuntu_8.04_&_8.10_on_an_X20 强烈推荐的参考资源,绝大部分遇到的问题都可以在这里得到解决
  2. http://ubuntuforums.org/showthread.php?t=972349

本周有两件事情需要记录一下:

1. 新买了一块硬盘,换到了我的爱本上。

2.在新硬盘上安装了Ubuntu 8.10,单系统,不再设置Windows分区。

实际上,接触Linux已经有7个年头了,七年之痒这句话在我的身上有了一次另类的展现。

说实话,以前也在本本上装过Linux,从开始的双系统,到后来的虚拟机。Linux,一句话,“想说爱你,不容易!”

笔记本硬件兼容差和软件质量差是我在过去的7年里对Linux的使用总结。

但是,在这次经过了事前充分的功课准备,和我在实验室一年多来的完全Linux化工作体验感受,下定了决心,要再给Linux桌面一个机会,给我的新硬盘一个机会。

果然,安装、配置和使用,和我预想的一样,没有遇到什么困难。基本没有经过多少hack,大部分的本本自带硬件都可以正确的识别和使用,稍微hack了一下就解决了宽屏显示和无线网络的问题。

软件方面,有了apt,再也不用在硬盘里单独准备一个目录整理安装软件了!

为了使用微软的Visio,安装了VMWare Player,以前在Windows下装的虚拟机全都可以直接使用!太爽了!

网银?支付宝?IE?Visio?统统不是问题!

最后show一张桌面截图,看看Ubuntu的桌面特效和VMWare Player的兼容,Vista和Windows 7都可以去一边凉快凉快了o(∩_∩)o..

VMWare Player in Ubuntu 8.10 on ThinkPad x200

关于BackTrack是什么,我在这就不多介绍了,相信搞安全评估的朋友们都有所耳闻吧。

前2天试了下在VMWare虚拟机中硬盘安装Live-CD的BackTrack 2,发现官方给的安装指南似乎有误,安装后无法硬盘引导启动系统,故自己摸索解决了这个问题,并记录下来,以给后来者一点启发。

对于需要多系统共存的朋友们需要注意了,BackTrack 2使用的是lilo引导的多系统,而我的这篇笔记中没有对多系统共存的情况进行试验,所以本文仅供参考,呵呵。

安装前最后一次提醒:强烈建议反复在虚拟机里安装成功后再在硬盘安装,安装前一定要做好备份!!

ok,let’s do it step by step…

Step 1:分区

BT ~ # fdisk /dev/sda

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous content won’t be recoverable.

Command (m for help):n [enter]

Command action

e extended

p primary partition (1-4)

p [enter]

Partition number (1-4): 1[enter]

First cylinder (1-456, default 1):[enter]

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): 458 [enter]

Command (m for help):n [enter]

Command action

e extended

p primary partition (1-4)

p [enter]

Partition number (1-4): 2 [enter]

First cylinder (459-522, default 459):[enter]

Using default value 459

Last cylinder or +size or +sizeM or +sizeK (459-522, default 522): [enter]

Command (m for help): a [enter]

Partition number (1-4): 1 [enter]

Command (m for help): t [enter]

Partition number (1-4): 2 [enter]

Hex code (type L to list codes): 82 [enter]

Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p [enter]

Disk /dev/sda: 4294 MB, 42944967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 458 3678853+ 83 Linux

/dev/sda2 459 522 514080 82 Linux swap

Command (m for help): w [enter]

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Step 2:格式化分区

BT ~ # mkfs.ext3 /dev/sda3

mke2fs 1.38 (30-Jun-2005)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

460288 inodes, 919713 blocks

45985 blocks (5.00%) reserved for the super user

First data block=0

29 block groups

32768 blocks per group, 32768 fragments per group

15872 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912,819200,884736

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

Step 3:挂载分区

BT ~#mkdir /mnt/sda1

BT ~#mount /dev/sda1 /mnt/sda1

Step 4:启动BackTrack Installer

BackTrack Installer的启动必须先进入X图形界面,启动KDE桌面系统使用下面的命令:

BT ~#startx

进入KDE桌面系统之后可以依次选择:

K -> System -> Backtrack Installer

启动BackTrackInstaller后会看到其中的Install BackTrack to和Write MBR to已经自动填写好了,默认情况不需要修改,直接选择Real方式进行Install就可以了。

启动BackTrackInstaller

最后再上几个图吧,enjoy~~

系统启动

系统登录

KDE桌面系统


© 2007 猪在笑 | iKon Wordpress Theme by TextNData | Powered by Wordpress | rakCha web directory
登录 | 访问数171372 | 水木BLOG | 水木社区 | 关于我们 | Blog论坛 | 法律声明 | 隐私权保护 | 京ICP证050249号
水木社区Blog系统是基于KBS系统WordPress MU架构的