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. Moreover 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?
The words VISUAL LINE will appear at the bottom of the screen. Use navigation commands, such as the Arrow keys, to highlight multiple lines of text. Once the desired text is highlighted, use commands to manipulate it. Press d to delete, then move the cursor to the new location, and press p to paste the text.
If you want to select lines visually and delete them, use linewise visual mode ( V ), select the lines with j and k (or down-arrow and up-arrow), then press d to delete them.
While you are inside a visual mode, you can switch to another visual mode by pressing either v , V , or Ctrl-v . For example, if you're in line-wise visual mode and you want to switch to block-wise visual mode, just type Ctrl-v . Try it! This will start visual mode on the same selected area as the last visual mode.
vim has two "modes": COMMAND mode and INSERT mode. In COMMAND mode, you execute commands (like undo, redo, find and replace, quit, etc.). In INSERT mode, you type text. There is a third mode, VISUAL mode, that is used to highlight and edit text in bulk. To go into INSERT mode from COMMAND mode, you type i .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With