├── .gitignore ├── .vim ├── doc │ ├── tags │ └── supertab.txt ├── colors │ └── ir_black.vim ├── ftplugin │ └── python │ │ └── khuno.vim ├── syntax │ └── python.vim └── plugin │ └── supertab.vim ├── README.rst └── .vimrc /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .netrwhist 3 | .local_vim 4 | 5 | -------------------------------------------------------------------------------- /.vim/doc/tags: -------------------------------------------------------------------------------- 1 | g:SuperTabCompletionContexts supertab.txt /*g:SuperTabCompletionContexts* 2 | g:SuperTabContextDefaultCompletionType supertab.txt /*g:SuperTabContextDefaultCompletionType* 3 | g:SuperTabDefaultCompletionType supertab.txt /*g:SuperTabDefaultCompletionType* 4 | g:SuperTabLongestHighlight supertab.txt /*g:SuperTabLongestHighlight* 5 | g:SuperTabMappingBackward supertab.txt /*g:SuperTabMappingBackward* 6 | g:SuperTabMappingForward supertab.txt /*g:SuperTabMappingForward* 7 | g:SuperTabMappingTabLiteral supertab.txt /*g:SuperTabMappingTabLiteral* 8 | g:SuperTabMidWordCompletion supertab.txt /*g:SuperTabMidWordCompletion* 9 | g:SuperTabRetainCompletionDuration supertab.txt /*g:SuperTabRetainCompletionDuration* 10 | supertab supertab.txt /*supertab* 11 | supertab-completioncontexts supertab.txt /*supertab-completioncontexts* 12 | supertab-contextdefault supertab.txt /*supertab-contextdefault* 13 | supertab-contextdiscover supertab.txt /*supertab-contextdiscover* 14 | supertab-contextexample supertab.txt /*supertab-contextexample* 15 | supertab-contexttext supertab.txt /*supertab-contexttext* 16 | supertab-defaultcompletion supertab.txt /*supertab-defaultcompletion* 17 | supertab-duration supertab.txt /*supertab-duration* 18 | supertab-forwardbackward supertab.txt /*supertab-forwardbackward* 19 | supertab-intro supertab.txt /*supertab-intro* 20 | supertab-longesthighlight supertab.txt /*supertab-longesthighlight* 21 | supertab-mappingtabliteral supertab.txt /*supertab-mappingtabliteral* 22 | supertab-midword supertab.txt /*supertab-midword* 23 | supertab-options supertab.txt /*supertab-options* 24 | supertab-usage supertab.txt /*supertab-usage* 25 | supertab.txt supertab.txt /*supertab.txt* 26 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Python-Vim-IDE 2 | ============== 3 | 4 | This is my vim config for hacking on Python. I hope you like it. 5 | I use default vim and SublimeText2 a lot as well. 6 | 7 | 8 | Installation 9 | ============ 10 | 11 | Back up your ~/.vimrc and ~/.vim directory (or in you $VIMRUNTIME if not in home dir). 12 | Checkout this project somewhere. 13 | Symlink the .vimrc and .vim directory into your home directory (or $VIMRUNTIME). 14 | 15 | 16 | Details 17 | ======= 18 | 19 | * Syntax highlighting 20 | 21 | * (http://www.vim.org/scripts/script.php?script_id=790) in .vim/syntax/python.vim 22 | 23 | * Tab completion (http://www.vim.org/scripts/script.php?script_id=1643) 24 | 25 | * Tab after a non-whitespace character (except those below) does keyword completion 26 | 27 | * Tab after `/` does filename completion 28 | 29 | * Tab after `.` does omnicompletion (http://www.vim.org/scripts/script.php?script_id=1542) 30 | 31 | * q (insert or command mode) will close the preview port. (:pc) 32 | 33 | * (shift+tab) will do regular keyword completion after `.` instead of omnicompletion. 34 | 35 | * Enter a virtualenv, your python path should be respected (http://sontek.net/blog/detail/turning-vim-into-a-modern-python-ide#virtualenv) 36 | 37 | * Flake8 38 | 39 | * https://github.com/alfredodeza/khuno.vim 40 | 41 | * You will need to install flake8 with pep8 and pyflakes globally to get this. 42 | 43 | * this plugin rocks. 44 | 45 | * hit or fn+F7 as a shortcut to Khuno show. 46 | 47 | * Folding 48 | 49 | * Just using indentation folds from the default .vimrc (I don't use folding):: 50 | 51 | :help fold 52 | 53 | zM to fold everything 54 | zR to unfold everything 55 | za to toggle the current fold 56 | zA to recursively toggle the current fold 57 | 58 | Everything is unfolded to start. 59 | 60 | * Django settings: 61 | 62 | Before launching vim (or mvim) just set the environment variable:: 63 | 64 | export DJANGO_SETTINGS_MODULE="myproject.settings" 65 | 66 | TODO:: 67 | 68 | Probably should look at this pathogen thing and Command+T or somesuch. 69 | 70 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " vimrc file for following the coding standards specified in PEP 7 & 8. 2 | " 3 | " To use this file, source it in your own personal .vimrc file (``source 4 | " ``) or, if you don't have a .vimrc file, you can just symlink to it 5 | " (``ln -s ~/.vimrc``). All options are protected by autocmds 6 | " (read below for an explanation of the command) so blind sourcing of this file 7 | " is safe and will not affect your settings for non-Python or non-C files. 8 | " 9 | " 10 | " All setting are protected by 'au' ('autocmd') statements. Only files ending 11 | " in .py or .pyw will trigger the Python settings while files ending in *.c or 12 | " *.h will trigger the C settings. This makes the file "safe" in terms of only 13 | " adjusting settings for Python and C files. 14 | " 15 | " Only basic settings needed to enforce the style guidelines are set. 16 | " Some suggested options are listed but commented out at the end of this file. 17 | 18 | " Number of spaces that a pre-existing tab is equal to. 19 | " For the amount of space used for a new tab use shiftwidth. 20 | au BufRead,BufNewFile *py,*pyw,*.c,*.h,*html,*js set tabstop=8 21 | 22 | " What to use for an indent. 23 | " This will affect Ctrl-T and 'autoindent'. 24 | " Python: 4 spaces 25 | " C: tabs (pre-existing files) or 4 spaces (new files) 26 | au BufRead,BufNewFile *.py,*pyw,*.html,*.js set shiftwidth=4 27 | au BufRead,BufNewFile *.py,*.pyw,*.html,*.js set expandtab 28 | fu Select_c_style() 29 | if search('^\t', 'n', 150) 30 | set shiftwidth=8 31 | set noexpandtab 32 | el 33 | set shiftwidth=4 34 | set expandtab 35 | en 36 | endf 37 | au BufRead,BufNewFile *.c,*.h call Select_c_style() 38 | au BufRead,BufNewFile Makefile* set noexpandtab 39 | 40 | " Use the below highlight group when displaying bad whitespace is desired. 41 | highlight BadWhitespace ctermbg=red guibg=red 42 | 43 | " Display tabs at the beginning of a line in Python mode as bad. 44 | au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/ 45 | " Make trailing whitespace be flagged as bad. 46 | au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/ 47 | 48 | " Wrap text after a certain number of characters 49 | " Python: No limit 50 | " C: 79 51 | " Uncomment this if you want to limit your textwidth in python 52 | " can be very annoying .. 53 | " au BufRead,BufNewFile *.py,*.pyc set textwidth=79 54 | au BufRead,BufNewFile *.c,*.h set textwidth=79 55 | 56 | " Turn off settings in 'formatoptions' relating to comment formatting. 57 | " - c : do not automatically insert the comment leader when wrapping based on 58 | " 'textwidth' 59 | " - o : do not insert the comment leader when using 'o' or 'O' from command mode 60 | " - r : do not insert the comment leader when hitting in insert mode 61 | " Python: not needed 62 | " C: prevents insertion of '*' at the beginning of every line in a comment 63 | au BufRead,BufNewFile *.c,*.h set formatoptions-=c formatoptions-=o formatoptions-=r 64 | 65 | " Use UNIX (\n) line endings. 66 | " Only used for new files so as to not force existing files to change their 67 | " line endings. 68 | " Python: yes 69 | " C: yes 70 | au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix 71 | 72 | 73 | " ---------------------------------------------------------------------------- 74 | " The following section contains suggested settings. While in no way required 75 | " to meet coding standards, they are helpful. 76 | 77 | " Set the default file encoding to UTF-8: 78 | set encoding=utf-8 79 | 80 | " Puts a marker at the beginning of the file to differentiate between UTF and 81 | " UCS encoding (WARNING: can trick shells into thinking a text file is actually 82 | " a binary file when executing the text file): ``set bomb`` 83 | 84 | " For full syntax highlighting: 85 | let python_highlight_all=1 86 | syntax on 87 | 88 | " Automatically indent based on file type: 89 | "filetype indent on 90 | " Keep indentation level from previous line: 91 | "set autoindent 92 | 93 | " Folding based on indentation: 94 | set foldmethod=indent 95 | set nofoldenable 96 | 97 | """""""""""""""""""""""""""""""" 98 | " END http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc 99 | """""""""""""""""""""""""""""""" 100 | 101 | filetype on 102 | filetype plugin on 103 | "set iskeyword+=. 104 | 105 | autocmd FileType python set omnifunc=pythoncomplete#Complete 106 | autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS 107 | autocmd FileType html set omnifunc=htmlcomplete#CompleteTags 108 | autocmd FileType css set omnifunc=csscomplete#CompleteCSS 109 | 110 | " inoremap 111 | 112 | " setlocal tabstop=4 113 | set softtabstop=4 114 | " I like hitting tab and getting two spaces 115 | au BufRead,BufNewFile *.js,*.html,*.css set softtabstop=2 116 | " setlocal shiftwidth=4 117 | " setlocal textwidth=80 118 | " setlocal smarttab 119 | " setlocal expandtab 120 | " setlocal smartindent 121 | " set noic "no ignore case 122 | " set t_Co=256 123 | 124 | set cursorline 125 | set laststatus=2 126 | "set clipboard=unnamed 127 | "set go+=a 128 | "vnoremap y "+y 129 | "set paste 130 | se nu 131 | set mouse=a 132 | set background=dark 133 | 134 | " http://vim.wikia.com/wiki/In_line_copy_and_paste_to_system_clipboard 135 | " sudo apt-get install xclip 136 | " Doesn't seem to hurt MacVim 137 | vmap y: call system("xclip -i -selection clipboard", getreg("\"")) 138 | nmap :call setreg("\"",system("xclip -o -selection clipboard"))p 139 | 140 | 141 | "This should be in /etc/vim/vimrc or wherever you global vimrc is. 142 | "But, if not, I for one can't live without it. 143 | if has("autocmd") 144 | au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif 145 | endif 146 | 147 | " if you ever actually need to type \ in insert mode, this is a problem 148 | " it's a shortcut to close the code-complete window. 149 | " well, maybe you have a different so .. hrm 150 | " TODO 151 | inoremap q :pci 152 | " and the same for visual mode 153 | noremap q :pc 154 | 155 | " no beeps 156 | set vb 157 | " show column number 158 | set ruler 159 | 160 | " always trim trailing whitespace .. is there ever a good reason? 161 | autocmd BufWritePre * :%s/\s\+$//e 162 | 163 | " Khuno 164 | noremap :Khuno show 165 | 166 | " http://sontek.net/blog/detail/turning-vim-into-a-modern-python-ide#virtualenv 167 | " Add the virtualenv's site-packages to vim path 168 | py << EOF 169 | import os.path 170 | import sys 171 | import vim 172 | if 'VIRTUAL_ENV' in os.environ: 173 | project_base_dir = os.environ['VIRTUAL_ENV'] 174 | sys.path.insert(0, project_base_dir) 175 | activate_this = os.path.join(project_base_dir, 'bin/activate_this.py') 176 | execfile(activate_this, dict(__file__=activate_this)) 177 | EOF 178 | 179 | 180 | " for things that are particular to this user/computer, 181 | " you can add commands to a .local_vim file in your home dir 182 | " and uncommenting the following 183 | " source .local_vim 184 | 185 | -------------------------------------------------------------------------------- /.vim/colors/ir_black.vim: -------------------------------------------------------------------------------- 1 | " ir_black color scheme 2 | " More at: http://blog.infinitered.com/entries/show/8 3 | 4 | 5 | " ******************************************************************************** 6 | " Standard colors used in all ir_black themes: 7 | " Note, x:x:x are RGB values 8 | " 9 | " normal: #f6f3e8 10 | " 11 | " string: #A8FF60 168:255:96 12 | " string inner (punc, code, etc): #00A0A0 0:160:160 13 | " number: #FF73FD 255:115:253 14 | " comments: #7C7C7C 124:124:124 15 | " keywords: #96CBFE 150:203:254 16 | " operators: white 17 | " class: #FFFFB6 255:255:182 18 | " method declaration name: #FFD2A7 255:210:167 19 | " regular expression: #E9C062 233:192:98 20 | " regexp alternate: #FF8000 255:128:0 21 | " regexp alternate 2: #B18A3D 177:138:61 22 | " variable: #C6C5FE 198:197:254 23 | " 24 | " Misc colors: 25 | " red color (used for whatever): #FF6C60 255:108:96 26 | " light red: #FFB6B0 255:182:176 27 | " 28 | " brown: #E18964 good for special 29 | " 30 | " lightpurpleish: #FFCCFF 31 | " 32 | " Interface colors: 33 | " background color: black 34 | " cursor (where underscore is used): #FFA560 255:165:96 35 | " cursor (where block is used): white 36 | " visual selection: #1D1E2C 37 | " current line: #151515 21:21:21 38 | " search selection: #07281C 7:40:28 39 | " line number: #3D3D3D 61:61:61 40 | 41 | 42 | " ******************************************************************************** 43 | " The following are the preferred 16 colors for your terminal 44 | " Colors Bright Colors 45 | " Black #4E4E4E #7C7C7C 46 | " Red #FF6C60 #FFB6B0 47 | " Green #A8FF60 #CEFFAB 48 | " Yellow #FFFFB6 #FFFFCB 49 | " Blue #96CBFE #FFFFCB 50 | " Magenta #FF73FD #FF9CFE 51 | " Cyan #C6C5FE #DFDFFE 52 | " White #EEEEEE #FFFFFF 53 | 54 | 55 | " ******************************************************************************** 56 | set background=dark 57 | hi clear 58 | 59 | if exists("syntax_on") 60 | syntax reset 61 | endif 62 | 63 | let colors_name = "ir_black" 64 | 65 | 66 | "hi Example guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 67 | 68 | " General colors 69 | hi Normal guifg=#f6f3e8 guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 70 | hi NonText guifg=#070707 guibg=black gui=NONE ctermfg=black ctermbg=NONE cterm=NONE 71 | 72 | hi Cursor guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=reverse 73 | hi LineNr guifg=#3D3D3D guibg=black gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE 74 | 75 | hi VertSplit guifg=#202020 guibg=#202020 gui=NONE ctermfg=darkgray ctermbg=darkgray cterm=NONE 76 | hi StatusLine guifg=#CCCCCC guibg=#202020 gui=italic ctermfg=white ctermbg=darkgray cterm=NONE 77 | hi StatusLineNC guifg=black guibg=#202020 gui=NONE ctermfg=blue ctermbg=darkgray cterm=NONE 78 | 79 | hi Folded guifg=#a0a8b0 guibg=#384048 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 80 | hi Title guifg=#f6f3e8 guibg=NONE gui=bold ctermfg=NONE ctermbg=NONE cterm=NONE 81 | hi Visual guifg=NONE guibg=#262D51 gui=NONE ctermfg=NONE ctermbg=darkgray cterm=NONE 82 | 83 | hi SpecialKey guifg=#808080 guibg=#343434 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 84 | 85 | hi WildMenu guifg=green guibg=yellow gui=NONE ctermfg=black ctermbg=yellow cterm=NONE 86 | hi PmenuSbar guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=NONE 87 | "hi Ignore guifg=gray guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 88 | 89 | hi Error guifg=NONE guibg=NONE gui=undercurl ctermfg=white ctermbg=red cterm=NONE guisp=#FF6C60 " undercurl color 90 | hi ErrorMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE 91 | hi WarningMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE 92 | 93 | " Message displayed in lower left, such as --INSERT-- 94 | hi ModeMsg guifg=black guibg=#C6C5FE gui=BOLD ctermfg=black ctermbg=cyan cterm=BOLD 95 | 96 | if version >= 700 " Vim 7.x specific colors 97 | hi CursorLine guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD 98 | hi CursorColumn guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD 99 | hi MatchParen guifg=#f6f3e8 guibg=#857b6f gui=BOLD ctermfg=white ctermbg=darkgray cterm=NONE 100 | hi Pmenu guifg=#f6f3e8 guibg=#444444 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 101 | hi PmenuSel guifg=#000000 guibg=#cae682 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE 102 | hi Search guifg=NONE guibg=NONE gui=underline ctermfg=NONE ctermbg=NONE cterm=underline 103 | endif 104 | 105 | " Syntax highlighting 106 | hi Comment guifg=#7C7C7C guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE 107 | hi String guifg=#A8FF60 guibg=NONE gui=NONE ctermfg=green ctermbg=NONE cterm=NONE 108 | hi Number guifg=#FF73FD guibg=NONE gui=NONE ctermfg=magenta ctermbg=NONE cterm=NONE 109 | 110 | hi Keyword guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE 111 | hi PreProc guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE 112 | hi Conditional guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE " if else end 113 | 114 | hi Todo guifg=#8f8f8f guibg=NONE gui=NONE ctermfg=red ctermbg=NONE cterm=NONE 115 | hi Constant guifg=#99CC99 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE 116 | 117 | hi Identifier guifg=#C6C5FE guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE 118 | hi Function guifg=#FFD2A7 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE 119 | hi Type guifg=#FFFFB6 guibg=NONE gui=NONE ctermfg=yellow ctermbg=NONE cterm=NONE 120 | hi Statement guifg=#6699CC guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE 121 | 122 | hi Special guifg=#E18964 guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE 123 | hi Delimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE 124 | hi Operator guifg=white guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE 125 | 126 | hi link Character Constant 127 | hi link Boolean Constant 128 | hi link Float Number 129 | hi link Repeat Statement 130 | hi link Label Statement 131 | hi link Exception Statement 132 | hi link Include PreProc 133 | hi link Define PreProc 134 | hi link Macro PreProc 135 | hi link PreCondit PreProc 136 | hi link StorageClass Type 137 | hi link Structure Type 138 | hi link Typedef Type 139 | hi link Tag Special 140 | hi link SpecialChar Special 141 | hi link SpecialComment Special 142 | hi link Debug Special 143 | 144 | 145 | " Special for Ruby 146 | hi rubyRegexp guifg=#B18A3D guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE 147 | hi rubyRegexpDelimiter guifg=#FF8000 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE 148 | hi rubyEscape guifg=white guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE 149 | hi rubyInterpolationDelimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE 150 | hi rubyControl guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE "and break, etc 151 | "hi rubyGlobalVariable guifg=#FFCCFF guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE "yield 152 | hi rubyStringDelimiter guifg=#336633 guibg=NONE gui=NONE ctermfg=lightgreen ctermbg=NONE cterm=NONE 153 | "rubyInclude 154 | "rubySharpBang 155 | "rubyAccess 156 | "rubyPredefinedVariable 157 | "rubyBoolean 158 | "rubyClassVariable 159 | "rubyBeginEnd 160 | "rubyRepeatModifier 161 | "hi link rubyArrayDelimiter Special " [ , , ] 162 | "rubyCurlyBlock { , , } 163 | 164 | hi link rubyClass Keyword 165 | hi link rubyModule Keyword 166 | hi link rubyKeyword Keyword 167 | hi link rubyOperator Operator 168 | hi link rubyIdentifier Identifier 169 | hi link rubyInstanceVariable Identifier 170 | hi link rubyGlobalVariable Identifier 171 | hi link rubyClassVariable Identifier 172 | hi link rubyConstant Type 173 | 174 | 175 | " Special for Java 176 | " hi link javaClassDecl Type 177 | hi link javaScopeDecl Identifier 178 | hi link javaCommentTitle javaDocSeeTag 179 | hi link javaDocTags javaDocSeeTag 180 | hi link javaDocParam javaDocSeeTag 181 | hi link javaDocSeeTagParam javaDocSeeTag 182 | 183 | hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE 184 | hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE 185 | "hi javaClassDecl guifg=#CCFFCC guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE 186 | 187 | 188 | " Special for XML 189 | hi link xmlTag Keyword 190 | hi link xmlTagName Conditional 191 | hi link xmlEndTag Identifier 192 | 193 | 194 | " Special for HTML 195 | hi link htmlTag Keyword 196 | hi link htmlTagName Conditional 197 | hi link htmlEndTag Identifier 198 | 199 | 200 | " Special for Javascript 201 | hi link javaScriptNumber Number 202 | 203 | 204 | " Special for Python 205 | "hi link pythonEscape Keyword 206 | 207 | 208 | " Special for CSharp 209 | hi link csXmlTag Keyword 210 | 211 | 212 | " Special for PHP 213 | -------------------------------------------------------------------------------- /.vim/ftplugin/python/khuno.vim: -------------------------------------------------------------------------------- 1 | " File: khuno.vim 2 | " Description: A Python Flakes plugin: analyze your code on the fly 3 | " Maintainer: Alfredo Deza 4 | " License: MIT 5 | " Notes: The (current) alternatives forced you to call a function. We 6 | " can do better. This plugin is better. 7 | " 8 | "============================================================================ 9 | 10 | 11 | if exists("g:loaded_khuno") || &cp 12 | finish 13 | endif 14 | 15 | 16 | let g:loaded_khuno = 1 17 | 18 | 19 | if !exists('g:khuno_flake_cmd') 20 | let g:khuno_flake_cmd = 'flake8' 21 | endif 22 | 23 | 24 | function! s:KhunoDebugSyntax() abort 25 | let b:current_syntax = 'khunoDebug' 26 | syn match KhunoKeys "\v^(Temp file|Command|Error file)\s+" 27 | syn match KhunoTitle '\v^Khuno(.*)$' 28 | syn match KhunoDelimiter '\v(\=\=\>)' 29 | 30 | hi def link KhunoKeys String 31 | hi def link KhunoTitle String 32 | hi def link KhunoDelimiter Comment 33 | endfunction 34 | 35 | 36 | function! s:KhunoErrorSyntax() abort 37 | let b:current_syntax = 'khunoErrors' 38 | syn match KhunoDelimiter "\v\s+(\=\=\>)\s+" 39 | syn match KhunoLine "Line:" 40 | syn match KhunoColumn "\v\s+Col:\s+" 41 | 42 | hi def link KhunoDelimiter Comment 43 | hi def link KhunoLine String 44 | hi def link KhunoColumn String 45 | endfunction 46 | 47 | 48 | function! s:GoToInlineError(direction) 49 | " Goes to the current open window that matches 50 | " the error path and moves you there. Pretty awesome 51 | let text = getline('.') 52 | echo text 53 | if !len(text) 54 | return 55 | endif 56 | let line_number = matchlist(text, '\v^(Line:\s+)(\d+)')[2] 57 | let column_number = matchlist(text, '\v\s+(Col:\s+)(\d+)')[2] 58 | 59 | " Go to previous window 60 | exe 'wincmd p' 61 | execute line_number 62 | execute 'normal! zz' 63 | execute 'normal! ' . column_number . '|h' 64 | exe 'wincmd p' 65 | endfunction 66 | 67 | 68 | " au commands 69 | augroup khuno_automagic 70 | autocmd! 71 | autocmd BufEnter * if s:au_should_run() | call s:Flake() | endif 72 | autocmd BufWritePost * if s:au_should_run() | call s:Flake() | endif 73 | autocmd InsertLeave if s:au_should_run() | call s:Flake() | endif 74 | autocmd InsertLeave * if s:au_should_run() | call s:ParseReport() | endif 75 | augroup END 76 | 77 | au CursorMoved * if &ft ==# 'python' | call s:GetFlakesMessage() | endif 78 | au CursorMoved * if &ft ==# 'python' | call s:ParseReport() | endif 79 | 80 | 81 | function! s:au_should_run() abort 82 | if !exists('b:khuno_au_enabled') 83 | let b:khuno_au_enabled = 1 84 | endif 85 | if ((&ft ==# 'python') && (b:khuno_au_enabled)) 86 | return 1 87 | endif 88 | return 0 89 | endfunction 90 | 91 | 92 | function! s:KhunoAutomagic(enabled) 93 | if a:enabled 94 | augroup khuno_automagic 95 | else 96 | au! khuno_automagic 97 | endif 98 | endfunction 99 | 100 | 101 | function! s:Echo(msg, ...) 102 | redraw 103 | let x=&ruler | let y=&showcmd 104 | set noruler noshowcmd 105 | if (a:0 == 1) 106 | echo a:msg 107 | else 108 | echohl WarningMsg | echo a:msg | echohl None 109 | endif 110 | 111 | let &ruler=x | let &showcmd=y 112 | endfunction 113 | 114 | 115 | if exists('g:khuno_automagic') 116 | if (g:khuno_automagic > 0) 117 | call s:KhunoAutomagic(1) 118 | else 119 | call s:KhunoAutomagic(0) 120 | endif 121 | else 122 | call s:KhunoAutomagic(1) 123 | endif 124 | 125 | 126 | function! s:ClearAll(...) 127 | let current = winnr() 128 | let bufferL = ['Errors.khuno', 'Debug.khuno'] 129 | for b in bufferL 130 | let _window = bufwinnr(b) 131 | if (_window != -1) 132 | silent! execute _window . 'wincmd w' 133 | silent! execute 'q' 134 | endif 135 | endfor 136 | 137 | " Remove any echoed messages 138 | if (a:0 == 1) 139 | " Try going back to our starting window 140 | " and remove any left messages 141 | call s:Echo('') 142 | silent! execute 'wincmd p' 143 | else 144 | execute current . 'wincmd w' 145 | endif 146 | endfunction 147 | 148 | 149 | function! s:ToggleErrorWindow() 150 | let winnr = bufwinnr('Errors.khuno') 151 | if (winnr == -1) 152 | call s:MakeErrorWindow() 153 | else 154 | silent! execute winnr . 'wincmd w' 155 | silent! execute 'q' 156 | silent! execute 'wincmd p' 157 | endif 158 | endfunction 159 | 160 | 161 | function! s:MakeDebugWindow() abort 162 | if !exists('b:khuno_debug') 163 | call s:Echo("khuno: no debug information available.") 164 | return 165 | endif 166 | let s:debug = b:khuno_debug 167 | let s:error_file = b:khuno_error_files[-1] 168 | call s:ClearAll() 169 | let winnr = bufwinnr('Debug.khuno') 170 | silent! execute winnr < 0 ? 'botright new ' . 'Debug.khuno' : winnr . 'wincmd w' 171 | setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number filetype=khuno 172 | let error_number = 1 173 | call setline(1, "Khuno debug information:") 174 | execute 'normal o'. 'Temp file ==> ' . s:debug['temp_file'] 175 | execute 'normal o'. 'Command ==> ' . s:debug['cmd'] 176 | execute 'normal o'. 'Error file ==> ' . s:debug['temp_error'] 177 | if filereadable(s:error_file) && len(readfile(s:error_file)) 178 | execute 'normal o'. 'Errors from command show below:' 179 | for line in readfile(s:error_file) 180 | execute 'normal o' . line 181 | endfor 182 | endif 183 | if (line('$') > 10) 184 | let resize = 10 185 | else 186 | let resize = line('$') 187 | endif 188 | silent! execute 'resize ' . resize 189 | autocmd! BufEnter Debug.khuno call s:CloseIfLastWindow() 190 | nnoremap q :call ClearAll(1) 191 | nnoremap :call ClearAll(1) 192 | exe 1 193 | exe "normal! 0|h" 194 | call s:Echo("Hit q or Enter to exit", 1) 195 | call s:KhunoDebugSyntax() 196 | endfunction 197 | 198 | 199 | function! s:MakeErrorWindow() abort 200 | let modified = &modified 201 | if !exists('b:flake_errors') 202 | call s:Echo("No flake errors from a previous run") 203 | return 204 | endif 205 | call s:ClearAll() 206 | " TODO revisit this at some point, redrawing makes the terminal 207 | " flicker 208 | "au BufLeave *.khuno echo "" | redraw! 209 | if (len(b:flake_errors) == 0) 210 | call s:Echo("No flake errors from a previous run") 211 | return 212 | endif 213 | let s:flake_errors = b:flake_errors 214 | let winnr = bufwinnr('Errors.khuno') 215 | silent! execute winnr < 0 ? 'botright new ' . 'Errors.khuno' : winnr . 'wincmd w' 216 | setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number filetype=khuno 217 | let error_number = 0 218 | for line_no in keys(s:flake_errors) 219 | if line_no != "last_error_line" 220 | let errors = s:flake_errors[line_no] 221 | for err in errors 222 | let error = err["error_text"] 223 | let column = err["error_column"] 224 | let message = printf('Line: %-*u Col: %-*u ==> %s', 3, line_no, 3, column, error) 225 | let error_number = error_number + 1 226 | call setline(error_number, message) 227 | endfor 228 | endif 229 | endfor 230 | execute "sort n" 231 | if (line('$') > 10) 232 | let resize = 10 233 | else 234 | let resize = line('$') 235 | endif 236 | silent! execute 'resize ' . resize 237 | autocmd! BufEnter Errors.khuno call s:CloseIfLastWindow() 238 | nnoremap q :call ClearAll(1) 239 | nnoremap :call GoToInlineError(1) 240 | call s:KhunoErrorSyntax() 241 | exe "normal! 0|h" 242 | if modified 243 | call s:Echo("Khuno has not updated yet, errors might be out of date. Hit q to exit") 244 | else 245 | call s:Echo("Hit q to exit", 1) 246 | endif 247 | endfunction 248 | 249 | 250 | function! s:Flake() 251 | if exists("g:khuno_builtins") 252 | let s:khuno_builtins_opt=" --builtins=".g:khuno_builtins 253 | else 254 | let s:khuno_builtins_opt="" 255 | endif 256 | 257 | if exists("g:khuno_ignore") 258 | let s:khuno_ignores=" --ignore=".g:khuno_ignore 259 | else 260 | let s:khuno_ignores="" 261 | endif 262 | 263 | if exists("g:khuno_max_line_length") 264 | let s:khuno_max_line_length=" --max-line-length=".g:khuno_max_line_length 265 | else 266 | let s:khuno_max_line_length="" 267 | endif 268 | 269 | let cmd=g:khuno_flake_cmd . s:khuno_builtins_opt . s:khuno_ignores . s:khuno_max_line_length 270 | 271 | " Write to a temp path so that unmodified contents are parsed 272 | " correctly, regardless. 273 | let tmp_path = tempname() 274 | silent! execute "w " . tmp_path 275 | let cmd = cmd . " ". tmp_path 276 | call s:AsyncCmd(cmd) 277 | endfunction 278 | 279 | 280 | function! s:ParseReport() 281 | if !exists('b:khuno_called_async') 282 | return 283 | endif 284 | if (b:khuno_called_async == 0) 285 | return 286 | endif 287 | 288 | " Parse stderr first, then try stdout 289 | if s:has_invalid_syntax() 290 | let errors = s:ReadOutput(b:khuno_debug['temp_error']) 291 | else 292 | let errors = s:ReadOutput(b:khuno_debug['temp_file']) 293 | endif 294 | 295 | silent! call s:ClearFlakes() 296 | let b:flake_errors = errors 297 | if len(errors) 298 | call s:ShowErrors() 299 | endif 300 | endfunction 301 | 302 | 303 | function! s:ReadOutput(file) 304 | " Output can be a stdout file or a stderr 305 | " so we make sure we can parse any of them here 306 | " to prevent not showing anything in case we have a syntax error 307 | " that makes the checker to blow up. 308 | " typical line expected from a report: 309 | " some_file.py:107:80: E501 line too long (86 > 79 characters) 310 | let line_regex = '\v^(.*):(\d+):' 311 | let errors = {} 312 | for line in readfile(a:file) 313 | if line =~ line_regex 314 | let current_error = {} 315 | let error_line = matchlist(line, '\v:(\d+):')[1] 316 | let has_error_column = matchlist(line, '\v:(\d+):(\d+):') 317 | if (has_error_column != []) 318 | let current_error.error_column = has_error_column[2] 319 | else 320 | let current_error.error_column = 0 321 | endif 322 | let current_error.error_text = matchlist(line, '\v(\d+):\s+(.*)')[2] 323 | 324 | " Lets see if we need to append to an existing line or not 325 | if has_key(errors, error_line) 326 | call add(errors[error_line], current_error) 327 | else 328 | let errors[error_line] = [current_error] 329 | endif 330 | let errors.last_error_line = error_line 331 | endif 332 | endfor 333 | return errors 334 | endfunction 335 | 336 | 337 | function! s:has_invalid_syntax() 338 | " This will only be called from s:ParseReport, so no effort into 339 | " check all the buffer flags 340 | if !exists('b:khuno_error_files') 341 | return 0 342 | endif 343 | let err_file = b:khuno_error_files[-1] 344 | if !filereadable(err_file) 345 | return 0 346 | else 347 | for line in readfile(err_file) 348 | if line =~ '\v\s+invalid\s+syntax' 349 | return 1 350 | endif 351 | endfor 352 | return 0 353 | endif 354 | endfunction 355 | 356 | 357 | 358 | function! s:ShowErrors() abort 359 | highlight link Flakes SpellBad 360 | for line in keys(b:flake_errors) 361 | if line != "last_error_line" 362 | let err = b:flake_errors[line][0] 363 | if (err['error_column'] > 0) 364 | if err['error_text'] =~ '\v\s+(line|trailing whitespace)' 365 | let match = '\%' . line . 'l\n\@!' 366 | else 367 | let match = '^\%'. line . 'l\_.\{-}\zs\k\+\k\@!\%>' . err['error_column'] . 'c' 368 | endif 369 | call matchadd('Flakes', match) 370 | else 371 | call matchadd('Flakes', '\%' . line . 'l\n\@!') 372 | endif 373 | endif 374 | endfor 375 | let b:khuno_called_async = 0 376 | endfunction 377 | 378 | 379 | function! s:CloseIfLastWindow() 380 | if winnr("$") == 1 381 | q 382 | endif 383 | endfunction 384 | 385 | 386 | function! s:ClearFlakes() abort 387 | let s:matches = getmatches() 388 | for s:matchId in s:matches 389 | if s:matchId['group'] == 'Flakes' 390 | call matchdelete(s:matchId['id']) 391 | endif 392 | endfor 393 | let b:flake_errors = {} 394 | endfunction 395 | 396 | 397 | function! s:GetFlakesMessage() abort 398 | if !(exists('b:flake_errors')) 399 | return 400 | endif 401 | let s:cursorPos = getpos(".") 402 | let line_no = s:cursorPos[1] 403 | " if there's a message for the line the cursor is currently on, echo 404 | " it to the console 405 | if has_key(b:flake_errors, line_no) 406 | call s:Echo(b:flake_errors[line_no][0]['error_text']) 407 | else 408 | echo 409 | endif 410 | endfunction 411 | 412 | 413 | function! s:AsyncCmd(cmd) 414 | if !exists('b:khuno_error_files') 415 | let b:khuno_error_files = [] 416 | endif 417 | let s:khuno_temp_file = tempname() 418 | let s:khuno_temp_error_file = tempname() 419 | let command = "! " . a:cmd . " > " . s:khuno_temp_file . " 2> " . s:khuno_temp_error_file . " &" 420 | silent execute command 421 | let b:khuno_called_async = 1 422 | let b:khuno_debug = {} 423 | let b:khuno_debug.temp_file = s:khuno_temp_file 424 | let b:khuno_debug.temp_error = s:khuno_temp_error_file 425 | let b:khuno_debug.cmd = command 426 | call add(b:khuno_error_files, s:khuno_temp_error_file) 427 | endfunction 428 | 429 | 430 | function! s:Completion(ArgLead, CmdLine, CursorPos) 431 | let _version = "version\n" 432 | let actionables = "run\nshow\nread\ndebug\n" 433 | let toggle = "on\noff\n" 434 | return _version . actionables . toggle 435 | endfunction 436 | 437 | 438 | function! s:Version() 439 | call s:Echo("khuno.vim version 0.0.1", 1) 440 | endfunction 441 | 442 | 443 | function! s:Proxy(action) 444 | if (executable(g:khuno_flake_cmd) == 0) 445 | call s:Echo("flake8 not found. This plugin needs flake8 installed and accessible") 446 | return 447 | endif 448 | if (a:action == "version") 449 | call s:Version() 450 | elseif (a:action == "run") 451 | call s:Flake() 452 | elseif (a:action == "show") 453 | call s:ToggleErrorWindow() 454 | elseif (a:action == "read") 455 | call s:ParseReport() 456 | elseif (a:action == "debug") 457 | call s:MakeDebugWindow() 458 | elseif (a:action == "on") 459 | let b:khuno_au_enabled = 1 460 | elseif (a:action == "off") 461 | call s:ClearFlakes() 462 | let b:khuno_au_enabled = 0 463 | else 464 | call s:Echo("Khuno: not a valid file or option ==> " . a:action) 465 | endif 466 | endfunction 467 | 468 | 469 | command! -nargs=+ -complete=custom,s:Completion Khuno call s:Proxy() 470 | -------------------------------------------------------------------------------- /.vim/doc/supertab.txt: -------------------------------------------------------------------------------- 1 | *supertab.txt* 2 | 3 | Authors: 4 | Original: Gergely Kontra 5 | Current: Eric Van Dewoestine (as of version 0.4) 6 | 7 | Contributors: 8 | Christophe-Marie Duquesne (documentation) 9 | 10 | Please direct all correspondence to Eric. 11 | 12 | This plugin is licensed under the terms of the BSD License. Please see 13 | supertab.vim for the license in its entirety. 14 | 15 | ============================================================================== 16 | Supertab *supertab* 17 | 18 | 1. Introduction |supertab-intro| 19 | 2. Supertab Usage |supertab-usage| 20 | 3. Supertab Options |supertab-options| 21 | Default completion type |supertab-defaultcompletion| 22 | Secondary default completion type |supertab-contextdefault| 23 | Completion contexts |supertab-completioncontexts| 24 | Context text |supertab-contexttext| 25 | Context Discover |supertab-contextdiscover| 26 | Example |supertab-contextexample| 27 | Completion Duration |supertab-duration| 28 | Midword completion |supertab-midword| 29 | Changing default mapping |supertab-forwardbackward| 30 | Inserting true tabs |supertab-mappingtabliteral| 31 | Preselecting the first entry |supertab-longesthighlight| 32 | 33 | ============================================================================== 34 | 1. Introduction *supertab-intro* 35 | 36 | Supertab is a plugin which allows you to perform all your insert completion 37 | (|ins-completion|) using the tab key. 38 | 39 | Supertab requires Vim version 7.0 or above. 40 | 41 | ============================================================================== 42 | 2. Supertab usage *supertab-usage* 43 | 44 | Using Supertab is as easy as hitting or (shift+tab) while in 45 | insert mode, with at least one non whitespace character before the cursor, to 46 | start the completion and then or again to cycle forwards or 47 | backwards through the available completions. 48 | 49 | Example ('|' denotes the cursor location): 50 | 51 | bar 52 | baz 53 | b| Hitting here will start the completion, allowing you to 54 | then cycle through the suggested words ('bar' and 'baz'). 55 | 56 | ============================================================================== 57 | 3. Supertab Options *supertab-options* 58 | 59 | Supertab is configured via several global variables that you can set in your 60 | |vimrc| file according to your needs. Below is a comprehensive list of 61 | the variables available. 62 | 63 | g:SuperTabDefaultCompletionType |supertab-defaultcompletion| 64 | The default completion type to use. If you program in languages that support 65 | omni or user completions, it is highly recommended setting this to 66 | 'context'. 67 | 68 | For help about built in completion types in vim, see |i_CTRL-X_index|. 69 | 70 | g:SuperTabContextDefaultCompletionType |supertab-contextdefault| 71 | The default completion type to use when 'context' is the global default, but 72 | context completion has determined that neither omni, user, or file 73 | completion should be used in the current context. 74 | 75 | g:SuperTabCompletionContexts |supertab-completioncontexts| 76 | Used to configure a list of function names which are used when the global 77 | default type is 'context'. These functions will be consulted in order to 78 | determine which completion type to use. Advanced users can plug in their own 79 | functions here to customize their 'context' completion. 80 | 81 | g:SuperTabRetainCompletionDuration |supertab-duration| 82 | This setting determines how long a non-default completion type should be 83 | retained as the temporary default. By default supertab will retain the 84 | alternate completion type until you leave insert mode. 85 | 86 | g:SuperTabMidWordCompletion |supertab-midword| 87 | This can be used to turn off completion if you are in the middle of a word 88 | (word characters immediately preceding and following the cursor). 89 | 90 | g:SuperTabMappingForward |supertab-forwardbackward| 91 | g:SuperTabMappingBackward |supertab-forwardbackward| 92 | If using the tab key for completion isn't for you, then you can use these to 93 | set an alternate key to be used for your insert completion needs. 94 | 95 | g:SuperTabMappingTabLiteral |supertab-mappingtabliteral| 96 | For those rare cases where supertab would normal want to start insert 97 | completion, but you just want to insert a tab, this setting is used to 98 | define the key combination to use to do just that. By default Ctrl-Tab is 99 | used. 100 | 101 | g:SuperTabLongestHighlight |supertab-longesthighlight| 102 | When enabled and you have the completion popup enable and 'longest' in your 103 | completeopt, supertab will auto highlight the first selection in the popup. 104 | 105 | 106 | Default Completion Type *supertab-defaultcompletion* 107 | *g:SuperTabDefaultCompletionType* 108 | 109 | g:SuperTabDefaultCompletionType (default value: "") 110 | 111 | Used to set the default completion type. There is no need to escape this 112 | value as that will be done for you when the type is set. 113 | 114 | Example: setting the default completion to 'user' completion: 115 | 116 | let g:SuperTabDefaultCompletionType = "" 117 | 118 | Note: a special value of 'context' is supported which will result in 119 | super tab attempting to use the text preceding the cursor to decide which 120 | type of completion to attempt. Currently super tab can recognize method 121 | calls or attribute references via '.', '::' or '->', and file path 122 | references containing '/'. 123 | 124 | let g:SuperTabDefaultCompletionType = "context" 125 | 126 | /usr/l # will use filename completion 127 | myvar.t # will use user completion if completefunc set, 128 | # or omni completion if omnifunc set. 129 | myvar-> # same as above 130 | 131 | When using context completion, super tab will fall back to a secondary default 132 | completion type set by |g:SuperTabContextDefaultCompletionType|. 133 | 134 | Note: once the buffer has been initialized, changing the value of this setting 135 | will not change the default complete type used. If you want to change the 136 | default completion type for the current buffer after it has been set, perhaps 137 | in an ftplugin, you'll need to call SuperTabSetDefaultCompletionType like so, 138 | supplying the completion type you wish to switch to: 139 | 140 | call SuperTabSetDefaultCompletionType("") 141 | 142 | 143 | Secondary default completion type *supertab-contextdefault* 144 | *g:SuperTabContextDefaultCompletionType* 145 | 146 | g:SuperTabContextDefaultCompletionType (default value: "") 147 | 148 | Sets the default completion type used when g:SuperTabDefaultCompletionType is 149 | set to 'context' and no completion type is returned by any of the configured 150 | contexts. 151 | 152 | 153 | Completion contexts *supertab-completioncontexts* 154 | *g:SuperTabCompletionContexts* 155 | 156 | g:SuperTabCompletionContexts (default value: ['s:ContextText']) 157 | 158 | Sets the list of contexts used for context completion. This value should 159 | be a list of function names which provide the context implementation. 160 | 161 | When supertab starts the default completion, each of these contexts will be 162 | consulted, in the order they were supplied, to determine the completion type 163 | to use. If a context returns a completion type, that type will be used, 164 | otherwise the next context in the list will be consulted. If after executing 165 | all the context functions, no completion type has been determined, then the 166 | value of g:SuperTabContextDefaultCompletionType will be used. 167 | 168 | Built in completion contexts: 169 | 170 | s:ContextText *supertab-contexttext* 171 | 172 | The text context will examine the text near the cursor to decide which type 173 | of completion to attempt. Currently the text context can recognize method 174 | calls or attribute references via '.', '::' or '->', and file path 175 | references containing '/'. 176 | 177 | /usr/l # will use filename completion 178 | myvar.t # will use user completion if completefunc set, or 179 | # omni completion if omnifunc set. 180 | myvar-> # same as above 181 | 182 | Supported configuration attributes: 183 | 184 | g:SuperTabContextTextFileTypeExclusions 185 | List of file types for which the text context will be skipped. 186 | 187 | g:SuperTabContextTextOmniPrecedence 188 | List of omni completion option names in the order of precedence that they 189 | should be used if available. By default, user completion will be given 190 | precedence over omni completion, but you can use this variable to give 191 | omni completion higher precedence by placing it first in the list. 192 | 193 | s:ContextDiscover *supertab-contextdiscover* 194 | 195 | This context will use the 'g:SuperTabContextDiscoverDiscovery' variable to 196 | determine the completion type to use. It will evaluate each value, in the 197 | order they were defined, until a variable evaluates to a non-zero or 198 | non-empty value, then the associated completion type is used. 199 | 200 | Supported configuration properties: 201 | 202 | g:SuperTabContextDiscoverDiscovery 203 | List of variable:completionType mappings. 204 | 205 | Example context configuration: *supertab-contextexample* 206 | 207 | let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover'] 208 | let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc'] 209 | let g:SuperTabContextDiscoverDiscovery = 210 | \ ["&completefunc:", "&omnifunc:"] 211 | 212 | In addition to the default completion contexts, you can plug in your own 213 | implementation by creating a globally accessible function that returns 214 | the completion type to use (eg. "\\"). 215 | 216 | function MyTagContext() 217 | if filereadable(expand('%:p:h') . '/tags') 218 | return "\\" 219 | endif 220 | " no return will result in the evaluation of the next 221 | " configured context 222 | endfunction 223 | let g:SuperTabCompletionContexts = 224 | \ ['MyTagContext', 's:ContextText', 's:ContextDiscover'] 225 | 226 | Note: supertab also supports the b:SuperTabCompletionContexts variable 227 | allowing you to set the list of contexts separately for the current buffer, 228 | like from an ftplugin for example. 229 | 230 | 231 | Completion Duration *supertab-duration* 232 | *g:SuperTabRetainCompletionDuration* 233 | 234 | g:SuperTabRetainCompletionDuration (default value: 'insert') 235 | 236 | Determines if, and for how long, the current completion type is retained. 237 | The possible values include: 238 | 'completion' - The current completion type is only retained for the 239 | current completion. Once you have chosen a completion 240 | result or exited the completion mode, the default 241 | completion type is restored. 242 | 'insert' - The current completion type is saved until you exit insert 243 | mode (via ESC). Once you exit insert mode the default 244 | completion type is restored. (supertab default) 245 | 'session' - The current completion type is saved for the duration of 246 | your vim session or until you enter a different completion 247 | mode. 248 | 249 | 250 | Midword completion *supertab-midword* 251 | *g:SuperTabMidWordCompletion* 252 | 253 | g:SuperTabMidWordCompletion (default value: 1) 254 | 255 | Sets whether or not mid word completion is enabled. When enabled, will 256 | kick off completion when ever a non whitespace character is to the left of the 257 | cursor. When disabled, completion will only occur if the char to the left is 258 | non whitespace char and the char to the right is not a keyword character (you 259 | are at the end of the word). 260 | 261 | 262 | Changing the default mapping *supertab-forwardbackward* 263 | *g:SuperTabMappingForward* 264 | *g:SuperTabMappingBackward* 265 | 266 | g:SuperTabMappingForward (default value: '') 267 | g:SuperTabMappingBackward (default value: '') 268 | 269 | These two variables allow you to set the keys used to kick off the current 270 | completion. By default this is and . To change to something 271 | like and , you can add the following to your |vimrc|. 272 | 273 | let g:SuperTabMappingForward = '' 274 | let g:SuperTabMappingBackward = '' 275 | 276 | Note: if the above does not have the desired effect (which may happen in 277 | console version of vim), you can try the following mappings. Although the 278 | backwards mapping still doesn't seem to work in the console for me, your 279 | milage may vary. 280 | 281 | let g:SuperTabMappingForward = '' 282 | let g:SuperTabMappingBackward = '' 283 | 284 | 285 | Inserting true tabs *supertab-mappingtabliteral* 286 | *g:SuperTabMappingTabLiteral* 287 | 288 | g:SuperTabMappingTabLiteral (default value: '') 289 | 290 | Sets the key mapping used to insert a literal tab where supertab would 291 | otherwise attempt to kick off insert completion. The default is '' 292 | (ctrl-tab) which unfortunately might not work at the console. So if you are 293 | using a console vim and want this functionality, you may have to change it to 294 | something that is supported. Alternatively, you can escape the with 295 | (see |i_CTRL-V| for more infos). 296 | 297 | 298 | Preselecting the first entry *supertab-longesthighlight* 299 | *g:SuperTabLongestHighlight* 300 | 301 | g:SuperTabLongestHighlight (default value: 0) 302 | 303 | Sets whether or not to pre-highlight the first match when completeopt has the 304 | popup menu enabled and the 'longest' option as well. When enabled, will 305 | kick off completion and pre-select the first entry in the popup menu, allowing 306 | you to simply hit to use it. 307 | 308 | vim:tw=78:ts=8:ft=help:norl: 309 | -------------------------------------------------------------------------------- /.vim/syntax/python.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Python 3 | " Maintainer: Dmitry Vasiliev 4 | " URL: http://www.hlabs.spb.ru/vim/python.vim 5 | " Last Change: 2009-07-24 6 | " Filenames: *.py 7 | " Version: 2.6.5 8 | " 9 | " Based on python.vim (from Vim 6.1 distribution) 10 | " by Neil Schemenauer 11 | " 12 | " Thanks: 13 | " 14 | " Jeroen Ruigrok van der Werven 15 | " for the idea to highlight erroneous operators 16 | " Pedro Algarvio 17 | " for the patch to enable spell checking only for the right spots 18 | " (strings and comments) 19 | " John Eikenberry 20 | " for the patch fixing small typo 21 | " Caleb Adamantine 22 | " for the patch fixing highlighting for decorators 23 | 24 | " 25 | " Options: 26 | " 27 | " For set option do: let OPTION_NAME = 1 28 | " For clear option do: let OPTION_NAME = 0 29 | " 30 | " Option names: 31 | " 32 | " For highlight builtin functions: 33 | " python_highlight_builtins 34 | " 35 | " For highlight standard exceptions: 36 | " python_highlight_exceptions 37 | " 38 | " For highlight string formatting: 39 | " python_highlight_string_formatting 40 | " 41 | " For highlight str.format syntax: 42 | " python_highlight_string_format 43 | " 44 | " For highlight string.Template syntax: 45 | " python_highlight_string_templates 46 | " 47 | " For highlight indentation errors: 48 | " python_highlight_indent_errors 49 | " 50 | " For highlight trailing spaces: 51 | " python_highlight_space_errors 52 | " 53 | " For highlight doc-tests: 54 | " python_highlight_doctests 55 | " 56 | " If you want all Python highlightings above: 57 | " python_highlight_all 58 | " (This option not override previously set options) 59 | " 60 | " For fast machines: 61 | " python_slow_sync 62 | " 63 | " For "print" builtin as function: 64 | " python_print_as_function 65 | 66 | " For version 5.x: Clear all syntax items 67 | " For version 6.x: Quit when a syntax file was already loaded 68 | if version < 600 69 | syntax clear 70 | elseif exists("b:current_syntax") 71 | finish 72 | endif 73 | 74 | if exists("python_highlight_all") && python_highlight_all != 0 75 | " Not override previously set options 76 | if !exists("python_highlight_builtins") 77 | let python_highlight_builtins = 1 78 | endif 79 | if !exists("python_highlight_exceptions") 80 | let python_highlight_exceptions = 1 81 | endif 82 | if !exists("python_highlight_string_formatting") 83 | let python_highlight_string_formatting = 1 84 | endif 85 | if !exists("python_highlight_string_format") 86 | let python_highlight_string_format = 1 87 | endif 88 | if !exists("python_highlight_string_templates") 89 | let python_highlight_string_templates = 1 90 | endif 91 | if !exists("python_highlight_indent_errors") 92 | let python_highlight_indent_errors = 1 93 | endif 94 | if !exists("python_highlight_space_errors") 95 | let python_highlight_space_errors = 1 96 | endif 97 | if !exists("python_highlight_doctests") 98 | let python_highlight_doctests = 1 99 | endif 100 | endif 101 | 102 | " Keywords 103 | syn keyword pythonStatement break continue del 104 | syn keyword pythonStatement exec return 105 | syn keyword pythonStatement pass raise 106 | syn keyword pythonStatement global assert 107 | syn keyword pythonStatement lambda yield 108 | syn keyword pythonStatement with 109 | syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite 110 | syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained 111 | syn keyword pythonRepeat for while 112 | syn keyword pythonConditional if elif else 113 | syn keyword pythonPreCondit import from as 114 | syn keyword pythonException try except finally 115 | syn keyword pythonOperator and in is not or 116 | 117 | if !exists("python_print_as_function") || python_print_as_function == 0 118 | syn keyword pythonStatement print 119 | endif 120 | 121 | " Decorators (new in Python 2.4) 122 | syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite 123 | syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained 124 | syn match pythonDot "\." display containedin=pythonDottedName 125 | 126 | " Comments 127 | syn match pythonComment "#.*$" display contains=pythonTodo,@Spell 128 | syn match pythonRun "\%^#!.*$" 129 | syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$" 130 | syn keyword pythonTodo TODO FIXME XXX contained 131 | 132 | " Errors 133 | syn match pythonError "\<\d\+\D\+\>" display 134 | syn match pythonError "[$?]" display 135 | syn match pythonError "[&|]\{2,}" display 136 | syn match pythonError "[=]\{3,}" display 137 | 138 | " TODO: Mixing spaces and tabs also may be used for pretty formatting multiline 139 | " statements. For now I don't know how to work around this. 140 | if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0 141 | syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display 142 | endif 143 | 144 | " Trailing space errors 145 | if exists("python_highlight_space_errors") && python_highlight_space_errors != 0 146 | syn match pythonSpaceError "\s\+$" display 147 | endif 148 | 149 | " Strings 150 | syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell 151 | syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell 152 | syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell 153 | syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell 154 | 155 | syn match pythonEscape +\\[abfnrtv'"\\]+ display contained 156 | syn match pythonEscape "\\\o\o\=\o\=" display contained 157 | syn match pythonEscapeError "\\\o\{,2}[89]" display contained 158 | syn match pythonEscape "\\x\x\{2}" display contained 159 | syn match pythonEscapeError "\\x\x\=\X" display contained 160 | syn match pythonEscape "\\$" 161 | 162 | " Unicode strings 163 | syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell 164 | syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell 165 | syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell 166 | syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell 167 | 168 | syn match pythonUniEscape "\\u\x\{4}" display contained 169 | syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained 170 | syn match pythonUniEscape "\\U\x\{8}" display contained 171 | syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained 172 | syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained 173 | syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained 174 | 175 | " Raw strings 176 | syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell 177 | syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell 178 | syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell 179 | syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell 180 | 181 | syn match pythonRawEscape +\\['"]+ display transparent contained 182 | 183 | " Unicode raw strings 184 | syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell 185 | syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell 186 | syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell 187 | syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell 188 | 189 | syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained 190 | syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained 191 | 192 | if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0 193 | " String formatting 194 | syn match pythonStrFormatting "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 195 | syn match pythonStrFormatting "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 196 | endif 197 | 198 | if exists("python_highlight_string_format") && python_highlight_string_format != 0 199 | " str.format syntax 200 | syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 201 | syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 202 | endif 203 | 204 | if exists("python_highlight_string_templates") && python_highlight_string_templates != 0 205 | " String templates 206 | syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 207 | syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 208 | syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString 209 | endif 210 | 211 | if exists("python_highlight_doctests") && python_highlight_doctests != 0 212 | " DocTests 213 | syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained 214 | syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained 215 | endif 216 | 217 | " Numbers (ints, longs, floats, complex) 218 | syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*[lL]\=\>" display 219 | 220 | syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display 221 | syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display 222 | syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display 223 | 224 | syn match pythonNumber "\<\d\+[lLjJ]\=\>" display 225 | 226 | syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display 227 | syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display 228 | syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display 229 | 230 | syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display 231 | syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display 232 | 233 | if exists("python_highlight_builtins") && python_highlight_builtins != 0 234 | " Builtin functions, types and objects 235 | syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented 236 | syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ 237 | 238 | syn keyword pythonBuiltinFunc __import__ abs all any apply 239 | syn keyword pythonBuiltinFunc basestring bin bool buffer bytearray bytes callable 240 | syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex 241 | syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval 242 | syn keyword pythonBuiltinFunc execfile file filter float format frozenset getattr 243 | syn keyword pythonBuiltinFunc globals hasattr hash help hex id 244 | syn keyword pythonBuiltinFunc input int intern isinstance 245 | syn keyword pythonBuiltinFunc issubclass iter len list locals long map max 246 | syn keyword pythonBuiltinFunc min next object oct open ord 247 | syn keyword pythonBuiltinFunc pow property range 248 | syn keyword pythonBuiltinFunc raw_input reduce reload repr 249 | syn keyword pythonBuiltinFunc reversed round set setattr 250 | syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple 251 | syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip 252 | 253 | if exists("python_print_as_function") && python_print_as_function != 0 254 | syn keyword pythonBuiltinFunc print 255 | endif 256 | endif 257 | 258 | if exists("python_highlight_exceptions") && python_highlight_exceptions != 0 259 | " Builtin exceptions and warnings 260 | syn keyword pythonExClass BaseException 261 | syn keyword pythonExClass Exception StandardError ArithmeticError 262 | syn keyword pythonExClass LookupError EnvironmentError 263 | 264 | syn keyword pythonExClass AssertionError AttributeError BufferError EOFError 265 | syn keyword pythonExClass FloatingPointError GeneratorExit IOError 266 | syn keyword pythonExClass ImportError IndexError KeyError 267 | syn keyword pythonExClass KeyboardInterrupt MemoryError NameError 268 | syn keyword pythonExClass NotImplementedError OSError OverflowError 269 | syn keyword pythonExClass ReferenceError RuntimeError StopIteration 270 | syn keyword pythonExClass SyntaxError IndentationError TabError 271 | syn keyword pythonExClass SystemError SystemExit TypeError 272 | syn keyword pythonExClass UnboundLocalError UnicodeError 273 | syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError 274 | syn keyword pythonExClass UnicodeTranslateError ValueError VMSError 275 | syn keyword pythonExClass WindowsError ZeroDivisionError 276 | 277 | syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning 278 | syn keyword pythonExClass PendingDepricationWarning SyntaxWarning 279 | syn keyword pythonExClass RuntimeWarning FutureWarning 280 | syn keyword pythonExClass ImportWarning UnicodeWarning 281 | endif 282 | 283 | if exists("python_slow_sync") && python_slow_sync != 0 284 | syn sync minlines=2000 285 | else 286 | " This is fast but code inside triple quoted strings screws it up. It 287 | " is impossible to fix because the only way to know if you are inside a 288 | " triple quoted string is to start from the beginning of the file. 289 | syn sync match pythonSync grouphere NONE "):$" 290 | syn sync maxlines=200 291 | endif 292 | 293 | if version >= 508 || !exists("did_python_syn_inits") 294 | if version <= 508 295 | let did_python_syn_inits = 1 296 | command -nargs=+ HiLink hi link 297 | else 298 | command -nargs=+ HiLink hi def link 299 | endif 300 | 301 | HiLink pythonStatement Statement 302 | HiLink pythonPreCondit Statement 303 | HiLink pythonFunction Function 304 | HiLink pythonConditional Conditional 305 | HiLink pythonRepeat Repeat 306 | HiLink pythonException Exception 307 | HiLink pythonOperator Operator 308 | 309 | HiLink pythonDecorator Define 310 | HiLink pythonDottedName Function 311 | HiLink pythonDot Normal 312 | 313 | HiLink pythonComment Comment 314 | HiLink pythonCoding Special 315 | HiLink pythonRun Special 316 | HiLink pythonTodo Todo 317 | 318 | HiLink pythonError Error 319 | HiLink pythonIndentError Error 320 | HiLink pythonSpaceError Error 321 | 322 | HiLink pythonString String 323 | HiLink pythonUniString String 324 | HiLink pythonRawString String 325 | HiLink pythonUniRawString String 326 | 327 | HiLink pythonEscape Special 328 | HiLink pythonEscapeError Error 329 | HiLink pythonUniEscape Special 330 | HiLink pythonUniEscapeError Error 331 | HiLink pythonUniRawEscape Special 332 | HiLink pythonUniRawEscapeError Error 333 | 334 | HiLink pythonStrFormatting Special 335 | HiLink pythonStrFormat Special 336 | HiLink pythonStrTemplate Special 337 | 338 | HiLink pythonDocTest Special 339 | HiLink pythonDocTest2 Special 340 | 341 | HiLink pythonNumber Number 342 | HiLink pythonHexNumber Number 343 | HiLink pythonOctNumber Number 344 | HiLink pythonBinNumber Number 345 | HiLink pythonFloat Float 346 | HiLink pythonOctError Error 347 | HiLink pythonHexError Error 348 | HiLink pythonBinError Error 349 | 350 | HiLink pythonBuiltinObj Structure 351 | HiLink pythonBuiltinFunc Function 352 | 353 | HiLink pythonExClass Structure 354 | 355 | delcommand HiLink 356 | endif 357 | 358 | let b:current_syntax = "python" 359 | -------------------------------------------------------------------------------- /.vim/plugin/supertab.vim: -------------------------------------------------------------------------------- 1 | " Author: 2 | " Original: Gergely Kontra 3 | " Current: Eric Van Dewoestine (as of version 0.4) 4 | " Please direct all correspondence to Eric. 5 | " Version: 1.0 6 | " GetLatestVimScripts: 1643 1 :AutoInstall: supertab.vim 7 | " 8 | " Description: {{{ 9 | " Use your tab key to do all your completion in insert mode! 10 | " You can cycle forward and backward with the and keys 11 | " Note: you must press once to be able to cycle back 12 | " 13 | " http://www.vim.org/scripts/script.php?script_id=1643 14 | " }}} 15 | " 16 | " License: {{{ 17 | " Software License Agreement (BSD License) 18 | " 19 | " Copyright (c) 2002 - 2009 20 | " All rights reserved. 21 | " 22 | " Redistribution and use of this software in source and binary forms, with 23 | " or without modification, are permitted provided that the following 24 | " conditions are met: 25 | " 26 | " * Redistributions of source code must retain the above 27 | " copyright notice, this list of conditions and the 28 | " following disclaimer. 29 | " 30 | " * Redistributions in binary form must reproduce the above 31 | " copyright notice, this list of conditions and the 32 | " following disclaimer in the documentation and/or other 33 | " materials provided with the distribution. 34 | " 35 | " * Neither the name of Gergely Kontra or Eric Van Dewoestine nor the names 36 | " of its contributors may be used to endorse or promote products derived 37 | " from this software without specific prior written permission of Gergely 38 | " Kontra or Eric Van Dewoestine. 39 | " 40 | " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 41 | " IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 42 | " THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43 | " PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 44 | " CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 45 | " EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 46 | " PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 47 | " PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 48 | " LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 49 | " NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 50 | " SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | " }}} 52 | " 53 | " Testing Info: {{{ 54 | " Running vim + supertab with the absolute bar minimum settings: 55 | " $ vim -u NONE -U NONE -c "set nocp | runtime plugin/supertab.vim" 56 | " }}} 57 | 58 | if v:version < 700 59 | finish 60 | endif 61 | 62 | if exists('complType') " Integration with other completion functions. 63 | finish 64 | endif 65 | 66 | let s:save_cpo=&cpo 67 | set cpo&vim 68 | 69 | " Global Variables {{{ 70 | 71 | if !exists("g:SuperTabDefaultCompletionType") 72 | let g:SuperTabDefaultCompletionType = "context" 73 | endif 74 | 75 | if !exists("g:SuperTabContextDefaultCompletionType") 76 | let g:SuperTabContextDefaultCompletionType = "" 77 | endif 78 | 79 | if !exists("g:SuperTabCompletionContexts") 80 | let g:SuperTabCompletionContexts = ['s:ContextText'] 81 | endif 82 | 83 | if !exists("g:SuperTabRetainCompletionDuration") 84 | let g:SuperTabRetainCompletionDuration = 'completion' 85 | endif 86 | 87 | if !exists("g:SuperTabMidWordCompletion") 88 | let g:SuperTabMidWordCompletion = 1 89 | endif 90 | 91 | if !exists("g:SuperTabMappingForward") 92 | let g:SuperTabMappingForward = '' 93 | endif 94 | if !exists("g:SuperTabMappingBackward") 95 | let g:SuperTabMappingBackward = '' 96 | endif 97 | 98 | if !exists("g:SuperTabMappingTabLiteral") 99 | let g:SuperTabMappingTabLiteral = '' 100 | endif 101 | 102 | if !exists("g:SuperTabLongestHighlight") 103 | let g:SuperTabLongestHighlight = 0 104 | endif 105 | 106 | " }}} 107 | 108 | " Script Variables {{{ 109 | 110 | " construct the help text. 111 | let s:tabHelp = 112 | \ "Hit or CTRL-] on the completion type you wish to switch to.\n" . 113 | \ "Use :help ins-completion for more information.\n" . 114 | \ "\n" . 115 | \ "|| - Keywords in 'complete' searching down.\n" . 116 | \ "|| - Keywords in 'complete' searching up (SuperTab default).\n" . 117 | \ "|| - Whole lines.\n" . 118 | \ "|| - Keywords in current file.\n" . 119 | \ "|| - Keywords in 'dictionary'.\n" . 120 | \ "|| - Keywords in 'thesaurus', thesaurus-style.\n" . 121 | \ "|| - Keywords in the current and included files.\n" . 122 | \ "|| - Tags.\n" . 123 | \ "|| - File names.\n" . 124 | \ "|| - Definitions or macros.\n" . 125 | \ "|| - Vim command-line.\n" . 126 | \ "|| - User defined completion.\n" . 127 | \ "|| - Omni completion.\n" . 128 | \ "|s| - Spelling suggestions." 129 | 130 | " set the available completion types and modes. 131 | let s:types = 132 | \ "\\\\\\\\" . 133 | \ "\\\\\\\\\s" 134 | let s:modes = '/^E/^Y/^L/^N/^K/^T/^I/^]/^F/^D/^V/^P/^U/^O/s' 135 | let s:types = s:types . "np" 136 | let s:modes = s:modes . '/n/p' 137 | 138 | " }}} 139 | 140 | " SuperTabSetDefaultCompletionType(type) {{{ 141 | " Globally available function that users can use to set the default 142 | " completion type for the current buffer, like in an ftplugin. 143 | function! SuperTabSetDefaultCompletionType(type) 144 | " init hack for workaround. 145 | let b:complCommandLine = 0 146 | 147 | let b:SuperTabDefaultCompletionType = a:type 148 | 149 | " set the current completion type to the default 150 | call SuperTabSetCompletionType(b:SuperTabDefaultCompletionType) 151 | endfunction " }}} 152 | 153 | " SuperTabSetCompletionType(type) {{{ 154 | " Globally available function that users can use to create mappings to quickly 155 | " switch completion modes. Useful when a user wants to restore the default or 156 | " switch to another mode without having to kick off a completion of that type 157 | " or use SuperTabHelp. Note, this function only changes the current 158 | " completion type, not the default, meaning that the default will still be 159 | " restored once the configured retension duration has been met (see 160 | " g:SuperTabRetainCompletionDuration). To change the default for the current 161 | " buffer, use SuperTabDefaultCompletionType(type) instead. Example mapping to 162 | " restore SuperTab default: 163 | " nmap :call SetSuperTabCompletionType("") 164 | function! SuperTabSetCompletionType(type) 165 | exec "let b:complType = \"" . escape(a:type, '<') . "\"" 166 | endfunction " }}} 167 | 168 | " SuperTabAlternateCompletion(type) {{{ 169 | " Function which can be mapped to a key to kick off an alternate completion 170 | " other than the default. For instance, if you have 'context' as the default 171 | " and want to map ctrl+space to issue keyword completion. 172 | " Note: due to the way vim expands ctrl characters in mappings, you cannot 173 | " create the alternate mapping like so: 174 | " imap =SuperTabAlternateCompletion("") 175 | " instead, you have to use \ to prevent vim from expanding the key 176 | " when creating the mapping. 177 | " gvim: 178 | " imap =SuperTabAlternateCompletion("\c-p>") 179 | " console: 180 | " imap =SuperTabAlternateCompletion("\c-p>") 181 | function! SuperTabAlternateCompletion(type) 182 | call SuperTabSetCompletionType(a:type) 183 | " end any current completion before attempting to start the new one. 184 | " use feedkeys to prevent possible remapping of from causing issues. 185 | "call feedkeys("\", 'n') 186 | " ^ since we can't detect completion mode vs regular insert mode, we force 187 | " vim into keyword completion mode and end that mode to prevent the regular 188 | " insert behavior of from occurring. 189 | call feedkeys("\\\", 'n') 190 | call feedkeys(b:complType) 191 | return '' 192 | endfunction " }}} 193 | 194 | " s:Init {{{ 195 | " Global initilization when supertab is loaded. 196 | function! s:Init() 197 | augroup supertab_init 198 | autocmd! 199 | autocmd BufEnter * call InitBuffer() 200 | augroup END 201 | 202 | " ensure InitBuffer gets called for the first buffer, after the ftplugins 203 | " have been called. 204 | augroup supertab_init_first 205 | autocmd! 206 | autocmd FileType call InitBuffer() 207 | augroup END 208 | 209 | " Setup mechanism to restore orignial completion type upon leaving insert 210 | " mode if configured to do so 211 | if g:SuperTabRetainCompletionDuration == 'insert' 212 | augroup supertab_retain 213 | autocmd! 214 | autocmd InsertLeave * call s:SetDefaultCompletionType() 215 | augroup END 216 | endif 217 | endfunction " }}} 218 | 219 | " s:InitBuffer {{{ 220 | " Per buffer initilization. 221 | function! s:InitBuffer() 222 | if exists("b:complType") 223 | return 224 | endif 225 | 226 | " init hack for workaround. 227 | let b:complCommandLine = 0 228 | 229 | let b:SuperTabDefaultCompletionType = g:SuperTabDefaultCompletionType 230 | 231 | " set the current completion type to the default 232 | call SuperTabSetCompletionType(b:SuperTabDefaultCompletionType) 233 | endfunction " }}} 234 | 235 | " s:ManualCompletionEnter() {{{ 236 | " Handles manual entrance into completion mode. 237 | function! s:ManualCompletionEnter() 238 | if &smd 239 | echo '' | echohl ModeMsg | echo '-- ^X++ mode (' . s:modes . ')' | echohl None 240 | endif 241 | let complType = nr2char(getchar()) 242 | if stridx(s:types, complType) != -1 243 | if stridx("\\", complType) != -1 " no memory, just scroll... 244 | return "\" . complType 245 | elseif stridx('np', complType) != -1 246 | let complType = nr2char(char2nr(complType) - 96) 247 | else 248 | let complType = "\" . complType 249 | endif 250 | 251 | if index(['insert', 'session'], g:SuperTabRetainCompletionDuration) != -1 252 | let b:complType = complType 253 | endif 254 | 255 | " Hack to workaround bug when invoking command line completion via = 256 | if complType == "\\" 257 | return s:CommandLineCompletion() 258 | endif 259 | 260 | return complType 261 | endif 262 | 263 | echohl "Unknown mode" 264 | return complType 265 | endfunction " }}} 266 | 267 | " s:SetCompletionType() {{{ 268 | " Sets the completion type based on what the user has chosen from the help 269 | " buffer. 270 | function! s:SetCompletionType() 271 | let chosen = substitute(getline('.'), '.*|\(.*\)|.*', '\1', '') 272 | if chosen != getline('.') 273 | let winnr = b:winnr 274 | close 275 | exec winnr . 'winc w' 276 | call SuperTabSetCompletionType(chosen) 277 | endif 278 | endfunction " }}} 279 | 280 | " s:SetDefaultCompletionType() {{{ 281 | function! s:SetDefaultCompletionType() 282 | if exists('b:SuperTabDefaultCompletionType') && 283 | \ (!exists('b:complCommandLine') || !b:complCommandLine) 284 | call SuperTabSetCompletionType(b:SuperTabDefaultCompletionType) 285 | endif 286 | endfunction " }}} 287 | 288 | " s:SuperTab(command) {{{ 289 | " Used to perform proper cycle navigation as the user requests the next or 290 | " previous entry in a completion list, and determines whether or not to simply 291 | " retain the normal usage of based on the cursor position. 292 | function! s:SuperTab(command) 293 | if s:WillComplete() 294 | " rare case where no autocmds have fired for this buffer to initialize the 295 | " supertab vars. 296 | call s:InitBuffer() 297 | 298 | let key = '' 299 | " highlight first result if longest enabled 300 | if g:SuperTabLongestHighlight && !pumvisible() && &completeopt =~ 'longest' 301 | let key = (b:complType == "\") ? "\" : "\" 302 | endif 303 | 304 | " exception: if in mode, then should move up the list, and 305 | " down the list. 306 | if a:command == 'p' && 307 | \ (b:complType == "\" || 308 | \ (b:complType == 'context' && 309 | \ tolower(g:SuperTabContextDefaultCompletionType) == '')) 310 | return "\" 311 | elseif a:command == 'p' && 312 | \ (b:complType == "\" || 313 | \ (b:complType == 'context' && 314 | \ tolower(g:SuperTabContextDefaultCompletionType) == '')) 315 | return "\" 316 | endif 317 | 318 | " handle 'context' completion. 319 | if b:complType == 'context' 320 | let complType = s:ContextCompletion() 321 | if complType == '' 322 | exec "let complType = \"" . 323 | \ escape(g:SuperTabContextDefaultCompletionType, '<') . "\"" 324 | endif 325 | return complType . key 326 | endif 327 | 328 | " Hack to workaround bug when invoking command line completion via = 329 | if b:complType == "\\" 330 | return s:CommandLineCompletion() 331 | endif 332 | return b:complType . key 333 | endif 334 | 335 | return "\" 336 | endfunction " }}} 337 | 338 | " s:SuperTabHelp() {{{ 339 | " Opens a help window where the user can choose a completion type to enter. 340 | function! s:SuperTabHelp() 341 | let winnr = winnr() 342 | if bufwinnr("SuperTabHelp") == -1 343 | botright split SuperTabHelp 344 | 345 | setlocal noswapfile 346 | setlocal buftype=nowrite 347 | setlocal bufhidden=delete 348 | 349 | let saved = @" 350 | let @" = s:tabHelp 351 | silent put 352 | call cursor(1, 1) 353 | silent 1,delete 354 | call cursor(4, 1) 355 | let @" = saved 356 | exec "resize " . line('$') 357 | 358 | syntax match Special "|.\{-}|" 359 | 360 | setlocal readonly 361 | setlocal nomodifiable 362 | 363 | nmap :call SetCompletionType() 364 | nmap :call SetCompletionType() 365 | else 366 | exec bufwinnr("SuperTabHelp") . "winc w" 367 | endif 368 | let b:winnr = winnr 369 | endfunction " }}} 370 | 371 | " s:WillComplete() {{{ 372 | " Determines if completion should be kicked off at the current location. 373 | function! s:WillComplete() 374 | let line = getline('.') 375 | let cnum = col('.') 376 | 377 | " Start of line. 378 | let prev_char = strpart(line, cnum - 2, 1) 379 | if prev_char =~ '^\s*$' 380 | return 0 381 | endif 382 | 383 | " Within a word, but user does not have mid word completion enabled. 384 | let next_char = strpart(line, cnum - 1, 1) 385 | if !g:SuperTabMidWordCompletion && next_char =~ '\k' 386 | return 0 387 | endif 388 | 389 | " In keyword completion mode and no preceding word characters. 390 | "if (b:complType == "\" || b:complType == "\") && prev_char !~ '\k' 391 | " return 0 392 | "endif 393 | 394 | return 1 395 | endfunction " }}} 396 | 397 | " s:CommandLineCompletion() {{{ 398 | " Hack needed to account for apparent bug in vim command line mode completion 399 | " when invoked via = 400 | function! s:CommandLineCompletion() 401 | " This hack will trigger InsertLeave which will then invoke 402 | " s:SetDefaultCompletionType. To prevent default completion from being 403 | " restored prematurely, set an internal flag for s:SetDefaultCompletionType 404 | " to check for. 405 | let b:complCommandLine = 1 406 | return "\\:call feedkeys('\\\', 'n') | " . 407 | \ "let b:complCommandLine = 0\" 408 | endfunction " }}} 409 | 410 | " s:ContextCompletion() {{{ 411 | function! s:ContextCompletion() 412 | let contexts = exists('b:SuperTabCompletionContexts') ? 413 | \ b:SuperTabCompletionContexts : g:SuperTabCompletionContexts 414 | 415 | for context in contexts 416 | try 417 | let Context = function(context) 418 | let complType = Context() 419 | unlet Context 420 | if type(complType) == 1 && complType != '' 421 | return complType 422 | endif 423 | catch /E700/ 424 | echohl Error 425 | echom 'supertab: no context function "' . context . '" found.' 426 | echohl None 427 | endtry 428 | endfor 429 | return '' 430 | endfunction " }}} 431 | 432 | " s:ContextDiscover() {{{ 433 | function! s:ContextDiscover() 434 | let discovery = exists('g:SuperTabContextDiscoverDiscovery') ? 435 | \ g:SuperTabContextDiscoverDiscovery : [] 436 | 437 | " loop through discovery list to find the default 438 | if !empty(discovery) 439 | for pair in discovery 440 | let var = substitute(pair, '\(.*\):.*', '\1', '') 441 | let type = substitute(pair, '.*:\(.*\)', '\1', '') 442 | exec 'let value = ' . var 443 | if value !~ '^\s*$' && value != '0' 444 | exec "let complType = \"" . escape(type, '<') . "\"" 445 | return complType 446 | endif 447 | endfor 448 | endif 449 | endfunction " }}} 450 | 451 | " s:ContextText() {{{ 452 | function! s:ContextText() 453 | let exclusions = exists('g:SuperTabContextTextFileTypeExclusions') ? 454 | \ g:SuperTabContextTextFileTypeExclusions : [] 455 | 456 | if index(exclusions, &ft) == -1 457 | let curline = getline('.') 458 | let cnum = col('.') 459 | let synname = synIDattr(synID(line('.'), cnum - 1, 1), 'name') 460 | if curline =~ '.*/\w*\%' . cnum . 'c' || 461 | \ ((has('win32') || has('win64')) && curline =~ '.*\\\w*\%' . cnum . 'c') 462 | return "\\" 463 | 464 | elseif curline =~ '.*\(\w\|[\])]\)\(\.\|::\|->\)\w*\%' . cnum . 'c' && 465 | \ synname !~ '\(String\|Comment\)' 466 | let omniPrecedence = exists('g:SuperTabContextTextOmniPrecedence') ? 467 | \ g:SuperTabContextTextOmniPrecedence : ['&completefunc', '&omnifunc'] 468 | 469 | for omniFunc in omniPrecedence 470 | if omniFunc !~ '^&' 471 | let omniFunc = '&' . omniFunc 472 | endif 473 | if getbufvar(bufnr('%'), omniFunc) != '' 474 | return omniFunc == '&omnifunc' ? "\\" : "\\" 475 | endif 476 | endfor 477 | endif 478 | endif 479 | endfunction " }}} 480 | 481 | " Key Mappings {{{ 482 | " map a regular tab to ctrl-tab (note: doesn't work in console vim) 483 | exec 'inoremap ' . g:SuperTabMappingTabLiteral . ' ' 484 | 485 | imap =ManualCompletionEnter() 486 | 487 | " From the doc |insert.txt| improved 488 | exec 'imap ' . g:SuperTabMappingForward . ' ' 489 | exec 'imap ' . g:SuperTabMappingBackward . ' ' 490 | 491 | " After hitting , hitting it once more will go to next match 492 | " (because in XIM mode and mappings are ignored) 493 | " and wont start a brand new completion 494 | " The side effect, that in the beginning of line and inserts a 495 | " , but I hope it may not be a problem... 496 | inoremap =SuperTab('n') 497 | inoremap =SuperTab('p') 498 | " }}} 499 | 500 | " Command Mappings {{{ 501 | if !exists(":SuperTabHelp") 502 | command SuperTabHelp :call SuperTabHelp() 503 | endif 504 | " }}} 505 | 506 | call s:Init() 507 | 508 | let &cpo = s:save_cpo 509 | 510 | " vim:ft=vim:fdm=marker 511 | --------------------------------------------------------------------------------