Skip to content

Instantly share code, notes, and snippets.

@urubatan
Created September 18, 2011 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urubatan/1224723 to your computer and use it in GitHub Desktop.
Save urubatan/1224723 to your computer and use it in GitHub Desktop.
VIM function to save the selected range to a file and replace the contents with a pointer to the file. Goot to be used with http://github.com/urubatan/codemerger
function! ExtractText(fileName,first_line,last_line)
let text = getline(a:first_line,a:last_line)
execute ":" . a:first_line . "," . a:last_line . "delete"
execute "normal O{{" . a:fileName . "}}"
return writefile(text, a:fileName)
endfunction
command! -range -nargs=1 Es call ExtractText(<f-args>,<line1>,<line2>)
@urubatan
Copy link
Author

Forgot to say, to use it, select visually a range :Es newFileName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment