Skip to content

Instantly share code, notes, and snippets.

@rleger
Last active March 29, 2016 21:01
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 rleger/3e26c0ed78b64f08d1540b2f0d148777 to your computer and use it in GitHub Desktop.
Save rleger/3e26c0ed78b64f08d1540b2f0d148777 to your computer and use it in GitHub Desktop.
Vim Sort Php Use
// Sort PHP use imports by length
// You don't have to select the use imports, hitting <leader>su anywhere in your file
// will sort the imports and put your cursor back where you left off.
//
// Replace ^M by hitting <C-v><C-m> in insert mode
function! SortPhpUseByLength()
exec 'normal mrgg/^use\s^Mma/^class\s^M/^use\s^MNmb:nohlsearch^M:''a,''b! awk ''{ print length(), $0 | "sort -n | cut -d\\ -f2-" }''^M''r'
endfunction
nmap <leader>su :call SortPhpUseByLength()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment