Advertisement
devinteske

Efficient Columnar Alignment in vim(1)

Aug 18th, 2015
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. Problem: You have some text similar to below and want to align COLUMN B
  2. Solution: Using vim(1) you can do this in 7 easy steps.
  3.  
  4. ############################################################
  5.  
  6. LINE COLUMN A COLUMN B
  7. 1 asd def
  8. 2 asd def ghi
  9. 3 boo blech
  10. 4 11111 asd xx
  11. 5 --- asd asd asd
  12.  
  13. ############################################################
  14.  
  15. How to align COLUMN B efficiently using vim?
  16.  
  17. Sep 1. :let tabs = "^I^I"
  18. NB: ^I is TAB (2x TAB is enough in this case)
  19. Step 2. Position cursor on line 1, start of COLUMN A
  20. Step 3. Ctrl-V, 4, Down-Arrow
  21. NB: Selects starting column for 5 lines
  22. Step 4. :s/\%V[^[:space:]]\{1,\}\zs\ze/\=tabs/
  23.  
  24. NB: One more step required to get to aligned COLUMN B
  25.  
  26. ############################################################
  27.  
  28. Now the text appears as below:
  29.  
  30. LINE COLUMN A COLUMN B
  31. 1 asd def
  32. 2 asd def ghi
  33. 3 boo blech
  34. 4 11111 asd xx
  35. 5 --- asd asd asd
  36.  
  37. ############################################################
  38.  
  39. Final steps:
  40.  
  41. Step 5. Position cursor on line 1, column under "C" in "COLUMN B"
  42. Step 6. Ctrl-V, 4, Down-Arrow
  43. NB: Selects starting column for 5 lines
  44. Step 7. :s/\%V[[:space:]]*//
  45.  
  46. ############################################################
  47.  
  48. Now the text appears as below:
  49.  
  50. LINE COLUMN A COLUMN B
  51. 1 asd def
  52. 2 asd def ghi
  53. 3 boo blech
  54. 4 11111 asd xx
  55. 5 --- asd asd asd
  56.  
  57. ############################################################
  58.  
  59. Wunderbar!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement