Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim visual selection delete/insert in Emacs

Tags:

emacs

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?

like image 938
Umut Tabak Avatar asked Oct 02 '11 10:10

Umut Tabak


People also ask

How to delete in visual mode in vim?

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.

How to delete multiple lines in vim in visual mode?

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.

How do I select a visual block in vim?

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.

What is insert visual in vim?

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 .


3 Answers

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.

like image 94
event_jr Avatar answered Oct 13 '22 04:10

event_jr


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!

like image 21
Tyler Avatar answered Oct 13 '22 04:10

Tyler


I think that the emacs rectangle feature would be a solution

like image 42
Thanos Tintinidis Avatar answered Oct 13 '22 04:10

Thanos Tintinidis