Skip to content

Instantly share code, notes, and snippets.

@wellle
Last active January 24, 2017 16:52
Show Gist options
  • Save wellle/9233238 to your computer and use it in GitHub Desktop.
Save wellle/9233238 to your computer and use it in GitHub Desktop.
function! Group()
normal! l"ry$"ly0
redir => message
execute "silent %g/\\V" . escape(@l, '/') . "/d"
redir END
let cnt = matchstr(message, '\d\+')
execute "normal! ggO" . cnt . ' ' . @l . ' || ' . @r . "\<Esc>0"
endfunction
nnoremap <silent> <leader>g :call Group()<CR>
@wellle
Copy link
Author

wellle commented Feb 26, 2014

Group similar lines around the cursor, similar to uniq -c. Example:

this is unrelated
some prefix, some details
some prefix, other details
some prefix, even more details
another prefix

With the cursor in front of other details press \g to group all lines sharing the prefix left to the cursor, leaving the text to the right as example details:

3 some prefix, || other details
this is unrelated
another prefix

This is useful to quickly group tons of lines into similar groups based on common prefixes.

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