bairui

Sample Asciidoc File

Jan 17th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Jump to the Longest Line
  2. ========================
  3. Barry Arthur
  4. v0.6, January 13, 2012
  5.  
  6. :pygments:
  7.  
  8. __The evolution of a Vimmer__
  9.  
  10. Ignoring the prosaic question of ``Why would you ever want to?!'',
  11. consider how, in your editor of choice, you would jump to the longest
  12. line in the file.
  13.  
  14. Vim provides a _lot_ of jump commands, possibly more so than any
  15. other editor. We can jump to a matching item; jump between words,
  16. sentences and paragraphs; jump between classes or #defined regions in
  17. a source file; jump between files and back and more.
  18. Jump-to-longest-line, however, is missing. This forces us to craft a
  19. solution using either existing builtin Vim commands, the ex commands,
  20. VimL (Vim's scripting language), or (more typically) a mixture of all
  21. three.
  22.  
  23. We compare three different approaches to solving this problem, each
  24. one arguably a little further along in the ``evolution'' of a Vim
  25. user.
  26.  
  27. Approach #1: Normal and Ex Commands
  28. -----------------------------------
  29.  
  30. .++LongestLine_Ex++ - Uses mostly Vim Normal and Ex commands:
  31. [source,vim,numbered]
  32. ------------------------------------------------------------------
  33.  
  34. function! LongestLine_Ex()
  35. global/^/substitute/^/\=len(getline('.')).' '.line('.').' '
  36. sort n
  37. normal! Gwyiwu
  38. return @"
  39. endfunction
  40.  
  41. -------------------------------------------------------------------
  42.  
  43. This style of solution would be considered by capable Vim users who
  44. have not yet ventured very far (if at all) into VimL -- limiting their
  45. choices to just Normal Mode and Ex commands.
  46.  
  47. NOTE: Although this solution is presented here in a function (for
  48. comparative purposes with the other solutions presented later), these
  49. sorts of solutions are typically hand-typed when needed or, at best,
  50. briefly stored in macros.
Advertisement
Add Comment
Please, Sign In to add comment