Alex Rivera | Logout

Vim: Split Words Into Lines?

Asked 2010-02-10T02:21:48.337
9

I frequently use Shift+J in visual mode to join several selected lines into a single line with the original lines separated by spaces. But I am wondering if there is an opposite shortcut such that it will split selected words into separate lines (one word per line).

Of course I can do:

:'<,'>s/ /^M/g

But something more succinct in terms of keystrokes would be very useful. Has anyone else found a way to do this?

Thanks in advance,

-aj

Edit
Report

1 Answer

2

I use this in my config to Un-Join/split the last word on current line:

nnoremap <C-J> g_F<Space><Space>i<CR><Esc>k

It maps CTRL-j to do the opposite of Join, I think of it as Counter-Join :) I mostly use it to convert between K&R style vs ...the other kind of curly brace placement.

g_       : search for the last non-whitespace on current line
F<Space> : reverse-find first space
<Space>  : go one character forward
i        : enter insert mode
<CR>     : insert a line break
<Esc>    : return to normal mode
k        : go up one line to where we begun
answered 2013-04-10T14:36:21.757

Your Answer