I was trying to find a replacement of vim's visual mode which is extremely useful, say I would like to delete the first two characters on the below two lines
11 line1
22 line2
in vim, I enter into the visual mode and select the region I want to delete, and delete it. More开发者_如何学Cover I also can add to the column after
11
22
like
11 added line1
22 added line2
wiht Shift+I after selecting the column in visual mode. Is there a way to do the same in emacs?
Sounds like Emacs' rectangle features. You kind have to visualize a rectangle in your head between the point and the mark.
C-x r k
to kill rectangle
C-x r t
to fill rectangle with text. You want a rectangle zero column wide to do your second request.
cua-mode provides exactly this sort of feature. You can turn it on with the following in your .emacs
:
(setq cua-enable-cua-keys nil)
(cua-mode)
The first line is necessary to prevent cua-mode
from replacing a bunch of standard keyboard shortcuts with Windows-style things (C-c for copy, C-x for cut etc).
Once you're in cua-mode
, C-enter
will turn on visual rectangles, which you can then expand with the movement keys (arrows, C-n
, C-f
etc) to cover the text you want to manipulate. While this is going on, hitting enter
moves the cursor around the edges of the rectangle, and anything you type is inserted outside the rectangle on the same side as the cursor. The insertion matches the size of the rectangle, so if you want to add the same text to the beginning (or middle or end) of a bunch of lines at once, this is the fastest way to do it.
If you disabled the cua keybindings, then C-w
will kill the contents of the rectangle.
It's kind of unfortunate that the rectangle bits of cua-mode aren't in their own mode, as lots of people who don't want the cua-mode bindings don't realize that the mode also has this very cool feature!
I think that the emacs rectangle feature would be a solution
It sounds like Vimpulse may be what you need:
http://www.emacswiki.org/emacs/vimpulse.el
Vimpulse emulates Vim's most popular features, like Visual mode and text objects. Vimpulse is a set of modifications to Viper, the standard library that emulates vi. Vimpulse is not a minor mode; as soon as it is loaded, Viper will start working in a more Vim-like way.
精彩评论