My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. " File: plugin/words_tools.vim
  2. " Author: Luc Hermitte <hermitte {at} free {dot} fr>
  3. " <URL:http://code.google.com/p/lh-vim/>
  4. " License: GPLv3 with exceptions
  5. " <URL:http://code.google.com/p/lh-vim/wiki/License>
  6. " Version: 3.0.0
  7. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $ (19th Mar 2012)
  8. " Purpose: Define functions better than expand("<cword>")
  9. "
  10. " Note: They are expected to be used in insert mode (thanks to <c-r>
  11. " or <c-o>)
  12. "
  13. "===========================================================================
  14. " Return the current keyword, uses spaces to delimitate {{{1
  15. function! GetNearestKeyword()
  16. let c = col ('.')-1
  17. let ll = getline('.')
  18. let ll1 = strpart(ll,0,c)
  19. let ll1 = matchstr(ll1,'\k*$')
  20. let ll2 = strpart(ll,c,strlen(ll)-c+1)
  21. let ll2 = matchstr(ll2,'^\k*')
  22. " let ll2 = strpart(ll2,0,match(ll2,'$\|\s'))
  23. return ll1.ll2
  24. endfunction
  25. " Return the current word, uses spaces to delimitate {{{1
  26. function! GetNearestWord()
  27. let c = col ('.')-1
  28. let l = line('.')
  29. let ll = getline(l)
  30. let ll1 = strpart(ll,0,c)
  31. let ll1 = matchstr(ll1,'\S*$')
  32. let ll2 = strpart(ll,c,strlen(ll)-c+1)
  33. let ll2 = strpart(ll2,0,match(ll2,'$\|\s'))
  34. ""echo ll1.ll2
  35. return ll1.ll2
  36. endfunction
  37. " Return the word before the cursor, uses spaces to delimitate {{{1
  38. " Rem : <cword> is the word under or after the cursor
  39. function! GetCurrentWord()
  40. let c = col ('.')-1
  41. let l = line('.')
  42. let ll = getline(l)
  43. let ll1 = strpart(ll,0,c)
  44. let ll1 = matchstr(ll1,'\S*$')
  45. if strlen(ll1) == 0
  46. return ll1
  47. else
  48. let ll2 = strpart(ll,c,strlen(ll)-c+1)
  49. let ll2 = strpart(ll2,0,match(ll2,'$\|\s'))
  50. return ll1.ll2
  51. endif
  52. endfunction
  53. " Return the keyword before the cursor, uses \k to delimitate {{{1
  54. " Rem : <cword> is the word under or after the cursor
  55. function! GetCurrentKeyword()
  56. let c = col ('.')-1
  57. let l = line('.')
  58. let ll = getline(l)
  59. let ll1 = strpart(ll,0,c)
  60. let ll1 = matchstr(ll1,'\k*$')
  61. if strlen(ll1) == 0
  62. return ll1
  63. else
  64. let ll2 = strpart(ll,c,strlen(ll)-c+1)
  65. let ll2 = matchstr(ll2,'^\k*')
  66. " let ll2 = strpart(ll2,0,match(ll2,'$\|\s'))
  67. return ll1.ll2
  68. endif
  69. endfunction
  70. " Extract the word before the cursor, {{{1
  71. " use keyword definitions, skip latter spaces (see "bla word_accepted ")
  72. function! GetPreviousWord()
  73. let lig = getline(line('.'))
  74. let lig = strpart(lig,0,col('.')-1)
  75. return matchstr(lig, '\<\k*\>\s*$')
  76. endfunction
  77. " GetLikeCTRL_W() retrieves the characters that i_CTRL-W deletes. {{{1
  78. " Initial need by Hari Krishna Dara <hari_vim@yahoo.com>
  79. " Last ver:
  80. " Pb: "if strlen(w) == " --> ") == " instead of just "== ".
  81. " There still exists a bug regarding the last char of a line. VIM bug ?
  82. function! GetLikeCTRL_W()
  83. let lig = getline(line('.'))
  84. let lig = strpart(lig,0,col('.')-1)
  85. " treat ending spaces apart.
  86. let s = matchstr(lig, '\s*$')
  87. let lig = strpart(lig, 0, strlen(lig)-strlen(s))
  88. " First case : last characters belong to a "word"
  89. let w = matchstr(lig, '\<\k\+\>$')
  90. if strlen(w) == 0
  91. " otherwise, they belong to a "non word" (without any space)
  92. let w = substitute(lig, '.*\(\k\|\s\)', '', 'g')
  93. endif
  94. return w . s
  95. endfunction
  96. " }}}1
  97. "========================================================================
  98. " vim60: set fdm=marker: