gpt4 book ai didi

python - 如何让 Vim 识别 Python3 语法?

转载 作者:太空狗 更新时间:2023-10-30 00:18:49 24 4
gpt4 key购买 nike

我搜索了相关帖子并尝试了几种方法,但在使用 Python3 语法时,我仍然在 Vim 中收到语法错误。

收到错误的代码:

types_of_people = 10; f"There are {types_of_people} types of people."

运行 $ vim --version 的输出:

$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 17 2017 10:39:50)
MacOS X (unix) version
Included patches: 1-1100
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminal
++builtin_terms +fork() +multi_lang +terminfo
+byte_offset -gettext -mzscheme +termresponse
+channel -hangul_input +netbeans_intg +textobjects
+cindent +iconv +num64 +timers
-clientserver +insert_expand +packages +title
+clipboard +job +path_extra -toolbar
+cmdline_compl +jumplist +perl +user_commands
+cmdline_hist +keymap +persistent_undo +vertsplit
+cmdline_info +lambda +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak -python +viminfo
+cscope +lispindent +python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con -lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind -X11
-dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape +startuptime -xpm
+eval +mouse_dec +statusline -xsmp
+ex_extra -mouse_gpm -sun_workshop -xterm_clipboard
+extra_search -mouse_jsbterm +syntax -xterm_save
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -
U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector -L/usr/local/lib -
L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -
L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv
-framework Cocoa -mmacosx-version-min=10.11 -fstack-protector-strong -
L/usr/local/lib -L/usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-
thread-multi-2level/CORE -lperl -lm -lutil -lc -
L/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-
darwin -lpython3.6m -framework CoreFoundation -lruby.2.4.2 -lobjc

你可能注意到上面的 Vim 包括 python3 而不是 python

我已经使用以下方法重新安装了 Vim:

$ brew uninstall vim
$ brew install vim --with-python3

我还尝试将 python 别名为我的 Python3 版本:

$ alias python='python3.6'

我的路径:

$ echo $PATH  
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/garythegoat/.rbenv/shims:/usr/bin/python:/usr/local/heroku/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/local/go/bin:/Users/garythegoat/golang/bin

:echo has('python') 返回 1

:echo has('python3') 返回 0

感谢任何建议

最佳答案

这是一个难题,因为这与您的操作系统配置的默认 python 有关。

我找到的最有用的相关问题是this one .

两种解决方案都对我有用:

  1. 使用 virtualenv 设置虚拟环境.这很累人,因为每次需要打开 vim 时都必须启动虚拟环境。

  2. 添加 let g:syntastic_python_python_exec = 'python3'.vimrc 配置文件。我不确定您的配置是否基于 syntastic 插件,但这是最糟糕的调查。

关于python - 如何让 Vim 识别 Python3 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46265824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com