给xcode插上vim的翅膀

野生的世界 2013-07-05

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

C-w nAdd new assistant editor
C-w qDelete one assistant editor
C-w sAdd new assistant editor horizontally
C-w vAdd new assistant editor vertically
C-w h,j,k,lMove 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

:w[rite] 
:wq 
:q[uit] 
:s[ubstitute] 
:setSee Options for supported variables
:mapMaps globally across XVim, in all modes
:nmapMaps normal mode
:vmapMaps visual mode
:imapMaps insert mode
:omapMaps operator pending mode

XVim original commands

:runInvoke Xcode's 'run' command
:makeInvoke Xcode's 'build' command
:xhelpShow quick help for current insertion point
:xccmdInvoke arbitrary command in Xcode's actions in its menu. Takes one argument as its action to invoke. Actions here are available.
:nissueInvoke "jump to next issue". ":ni" does the samse.
:pissueInvoke "jump to previous issue". ":pi" does the same.
:ncounterpartInvoke "jump to next counterpart". ":nc" does the same.
:pcounterpartInvoke "jump to previous counterpart". ":pc" does the same.

Options

[no]ignorecase 
[no]wrap 
[no]wrapscan 
[no]errorbells 
[no]incsearch 
[no]gdefault 
[no]smartcase 
guioptionsSee below
timeoutlenThe time in milliseconds that is waited for mapped key sequence to complete (default 1000)
laststatus0 or 1 : status line is hidden, 2 : status line is displayed (default 2)
[no]pasteboardWhether yank/delete/pull uses the standard clipboard

pasteboard

guioptions

A limited subset of Vim options is implemented.

rShow vertical scrollbar
bShow 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.

相关推荐

APCDE / 0评论 2019-12-01
野生的世界 / 0评论 2015-10-29