Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move the text after the cursor to a new line

Tags:

vim

I am Vim newbie, and I'm using MacVim on OSX Snow Leopard. One of the most common actions I have to take is to move the cursor to a new line but also move the text after the cursor to the new line. I know that pressing 'o' in normal or visual mode moves the cursor to a new line and switches the mode to insert.

What I'd like to do is move the cursor to a new line, and move the text after the cursor to that new line as well, preferably staying in the normal mode? Is this possible? How can I accomplish this task?

like image 906
Anup Avatar asked Apr 01 '12 13:04

Anup


People also ask

What moves the cursor to a new line?

Move the text cursor to where you want the new line to begin, press the Enter key, hold down the Shift key, and then press Enter again. You can continue to press Shift + Enter to move to each new line, and when ready to move to the next paragraph, press Enter .

How do I move the cursor to the next line in HTML?

If you are talking about moving the cursor to next line on screen when you are at command prompt then you can use the key combination ctrl+enter to add a line break and reach next line.

How do I move my cursor to a specific line?

Jump to a specific line number ↩Press Ctrl+G, or select Goto > Goto Line, to open the Goto Line palette. Type in the number to which you want to jump. Press Enter, & your cursor will now be on that line.

How do I move text to the next line in Vim?

I know that pressing 'o' in normal or visual mode moves the cursor to a new line and switches the mode to insert.


3 Answers

If the cursor is on a <space> as in ([] marks the cursor):

lorem ipsum[ ]dolor sit amet

the simplest is to do r<CR>, that is "replace the current character with a linebreak".

Otherwise, use @knittl's solution.

like image 119
romainl Avatar answered Oct 20 '22 16:10

romainl


So you want to move everything in the current line, which comes after the cursor to the next line? Read: insert a line break??

(move cursor)
i (or a)
<return>
<esc> (or ^C)

To map this sequence of keystrokes to a single key, follow @thb's suggestion and use the :map command:

:map <F2> i<CR><ESC>
like image 10
knittl Avatar answered Oct 20 '22 16:10

knittl


:map <F2> i<CR>

This keeps vi in insert mode.

like image 8
prongs Avatar answered Oct 20 '22 17:10

prongs