Sorting IP addresses in vim 1) Prepend zeros to the single-digit and two-digit numbers: :%s/\<\d\d\?\>/0&/g|%&& 2) Sort the lines comparing IP addresses as text: :sort r/\(\d\{3}\)\%(\.\d\{3}\)\{3}/ or (%!sort -n ) ?! 3) Strip redundant leading zeros: :%s/\<00\?\ze\d//g -------------------------- To run all three steps as a single command, one can use the following one-liner: :%s/\<\d\d\?\>/0&/g|%&&|sor r/\(\d\{3}\)\%(\.\d\{3}\)\{3}/|%s/\<00\?\ze\d//g