2011年3月8日 星期二

在 Vim 多行同時插入相同文字

引用 http://stackoverflow.com/questions/253380/how-do-i-insert-text-at-beginning-of-a-multi-line-selection-in-vi-vim
  • Use Ctrl+v to select the first column of text in the lines you want to comment.
  • Then hit 'I' and type the text you want to insert.
  • Then hit 'Esc', wait 1 second and the inserted text will appear on every line.
這個功能在MadEdit中使用更容易,按Alt+2就可以了。但這都是要在連續的幾列之間才能用,更厲害的是Sublime Text 2,可以跳著選,然後真正的多行修改。

2011年3月5日 星期六

在 Vim 使用 MONACO 字型

引用 http://plog.longwin.com.tw/programming/2007/08/14/programmer_best_font_monaco_2007
1 先下載MONACO.TTF到/usr/share/fonts/truetype/
2 執行 fc-cache -f -v
3 .vimrc中加上:
set guifont=Monaco\ 10

Python檔案內容的編碼宣告

# -*- coding: UTF-8 -*-

#encoding=utf-8

在 Vim 下去掉 ^M

引用 http://graphics.csie.ntu.edu.tw/~jonathan/tpd/2008/06/get-rid-of-carrot-m/


:%s/^M$//g

Vim指令01: 取代字串

引用 http://vimregex.com/#substitute

:range s[ubstitute]/pattern/string/cgiI
For each line in the range replace a match of the pattern with the string where:
c
Confirm each substitution
g
Replace all occurrences in the line (without - only first).
i
Ignore case for the pattern.
I
Don't ignore case for the pattern.

:1,5s/java/scala/g
選取第1行到第5行,並將其中所有的java取代成scala

:%s/java/scala/g
選取全檔,並將其中所有的java取代成scala

:%s/[Rr]uby/Python/g
選取全檔,並將其中的Ruby和ruby都取代成Python