显示标签为“Vi”的博文。显示所有博文
显示标签为“Vi”的博文。显示所有博文

2009年5月21日星期四

Vimperator

Vimperator是Firefox的一个addon,可以像使用Vim一样来使用浏览器。

以下是一些命令的备忘

CTRL-Z
Disable all Vimperator keys except <Esc> and pass them to the next event handler.
If you also need to pass <Esc> in this mode to the web page, prepend it with <C-v>.

CTRL-V
If you only need to pass a single key to a JavaScript form field or another extension prefix the key with <C-v>.
When Vimperator mode is temporarily disabled with <C-z>, <C-v> will pass the next key to Vimperator instead of the web page.

Opened with the specified search engine if the token looks like a search string and the first word is the name of a search engine.
The short name of a search engine is automatically guessed from its name. If you want to set a custom name, you can change it with :dialog searchengines.

T Works like t but preselects current URL in the :tabopen query.

:tabd[uplicate]
Duplicates current tab.

:wino[pen]
Just like :tabopen but opens the resulting web page(s) in a new window.

p
Open (put) a URL based on the current clipboard contents in the current buffer.

P
Open (put) a URL based on the current clipboard contents in a new buffer. Works like p but opens a new tab.

:ju[mps]
List all jumps aka current tab's history aka session history.

r
Force reloading of the current page.

R
Force reloading of the current page skipping the cache.

<C-c>
Stop loading the current web page.

ZQ
Quit and don't save the session.

ZZ
Quit and save the session.

g<C-g>
Print file information.

[count]gi
Focus last used input field. If there is no last input field, it focuses the first input field. When used with [count] it directly jumps to the [count]th input field.

zz
Set full zoom value of current web page. Zoom value can be between 30 and 300%. If it is omitted, full zoom is reset to 100%.

/{pattern}[/]<CR>
If "\c" appears anywhere in the pattern the whole pattern is handled as though 'ignorecase' is on. "\C" forces case-sensitive matching for the whole pattern.

:noh[lsearch]
Remove the search highlighting.

:buffers [filter]
B
Show a list of buffers (=tabs) matching [filter]. Without [filter] list all tabs.

:tab {cmd}
Execute {cmd} and tell it to output in a new tab. Works only for commands that support it, currently:
:tab help
:tab prefs[!]
:tab addons
:tab downloads

g0
Switch to the first tab.

g$
Switch to the last tab.

u
Undo closing of a tab.

ExtendedHint mode
{mode} can be one of:
;; to focus a link and hover it with the mouse
;? to show information about the element (incomplete)
;s to save its destination
;a to save its destination (prompting for save location)
;f to focus a frame
;F to follow a sequence of <CR>-delimited hints in background tabs
;y to yank its destination location
;Y to yank its text description

:bma[rk]
Add a bookmark.

:bmarks [filter]
List or open multiple bookmarks. Open the message window at the bottom of the screen with all bookmarks which match [filter] either in the title or URL.

m{a-zA-Z}
Set mark at the cursor position. Marks a-z are local to the buffer, whereas A-Z are valid between buffers.

'{a-zA-Z}
Jump to the mark in the current buffer. Marks a-z are local to the buffer, whereas A-Z are valid between buffers.

:marks
Show all location marks of the current web page.

q{0-9a-zA-Z}
Record a key sequence into a macro. Available macros are {0-9a-zA-Z} (uppercase to append). Type q to stop recording.

:mac[ros] [pat]
List recorded macros matching the optional regular expression [pat]. If no regexp is given, list all macros.

:dialog printpreview

<C-a>
Increment last number in URL

<C-x>
Decrement last number in URL

0
Scroll to the absolute left of the document

$
Scroll to the absolute right of the document

gU
Go to the root of the website

:messages
Display previously given messages

:restart
Force the browser to restart

:se[t] all
Show all options.

2009年1月16日星期五

用ctags在vim里实现跳转

首先安装ctags:

sudo apt-get install ctags


然后在源码的根目录下执行命令:

ctags -R


ctags --recurse


这会在根目录下生成一个tags文件

接着在~/.vimrc里加上这两句
set tags=tags;
set autochdir

然后按Ctrl-],就可以跳转到方法定义的地方了。
要想跳回去,按Ctrl-t

参考:
http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx
http://likeyesterday.spaces.live.com/Blog/cns!A80F5D17DD9D10BF!148.entry

2009年1月8日星期四

Vim Plugin - TabBar

上次用了个叫miniBufExplorer的插件,已经很好用了,唯一的缺点是不支持Alt+{1,2,3...}来切换。
结果今天发现了另一个插件:TabBar,它是基于miniBufExplorer的。

这下可以用Alt+{1,2,3...}和Ctrl+Tab来模拟tab间的切换了。但是在窗口间切换就不方便,要用CTRL+w w,后来google了一下,发现了这篇文章:http://www.lousycoder.com/blog/index.php?/archives/97-Vim-+Project-+Tabbar.html
按里面的介绍,在~/.vimrc里加上以下的设置:
map <C-H> <C-W>h
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-L> <C-W>l
然后按Ctrl+{h,j,k,l}就可以在窗口间肆意流窜了。

默认tab的高度是1,也就是说打开的tab太多超过一行的话,后打开tab就看不见了。当然这时我们可以用鼠标拖动来扩大tab窗口的高度,然而更好的办法是配置一个tab窗口高度的最大值:
let g:Tb_MaxSize = 3

2009年1月6日星期二

Vim-Project Plugin

Project quickstart guide:
(From http://wiki.rubyonrails.org/rails/pages/howtousevimwithrails)

Here is a quick guide to get you started after installing Project.
1. Type :Project in Vim to launch the Project plugin.
2. Type \C to launch the create project routine.
3. Enter a name for the project (e.g. @RailsApp@)
4. Enter the directory path (e.g. /Users/me/Development/RailsApp)
5. Type . as the CD parameter.
6. Type * as the filter.
7. Type \r to load all files and directories.

project中文帮助: http://www.cppblog.com/DrMagic/archive/2007/11/19/36964.html

要使用本插件, 只需将其放置到 Vim 的插件目录(~/.vim/plugin)即可. 参见
"|add-global-plugin|", 在下次打开 Vim 时, 输入如下命令 >
:Project
或者 >
:Project filename

如果没有指定具体的项目文件, 那么会默认使用$HOME/.vimprojects文件.

命令: [g]vim +Project 可在 Vim 启动时同时自动载入project插件窗口.
(可以在~/.bashrc里加个alias: alias vimp='vim +Project')

在~/.vimrc里设置标志位和热键映射:
" Set project-flags
let g:proj_flags="imstg"
" Project-adding-mappings
nmap P :Project
g:proj_flags默认的标志位是imst,这里加上g以后,就可以按关闭和打开左边的项目窗口。
设置了上面那个映射之后,按\P就可以将光标焦点移到项目窗口。

一些热键:

(Shift+回车) 或 \s: 打开一个文件,但会水平分割目标窗口.

\v: 仅仅显示文件内容, 而光标依然停留在项目窗口中.

: 增加项目窗口的宽度,反复点击则为在原宽度和增加后的宽度之间切换.

\g: 搜索当前项目层所有文件.

\G: 搜索项目所有层所有文件.

当项目窗口因为或开或闭的折叠显得凌乱时, 按 zm 可以关闭所有的展开折叠.

\r: 根据过滤符更新光标处的项目(也就是刷新该目录)

\R: 递归执行 \r.

另一个有用的plugin: miniBufExplorer

把下载的文件copy到~/.vim/plugin/目录下
然后在.vimrc里加上:
" minibufexpl setting
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

然后就可以用Ctrl+Tab键来切换tab了。

要想删除某个文件的打开记录,则先Ctrl+UP切换到上方的MiniBufExplorer窗口,然后将光标移动到要删的文件名上(不是删文件,而是删文件的打开记录),按d就行了。

2008年6月19日星期四

Vi 跳到文件第一行、最后一行

:$ 跳到文件最后一行
:0或:1 跳到文件第一行

== 2008-06-24

gg 跳到文件第一行
Shift + g 跳到文件最后一行
感谢Ryan

2008年6月11日星期三

vi下查找匹配的字符串

正向查找(就是向下查找)

/some_string

按n查找下一个

反向查找(就是向上查找)

?another_string