Last Updated: February 25, 2016
·
1.041K
· novalore

Vim: Copy/paste selection in new file

Do you usually select text in vim then yank it with y, open a new file and paste the selection with p?

Stop wasting your time!

To copy selection in new file just use the usual write command :w when in Visual mode (vim will automatically add the range to your command line, resulting in : '<,'>w newfile )

To cut and paste a selection in a new file: enter Visual mode and select what you want, then hit : and type !cat > newfile resulting in : '<,'>:!cat > newfile