(Note: the Python 2 keywords were removed in February 2021 with Vim 8.2.2554).
You'll have to look at the syntax file and undo what it's doing. You can find the syntax file with
:e $VIMRUNTIME/syntax/python.vim, and with
/file I found:
" Python 2 only
syn keyword pythonBuiltin basestring cmp execfile file
syn keyword pythonBuiltin long raw_input reduce reload unichr
syn keyword pythonBuiltin unicode xrange
" non-essential built-in functions; Python 2 only
syn keyword pythonBuiltin apply buffer coerce intern
As far as I know there is no way to remove keywords from the
syn keyword declaration, so you'll have to either:
- Clear the
pythonBuiltin declarations with
:syn clear pythonBuiltin and define your own with just the Python 3 ones:
syn keyword pythonBuiltin abs all any [...]
- Override the Python 3 ones; e.g.
:syn keyword pythonTwoBuiltin file.
The first method is arguably a bit "cleaner", but with the second method you will retain future additions to
pythonBuiltin from the system's file. It will also allow you to do something like
:hi link pythonTwoBuiltin pythonBuiltin to highlight the Python 2 builtins in case you find yourself editing Python 2 code.
I would personally opt for the second method, and added this to my vimrc:
" Remove Python 2 keywords.
autocmd Syntax python
\ syn keyword pythonTwoBuiltin basestring cmp execfile file long
\ raw_input reduce reload unichr unicode
\ xrange apply buffer coerce intern
Note you can't just add this to your vimrc file; you'll have to use an autocmd or the
~/.vim/after/syntax/python.vim file. See How can I add additional syntax highlighting rules in my local vimrc? for details on that.