close

雖然用vim一段時間了,但還是常常會忘記指令

尤其覺得vim的visual mode超好用,卻常常不知道要做的事情對應的指令是甚麼

於是就決定上網查一下:

先貼上指令全文吧:


(This reference page is modified from Sandip Chitale's Rectangular Edit documentation. Thanks Sandip.)

Block Mode in action

This NetBeans screenshot shows a visual block mode selection. Notice that the status bar displays both jVi's current mode and the dimensions of the block mode selection. The cursor is in the lower right corner of the selected block. It can be moved around with the arrow keys to extend and shrink the selection. There are commands to shift the cursor to other corners.

Notes for non vi/vim users using Block Mode

  • jVi is turned on/off with a checkbox in the Tools menu
  • The current mode displays in the status bar beneath editor region.
  • Use <ESC> to end the current mode or operation.
  • gv starts visual mode with the previous visual selection
  • u and Ctrl-R are undo and redo in command mode.

Selecting a Rectangular Region

  • Converting a normal selection
    Create a selection, for example drag the mouse, so the the endpoints of the selection are the corners of the rectangular region of interest. Then enter Ctrl-V to begin visual block mode. Then use the arrow keys if needed.
  • arrow keys
    If not already in visual block mode, enter Ctrl-V and then use the arrow keys to move move the cursor. In block mode, cursor motion adjust a corner of the block. Note that any vi/vim motion commands (such as a pattern search, eg /class) may be used to move the cursor and so extend or shrink the block.
  • moving the cursor to other corners
    The following illustration shows how the cursor is moved to other corners of the block.
 lower case,
moves cursor to
opposite corner
upper case,
moves cursor to
other end of line
end result
of entering
○●
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789

Notice that entering ○●○● touches all four corners returning the cursor to its original position.

When there are TABS in the selection, the display may not look correct, however the commands behave correctly.

Block Mode Commands

Note that most commands that add text take an optional count, in particular the pPI and A commands, this results in tiling the block. See the last example.

By default the delete, yank and put commands operate on an internal buffer. To use them with the clipboard, prepend the command with "*. For example, "*d deletes the block and places the text in the clipboard. (the double quote is part of the command).

When jvi (vim) puts block mode data into a buffer, the d and y commands, it marks that buffer as containing block mode data. The command behaves differently if the buffer does not contain block mode data.

The following examples all assume the buffer has block mode data. The last examples show advanced command features in action.

If there are TABS in the selection, they are "split" as needed to square things up.

Selection Command Result Buffer
0123456789
0123456789
0123456789
0123456789
0123456789

x or d
delete

      

(刪除指令會把刪掉的
東西放到buffer裡)

0123456789
01789
01789
01789
0123456789
2345
2345
2345
0123456789
0123456789
0123456789
0123456789
0123456789

y
yank

 

(複製)

0123456789
0123456789
0123456789
0123456789
0123456789
2345
2345
2345
01234
01234
01234
01234
01234

uppercase
put before cursor,
from buffer

 

(大寫P把buffer的東西

貼到游標前)

01234
01-- 234
01++++ 234
01*****234
01234
--
++++
*****
no change
01234
01234
01234
01234
01234

p lowercase
put after cursor,
from buffer

 

(小寫p把buffer的東西

貼到遊標後)

01234
012-- 34
012++++ 34
012*****34
01234
--
++++
*****
no change
In next, buffer first provides the source data, 
then it is replaced by what was deleted.
01234567
01234567
01234567
01234567
01234567

P or p
replace selected
from buffer

 

(先框起來再貼上的話就

是取代掉框起來的東西;

且框起來的東西會被放入

buffer)

01234567
01-- 567
01++++ 567
01*****567
01234567
after
234
234
234
0123456789
0123456789
0123456789
0123456789
0123456789

rx
replace all
with char

(如果用ra,就是把字元取

代成a;取代掉的字不會放

入buffer)

0123456789
01xxxxx789
01xxxxx789
01xxxxx789
0123456789
no change
0123456789
0123456789
0123456789
0123456789
0123456789

c-+*<ESC>
change each
line selection
to user text

(框起來按c,可把原來框起來的地方刪掉,再打要取代掉的字即可。用c和用r的差別是,r會取代成同一個字重複出現;c可以打任意字串)

0123456789
01-+*789
01-+*789
01-+*789
0123456789
no change
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ

U

Uppercase

 

(框起來按大寫U改成大寫)

aBcDeFgHiJ
aBCDEFGHiJ
aBCDEFGHiJ
aBCDEFGHiJ
aBcDeFgHiJ
no change
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ
aBcDeFgHiJ

u

Lowercase

 

(框起來按小寫u改成小寫)

aBcDeFgHiJ
aBcdefgHiJ
aBcdefgHiJ
aBcdefgHiJ
aBcDeFgHiJ
no change
01234
01234
01234
01234
01234

I#*<ESC>
insert
before block

 

(框起來按大寫I,可在每行前插入字串)

01234
0#*1234
0#*1234
0#*1234
01234
no change
01234
01234
01234
01234
01234

A*#<ESC>
append
after block

 

(框起來按大寫A,可在每行後插入字串)

01234
0123*#4
0123*#4
0123*#4
01234
no change
Notice that the behavior of I and A are different when short lines are included in the selection. This is intentional so that both types of behavior are available.
01234
01234
0
0
01
234
01234

I+=<ESC>
insert
before block

 

(若有缺行沒框到者,大寫I不會有插入的資料)

01234
01+=234
0
0
01+=234
01234
no change
I, insert, does not affect short lines (above).
A, append, modifies short lines (below).
01234
01234
0
0
01
234
01234

A++<ESC>
append
after block

 

(但若有缺行沒框到者,大寫A仍會在後面插入字串)

01234
0123++4
0 ++
0 ++
0123++4
01234
no change
The following example shows how p, the put command, inserts blanks after short lines to complete a put. The $ in the example command move the cursor to the end of the line.
01234
01234
0
0
01234
01234
y$p
put extends
short lines
if needed
01234
01234012
0 0
0 0
01234012
01234
012
0
0
012
Here is an example using a count with the put command. The buffer contents are shown before the command is exectued.
0123
0123
0123
0123
0123
3p
tile three
copies of
buffer
0123
01ababab23
01cdcdcd23
01efefef23
0123
ab
cd
ef
no change


最後附上連結網址:
http://jvi.sourceforge.net/javahelpset/jvi-vis_block.html 
 
 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 yann98700 的頭像
    yann98700

    yann98700的部落格

    yann98700 發表在 痞客邦 留言(0) 人氣()