Skip to content

Instantly share code, notes, and snippets.

@suplo
Created July 14, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suplo/c3eff82edab317f6e4a50cc943f7fcae to your computer and use it in GitHub Desktop.
Save suplo/c3eff82edab317f6e4a50cc943f7fcae to your computer and use it in GitHub Desktop.
Split a file into multiple chunk by lines count
https://stackoverflow.com/questions/40509083/vim-split-one-file-into-multiple-files-based-on-row-count
up vote
8
down vote
accepted
First, you define a control variable:
:let i = 1
Then, you write lines 1 to 99 (inclusive) to a file named after the current value of the control variable, cut those line, and increment the control variable;
:exec "1,99w! chunk-" . i|1,99d|let i = i + 1
Repeat as many times as needed:
49@:
This should give you 50 files named chunk-1 to chunk-50.
Since 5000 is not divisible by 99 you will be left with 50 lines. Write them to chunk-51:
:w chunk-51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment