/.vim/plugin/SuperTab.vim

https://bitbucket.org/rmichnik/vim · Vim Script · 73 lines · 53 code · 2 blank · 18 comment · 3 complexity · 7e5d69baabbc8eeba90a8b406ed3b6f9 MD5 · raw file

  1. " Author: Gergely Kontra <kgergely@mcl.hu>
  2. " Version: 0.32
  3. " Description:
  4. " Use your tab key to do all your completion in insert mode!
  5. " The script remembers the last completion type, and applies that.
  6. " Eg.: You want to enter /usr/local/lib/povray3/
  7. " You type (in insert mode):
  8. " /u<C-x><C-f>/l<Tab><Tab><Tab>/p<Tab>/i<Tab>
  9. " You can also manipulate the completion type used by changing g:complType
  10. " variable.
  11. " You can cycle forward and backward with the <Tab> and <S-Tab> keys
  12. " (<S-Tab> will not work in the console version)
  13. " Note: you must press <Tab> once to be able to cycle back
  14. " History:
  15. " 0.3 Back to the roots. Autocompletion is another story...
  16. " Now the prompt appears, when showmode is on
  17. " 0.31 Added <S-Tab> for backward cycling. (req by: Peter Chun)
  18. " 0.32 Corrected tab-insertion/completing decidion (thx to: Lorenz Wegener)
  19. if !exists('complType') "Integration with other copmletion functions...
  20. let complType="\<C-n>"
  21. im <C-X> <C-r>=CtrlXPP()<CR>
  22. fu! CtrlXPP()
  23. if &smd
  24. ec''|ec '-- ^X++ mode (/^E/^Y/^L/^]/^F/^I/^K/^D/^V/^N/^P/n/p)'
  25. en
  26. let complType=nr2char(getchar())
  27. if stridx(
  28. \"\<C-E>\<C-Y>\<C-L>\<C-]>\<C-F>\<C-I>\<C-K>\<C-D>\<C-V>\<C-N>\<C-P>np",
  29. \complType)!=-1
  30. if stridx("\<C-E>\<C-Y>",complType)!=-1 " no memory, just scroll...
  31. retu "\<C-x>".complType
  32. elsei stridx('np',complType)!=-1
  33. let g:complType=nr2char(char2nr(complType)-96) " char2nr('n')-char2nr("\<C-n")
  34. el
  35. let g:complType="\<C-x>".complType
  36. en
  37. iun <Tab>
  38. iun <S-Tab>
  39. if g:complType=="\<C-p>" || g:complType=='p'
  40. im <Tab> <C-p>
  41. ino <S-Tab> <C-n>
  42. el
  43. im <Tab> <C-n>
  44. ino <S-Tab> <C-p>
  45. en
  46. retu g:complType
  47. el
  48. echohl "Unknown mode"
  49. retu complType
  50. en
  51. endf
  52. " From the doc |insert.txt| improved
  53. im <Tab> <C-n>
  54. inore <S-Tab> <C-p>
  55. " This way after hitting <Tab>, hitting it once more will go to next match
  56. " (because in XIM mode <C-n> and <C-p> mappings are ignored)
  57. " and wont start a brand new completion
  58. " The side effect, that in the beginning of line <C-n> and <C-p> inserts a
  59. " <Tab>, but I hope it may not be a problem...
  60. ino <C-n> <C-R>=<SID>SuperTab()<CR>
  61. ino <C-p> <C-R>=<SID>SuperTab()<CR>
  62. fu! <SID>SuperTab()
  63. if (strpart(getline('.'),col('.')-2,1)=~'^\s\?$')
  64. return "\<Tab>"
  65. el
  66. return g:complType
  67. en
  68. endf
  69. en