vim/gvimにかぎらず、テキストエディターを使っていて矩形操作(ブロック操作)をする機会は少ない。めったにやらないから、一度成功したことでも、忘れてしまう。しょうがないのでvim-userメーリングリスト(今ではgooglegroups)に久しぶりに質問したみた。最後のKen Takataさんの解は、まだ試してない。マウスを4回クリックするなんて、オトロシイ!
[自分]
On my gvim screen, there are two sections on a same column:
abc
def
ghi
rst
uvw
xyz
and I'd like to have two different columns aligned on same lines, like this:
abc rst
def uvw
ghi xyz
Yes, I think I have read all of the related docs available on the net, but they can't help. So I'm going to rely on the old friends here. TIA.
[Paul(Jan)]
Visual block select (control-v) and yank the second block. Enter two spaces after the c. Either enter normal mode and paste, or control-o and p.
[自分]
We only get the [p] result as:
abc rst
uvw
xyz
def
ghi
That is, and has been, our current perpetual problem.
[Pongthep]
You did something wrong.
Well, you have...
abc
def
ghi
rst
uvw
xyz
In exit mode (escape), move the cursor to 'c'.
Type 'a' to enter insert mode, then type 2 spaces.
Escape again, then move the cursor to 'r'.
ctrl-v to enter visual block mode.
Then type 'l', 'l', 'j', 'j', to cover the block to move.
The current cursor will then move to 'z'.
Type 'd' to delete them.
Then repeating 'k' until the cursor points 'a'.
Then type '$', and finally 'p'.
Hope that helps.
[Aswin]
With cursor on the 'r' of 'rst', do this key sequence:
<ctrl-v>lll jj d gg A <space><space><esc>>p
This is same as what Jan said, just putting down the keystrokes.
[自分]
Thanks Aswin and Pongthep. I think I was doing the same thing as suggested by using the gvim gui, that is, using a small animal-like good-old hand device and everytime got the funny pasting result by hitting [p].
On the jEdit program which is one of the new generation of the text editors on Linux, you have [rectangular select] and [clipboard extension]>>[vertical paste] menu items under the [[Edit]] primary menu. This "vertical paste" thing did the task I wanted long perfectly.
I shall use the jEdit editor when some table-like editing operation is needed.
Any way, thanks very much for your valuable helps. Thanks again.
[Ben Fritz]
If you were to actually, correctly, use CTRL+V to select the text you copied, then Vim will AUTOMATICALLY do a "vertical paste".
Either you aren't following directions, or you have a mapping interfering. You shouldn't need a different editor to do this. It's built into Vim and has been for years.
[自分]
Oh Ben, you are right.
This morning I tried to do THE same task by using ONLY vim key commands like [h][j][k][l] for cursor movement, then I got the perfect desired result i.e. a vertical pasting. The lesson I may have learned is "don't use mouse for cursor movement for gvim rectangular operations", and, "You only should use those venerable vim key commands".
I prefer an appropriate set of menu items and mouse operations, though. Gvim must be a GUIed vim.
Thanks, any way.
[KF]
Use Alt-LMB (Left Mouse Button) to do a VISUAL BLOCK selection.
Add two spaces, and do a paste...
HTH
[kamaraju kusumanchi]
Does not seem like a portable solution. For example, in Debian + KDE
setup, + drags the window as mouse moves along.
[自分]
Kamaraju may be right. It doesn't work on my environment which is Linux/Ubuntu too. Did KF mean a Windows environment, or ...?
[KF]
I'm on Windows, maybe this will help for KDE/Genome:
" .vimrc settings...
" Alt-Mouse-Left for block selections
" You need to disable/switch the Alt key for KDE/Gnome (Windowsettings for KDE)
nmap <A-LeftMouse> ms<LeftMouse><C-q>`so
imap <A-LeftMouse> <Esc><C-q>`^ms<Esc>gi<LeftMouse><C-o><C-q>`so
vmap <A-LeftDrag> <LeftDrag>
vmap <A-LeftMouse> <C-q>
Ref: http://code.jity.de/Jack12816/linux-environment/commit/85e397753e5cceb505dfd1f7ccbfe1955fd83c29?view=inline&w=1
HTH
[Ken Takata]
See ":help gui-mouse-select".
It says "quadruple clicking makes it rectangular block-wise."
Regards,
Ken Takata
【2017/01/29追記】
[自分]
Hi Ken,
Thanks for giving us one of the deepest esoterica of the gvim editor.
But we somehow feel the four consecutive mouse clicks on a same position and in a very short time so horrible that we haven't tried them yet. When a good time should come someday, we'd surely try them, though.
Thanks again.
[Ryan Nabinger]
A quick note:
I find P more useful than p because of columns' typical left-alignment and my desire to not mangle the tailend of my paste destination.
Also, 1v is very useful when dealing with blocks (:he visual-start), especially when transposing blocks / overwriting blocks.
最近のコメント