给xcode插上vim的翅膀

From : http://blog.cnrainbird.com/index.php/2012/12/11/gei_xcode_cha_shang_vim_de_chi_bang/

 

用eclipse的同学开始使用xcode的时候总会问:上下两行交换位置用什么快捷键,选中{怎么自动跳到}。好吧,上下两行交换交换位置在4.x的xcode里确实是有快捷键的:option+command+[向上移;option+command+]向下移。但是这个{}之间的来回跳转我确实没研究出来。于是想着vim里有这样的快捷键,于是google:xcode+vim竟然有个叫作xvim的神器,于是赶紧装了。下面是在这个环境下编程了三四天的感受:

1.作为vim党,用这个插件确实很享受,尤其是习惯了h,j,k,l这些键上下移动

2.{}来回跳转解决了,在大量if,else的时候很有用哟。

3.可以直接直接跳转到哪些行,yy,dd自然不在话下。另外上下两行交换位置也不用按那么多键了,直接ddp搞定。

4.习惯了在vim里输入完东西,然后就:w保存。要知道xcode每次编译运行都会自动保存代码的。so,正在逐渐的适应:run,相当于command+b哟。

唯一不爽的:

选择多行,command+x剪切的时候会崩溃,这问题出现过两次了,还没空看代码解决Bug,不过遇到这种情况用vim的快捷键就好了。

另外就是目前还不支持:20,30d这种指令,准备有空了仔细看下代码给加上。

 

最后说下安装方法:

1.下载安装包

2.双击安装

3.重启xcode

 

然后就是have fun了~

 

Feature List

We try to keep this up to date, but sometimes implementation can get ahead of documentation. If a command is missing, just try it in XVim first - it might already be there!

If you've tried a command and it really is missing, feel free to create an issue and a friendly contributor will pick it up eventually.

Motion

b, B, f, F, gg, G, h, j, k, l, w, W, t, T, 0, $, ^, %, +, -, {, }, (, ), n, N, ', `, M, H, L

Comma and semicolon are supported. Toggle inclusive/exclusive by v is supported.

Mark

File-local marks are supported. Global marks are not yet supported.

The '.' mark (last insertion point) is supported. gi (insert mode at last insertion point) is supported.

Scroll

C-d, C-f, C-e, C-u, C-b, C-y, zz, zb, zt

Jumps

C-o, C-i, gd

If you want to open the file under the cursor you can use 'gd' instead of 'gf' in XVim environment.

Insert

a, A, i, I, o, O

Yank, put and change

d, dd, D, y, yy, Y, c, cc, C, r, s, x, X

Line join

J

Shift block

Normal mode: >, >>, <, <<

Visual mode: >, <

Case change operations

Normal mode: ~, gu, gU, g~

Visual mode: u, U, ~, gu, gU

Undo

u, C-r

Visual

v, V

Ctrl-v is not supported now. (v, V in visual mode to toggle or escape from visual mode is supported)

Visual block mode is currently not supported.

Window manipulation

Input Operation
C-w n Add new assistant editor
C-w q Delete one assistant editor
C-w s Add new assistant editor horizontally
C-w v Add new assistant editor vertically
C-w h,j,k,l Move focus between editors

Search and Replace

/, ?, #, *, g*, g#, :s, n, N

Regex search is supported using the ICU regex format.

Substitution does not work as Vim does. When you input command following

:%s/xxxx/yyyy/

XVim does replace the first occurence of xxxx IN THE FILE (not each line ). If you want to replace all the occurence of xxxx with yyyy in the file you can specify

:%s/xxxx/yyyy/g

Currently replacing first occurence of xxxx with yyyy each line is not available

Insert mode commands

C-y, C-e

Print status commands

C-g

Text Object

ib, iB, i(, i), i{, i}, i[, i], i>, i<, i", i', iw, iW ab, aB, a(, a), a{, a}, a[, a], a>, a<, a", a', aw, aW

Recording

q, @

Dot command

The dot command ('.') is supported.

Ex commands

Command Note
:w[rite]  
:wq  
:q[uit]  
:s[ubstitute]  
:set See Options for supported variables
:map Maps globally across XVim, in all modes
:nmap Maps normal mode
:vmap Maps visual mode
:imap Maps insert mode
:omap Maps operator pending mode

XVim original commands

Command Note
:run Invoke Xcode's 'run' command
:make Invoke Xcode's 'build' command
:xhelp Show quick help for current insertion point
:xccmd Invoke arbitrary command in Xcode's actions in its menu. Takes one argument as its action to invoke. Actions here are available.
:nissue Invoke "jump to next issue". ":ni" does the samse.
:pissue Invoke "jump to previous issue". ":pi" does the same.
:ncounterpart Invoke "jump to next counterpart". ":nc" does the same.
:pcounterpart Invoke "jump to previous counterpart". ":pc" does the same.

Options

Command Note
[no]ignorecase  
[no]wrap  
[no]wrapscan  
[no]errorbells  
[no]incsearch  
[no]gdefault  
[no]smartcase  
guioptions See below
timeoutlen The time in milliseconds that is waited for mapped key sequence to complete (default 1000)
laststatus 0 or 1 : status line is hidden, 2 : status line is displayed (default 2)
[no]pasteboard Whether yank/delete/pull uses the standard clipboard

pasteboard

guioptions

A limited subset of Vim options is implemented.

Option Effect
r Show vertical scrollbar
b Show horizontal scrollbar

These changes only take effect on startup, meaning this option is only effective if used from within your .xvimrc.

Key mapping

XVim supports five map commands: map, nmap, vmap, imap, omap. A map command can change one or more keystrokes into one or more key strokes.

Note: The default timeout value for multi-key mapping completion is 1 seconds (1000 milliseconds). You can change it using 'timeoutlen' option.

Examples:

nmap n e
imap ' <Esc>
nmap u 5jiInsert some text<Esc>
nmap ,w :w<cr>

.xvimrc

At startup XVim looks for ~/.xvimrc. Each line in this file is executed as an ex command. This allows you to configure mappings and options.

Example:

set ignorecase
set wrapscan
set guioptions=r
nmap n e

Known problems

See XVim issue page.

猜你喜欢

转载自duchengjiu.iteye.com/blog/1899909