Skip to content

Instantly share code, notes, and snippets.

@matiasfha
Last active January 19, 2018 19:32
Show Gist options
  • Save matiasfha/e351f02a5dc55ab0d1edea93cdfb2940 to your computer and use it in GitHub Desktop.
Save matiasfha/e351f02a5dc55ab0d1edea93cdfb2940 to your computer and use it in GitHub Desktop.
MoveSelectionToBuffer is a command that allows you to move a block of text from the current buffer to a new buffer that will be saved in the same path as the original buffer with the name that is passed as argument. The original text will be removed and pasted in the new buffer. Flaws: I didn't find a way to call the command using a key mapping.
function! AddPathToName(name)
let b:path = expand('%:p:h')
let b:filename = join([b:path, a:name],'/')
execute "vnew ". b:filename
endfunction
"named vnew
command! -nargs=1 VN call AddPathToName(<f-args>)
function! MoveSelectionToBuffer(name)
execute 'norm gvdw<Esc>'
let b:selection = @*
call AddPathToName(a:name)
execute 'norm pw'
endfunction
command! -range -nargs=1 MSTB call MoveSelectionToBuffer(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment