makecols.vim: converting lists to columns made simple
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
862 B

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. " makecols.vim - Makecolumns
  2. " Author: Levi Olson <http://leviolson.com/>
  3. " Version: 1.0
  4. function! s:beep()
  5. exe "norm! \<Esc>"
  6. return ""
  7. endfunction
  8. function! s:makecols() range
  9. let mode = visualmode()
  10. if (mode !=# "V")
  11. echo "You must be in linewise visual mode"
  12. return s:beep()
  13. else
  14. echo "You are in the right mode"
  15. endif
  16. echo s:get_visual_selection()
  17. return ""
  18. endfunction
  19. function! s:get_visual_selection()
  20. let [lnum1, col1] = getpos("'<")[1:2]
  21. let [lnum2, col2] = getpos("'>")[1:2]
  22. let lines = getline(lnum1, lnum2)
  23. let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
  24. let lines[0] = lines[0][col1 - 1:]
  25. return lines
  26. " return join(lines, "\n")
  27. endfunction
  28. vnoremap <silent> mc :<C-U>call <SID>makecols()<CR>
  29. " vim:set ft=vim sw=4 sts=4 et: