Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Split Words Into Lines?

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

like image 659
AJ. Avatar asked Feb 10 '10 02:02

AJ.


1 Answers

Map it if you are using it often in your ~/.vimrc file or similar

vnoremap \ll :'<,'>s/ /^M/g<cr>
nnoremap \ll :s/ /^M/g<cr>

if you are only wanting to to it multiple times now you can use & command to repeat last search also

Theres also gqq but thats for textwidth eg 80 chars

like image 153
michael Avatar answered Oct 17 '22 09:10

michael