if_pyth.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. *if_pyth.txt* Nvim
  2. NVIM REFERENCE MANUAL
  3. The Python Interface to NVim *if_pyth* *python* *Python*
  4. See |provider-python| for more information.
  5. Type |gO| to see the table of contents.
  6. ==============================================================================
  7. Commands *python-commands*
  8. *:python* *:py* *E263* *E264* *E887*
  9. :[range]py[thon] {stmt}
  10. Execute Python statement {stmt}. A simple check if
  11. the `:python` command is working: >vim
  12. :python print("Hello")
  13. :[range]py[thon] << [trim] [{endmarker}]
  14. {script}
  15. {endmarker}
  16. Execute Python script {script}. Useful for including
  17. python code in Vim scripts. Requires Python, see
  18. |script-here|.
  19. If [endmarker] is omitted from after the "<<", a dot '.' must be used after
  20. {script}, like for the |:append| and |:insert| commands. Refer to
  21. |:let-heredoc| for more information.
  22. Example: >vim
  23. function! IcecreamInitialize()
  24. python << EOF
  25. class StrawberryIcecream:
  26. def __call__(self):
  27. print('EAT ME')
  28. EOF
  29. endfunction
  30. To see what version of Python you have: >vim
  31. :python print(sys.version)
  32. There is no need to "import sys", it's done by default.
  33. *python-environment*
  34. Environment variables set in Vim are not always available in Python. This
  35. depends on how Vim and Python were build. Also see
  36. https://docs.python.org/3/library/os.html#os.environ
  37. Note: Python is very sensitive to indenting. Make sure the "class" line and
  38. "EOF" do not have any indent.
  39. *:pydo*
  40. :[range]pydo {body} Execute Python function "def _vim_pydo(line, linenr):
  41. {body}" for each line in the [range], with the
  42. function arguments being set to the text of each line
  43. in turn, without a trailing <EOL>, and the current
  44. line number. The function should return a string or
  45. None. If a string is returned, it becomes the text of
  46. the line in the current turn. The default for [range]
  47. is the whole file: "1,$".
  48. Examples:
  49. >vim
  50. :pydo return "%s\t%d" % (line[::-1], len(line))
  51. :pydo if line: return "%4d: %s" % (linenr, line)
  52. <
  53. One can use `:pydo` in possible conjunction with `:py` to filter a range using
  54. python. For example: >vim
  55. :py3 << EOF
  56. needle = vim.eval('@a')
  57. replacement = vim.eval('@b')
  58. def py_vim_string_replace(str):
  59. return str.replace(needle, replacement)
  60. EOF
  61. :'<,'>py3do return py_vim_string_replace(line)
  62. <
  63. *:pyfile* *:pyf*
  64. :[range]pyf[ile] {file}
  65. Execute the Python script in {file}. The whole
  66. argument is used as a single file name.
  67. Both of these commands do essentially the same thing - they execute a piece of
  68. Python code, with the "current range" |python-range| set to the given line
  69. range.
  70. In the case of :python, the code to execute is in the command-line.
  71. In the case of :pyfile, the code to execute is the contents of the given file.
  72. Python commands cannot be used in the |sandbox|.
  73. To pass arguments you need to set sys.argv[] explicitly. Example: >vim
  74. :python sys.argv = ["foo", "bar"]
  75. :pyfile myscript.py
  76. Here are some examples *python-examples*
  77. >vim
  78. :python from vim import *
  79. :python current.line = str.upper(current.line)
  80. :python print("Hello")
  81. :python str = current.buffer[42]
  82. Note that changes (such as the "import" statements) persist from one command
  83. to the next, just like the Python REPL.
  84. *script-here*
  85. When using a script language in-line, you might want to skip this when the
  86. language isn't supported.
  87. >vim
  88. if has('python')
  89. python << EOF
  90. print("python works")
  91. EOF
  92. endif
  93. <
  94. Note that "EOF" must be at the start of the line without preceding white
  95. space.
  96. ==============================================================================
  97. The vim module *python-vim*
  98. Python code gets all of its access to vim (with one exception - see
  99. |python-output| below) via the "vim" module. The vim module implements two
  100. methods, three constants, and one error object. You need to import the vim
  101. module before using it: >vim
  102. :python import vim
  103. Overview >vim
  104. :py print("Hello") # displays a message
  105. :py vim.command(cmd) # execute an Ex command
  106. :py w = vim.windows[n] # gets window "n"
  107. :py cw = vim.current.window # gets the current window
  108. :py b = vim.buffers[n] # gets buffer "n"
  109. :py cb = vim.current.buffer # gets the current buffer
  110. :py w.height = lines # sets the window height
  111. :py w.cursor = (row, col) # sets the window cursor position
  112. :py pos = w.cursor # gets a tuple (row, col)
  113. :py name = b.name # gets the buffer file name
  114. :py line = b[n] # gets a line from the buffer
  115. :py lines = b[n:m] # gets a list of lines
  116. :py num = len(b) # gets the number of lines
  117. :py b[n] = str # sets a line in the buffer
  118. :py b[n:m] = [str1, str2, str3] # sets a number of lines at once
  119. :py del b[n] # deletes a line
  120. :py del b[n:m] # deletes a number of lines
  121. Methods of the "vim" module
  122. vim.command(str) *python-command*
  123. Executes the vim (ex-mode) command str. Returns None.
  124. Examples: >vim
  125. :py vim.command("set tw=72")
  126. :py vim.command("%s/aaa/bbb/g")
  127. < The following definition executes Normal mode commands: >python
  128. def normal(str):
  129. vim.command("normal "+str)
  130. # Note the use of single quotes to delimit a string containing
  131. # double quotes
  132. normal('"a2dd"aP')
  133. vim.eval(str) *python-eval*
  134. Evaluates the expression str using the vim internal expression
  135. evaluator (see |expression|). Returns the expression result as:
  136. - a string if the Vim expression evaluates to a string or number
  137. - a list if the Vim expression evaluates to a Vim list
  138. - a dictionary if the Vim expression evaluates to a Vim dictionary
  139. Dictionaries and lists are recursively expanded.
  140. Examples: >vim
  141. :py text_width = vim.eval("&tw")
  142. :py str = vim.eval("12+12") # NB result is a string! Use
  143. # int() to convert to a
  144. # number.
  145. vim.strwidth(str) *python-strwidth*
  146. Like |strwidth()|: returns number of display cells str occupies, tab
  147. is counted as one cell.
  148. vim.foreach_rtp(callable) *python-foreach_rtp*
  149. Call the given callable for each path in 'runtimepath' until either
  150. callable returns something but None, the exception is raised or there
  151. are no longer paths. If stopped in case callable returned non-None,
  152. vim.foreach_rtp function returns the value returned by callable.
  153. `vim.chdir(*args, **kwargs)` *python-chdir*
  154. `vim.fchdir(*args, **kwargs)` *python-fchdir*
  155. Run os.chdir or os.fchdir, then all appropriate vim stuff.
  156. Note: you should not use these functions directly, use os.chdir and
  157. os.fchdir instead. Behavior of vim.fchdir is undefined in case
  158. os.fchdir does not exist.
  159. Error object of the "vim" module
  160. vim.error *python-error*
  161. Upon encountering a Vim error, Python raises an exception of type
  162. vim.error.
  163. Example: >python
  164. try:
  165. vim.command("put a")
  166. except vim.error:
  167. # nothing in register a
  168. Constants of the "vim" module
  169. Note that these are not actually constants - you could reassign them.
  170. But this is silly, as you would then lose access to the vim objects
  171. to which the variables referred.
  172. vim.buffers *python-buffers*
  173. A mapping object providing access to the list of vim buffers. The
  174. object supports the following operations: >vim
  175. :py b = vim.buffers[i] # Indexing (read-only)
  176. :py b in vim.buffers # Membership test
  177. :py n = len(vim.buffers) # Number of elements
  178. :py for b in vim.buffers: # Iterating over buffer list
  179. <
  180. vim.windows *python-windows*
  181. A sequence object providing access to the list of vim windows. The
  182. object supports the following operations: >vim
  183. :py w = vim.windows[i] # Indexing (read-only)
  184. :py w in vim.windows # Membership test
  185. :py n = len(vim.windows) # Number of elements
  186. :py for w in vim.windows: # Sequential access
  187. < Note: vim.windows object always accesses current tab page.
  188. |python-tabpage|.windows objects are bound to parent |python-tabpage|
  189. object and always use windows from that tab page (or throw vim.error
  190. in case tab page was deleted). You can keep a reference to both
  191. without keeping a reference to vim module object or |python-tabpage|,
  192. they will not lose their properties in this case.
  193. vim.tabpages *python-tabpages*
  194. A sequence object providing access to the list of vim tab pages. The
  195. object supports the following operations: >vim
  196. :py t = vim.tabpages[i] # Indexing (read-only)
  197. :py t in vim.tabpages # Membership test
  198. :py n = len(vim.tabpages) # Number of elements
  199. :py for t in vim.tabpages: # Sequential access
  200. <
  201. vim.current *python-current*
  202. An object providing access (via specific attributes) to various
  203. "current" objects available in vim:
  204. vim.current.line The current line (RW) String
  205. vim.current.buffer The current buffer (RW) Buffer
  206. vim.current.window The current window (RW) Window
  207. vim.current.tabpage The current tab page (RW) TabPage
  208. vim.current.range The current line range (RO) Range
  209. The last case deserves a little explanation. When the :python or
  210. :pyfile command specifies a range, this range of lines becomes the
  211. "current range". A range is a bit like a buffer, but with all access
  212. restricted to a subset of lines. See |python-range| for more details.
  213. Note: When assigning to vim.current.{buffer,window,tabpage} it expects
  214. valid |python-buffer|, |python-window| or |python-tabpage| objects
  215. respectively. Assigning triggers normal (with |autocommand|s)
  216. switching to given buffer, window or tab page. It is the only way to
  217. switch UI objects in python: you can't assign to
  218. |python-tabpage|.window attribute. To switch without triggering
  219. autocommands use >vim
  220. py << EOF
  221. saved_eventignore = vim.options['eventignore']
  222. vim.options['eventignore'] = 'all'
  223. try:
  224. vim.current.buffer = vim.buffers[2] # Switch to buffer 2
  225. finally:
  226. vim.options['eventignore'] = saved_eventignore
  227. EOF
  228. <
  229. vim.vars *python-vars*
  230. vim.vvars *python-vvars*
  231. Dictionary-like objects holding dictionaries with global (|g:|) and
  232. vim (|v:|) variables respectively.
  233. vim.options *python-options*
  234. Object partly supporting mapping protocol (supports setting and
  235. getting items) providing a read-write access to global options.
  236. Note: unlike |:set| this provides access only to global options. You
  237. cannot use this object to obtain or set local options' values or
  238. access local-only options in any fashion. Raises KeyError if no global
  239. option with such name exists (i.e. does not raise KeyError for
  240. |global-local| options and global only options, but does for window-
  241. and buffer-local ones). Use |python-buffer| objects to access to
  242. buffer-local options and |python-window| objects to access to
  243. window-local options.
  244. Type of this object is available via "Options" attribute of vim
  245. module.
  246. Output from Python *python-output*
  247. Vim displays all Python code output in the Vim message area. Normal
  248. output appears as information messages, and error output appears as
  249. error messages.
  250. In implementation terms, this means that all output to sys.stdout
  251. (including the output from print statements) appears as information
  252. messages, and all output to sys.stderr (including error tracebacks)
  253. appears as error messages.
  254. *python-input*
  255. Input (via sys.stdin, including input() and raw_input()) is not
  256. supported, and may cause the program to crash. This should probably be
  257. fixed.
  258. *python3-directory* *pythonx-directory*
  259. Python 'runtimepath' handling *python-special-path*
  260. In python vim.VIM_SPECIAL_PATH special directory is used as a replacement for
  261. the list of paths found in 'runtimepath': with this directory in sys.path and
  262. vim.path_hooks in sys.path_hooks python will try to load module from
  263. {rtp}/python3 and {rtp}/pythonx for each {rtp} found in 'runtimepath'.
  264. Implementation is similar to the following, but written in C: >python
  265. from imp import find_module, load_module
  266. import vim
  267. import sys
  268. class VimModuleLoader(object):
  269. def __init__(self, module):
  270. self.module = module
  271. def load_module(self, fullname, path=None):
  272. return self.module
  273. def _find_module(fullname, oldtail, path):
  274. idx = oldtail.find('.')
  275. if idx > 0:
  276. name = oldtail[:idx]
  277. tail = oldtail[idx+1:]
  278. fmr = find_module(name, path)
  279. module = load_module(fullname[:-len(oldtail)] + name, *fmr)
  280. return _find_module(fullname, tail, module.__path__)
  281. else:
  282. fmr = find_module(fullname, path)
  283. return load_module(fullname, *fmr)
  284. # It uses vim module itself in place of VimPathFinder class: it does not
  285. # matter for python which object has find_module function attached to as
  286. # an attribute.
  287. class VimPathFinder(object):
  288. @classmethod
  289. def find_module(cls, fullname, path=None):
  290. try:
  291. return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
  292. except ImportError:
  293. return None
  294. @classmethod
  295. def load_module(cls, fullname, path=None):
  296. return _find_module(fullname, fullname, path or vim._get_paths())
  297. def hook(path):
  298. if path == vim.VIM_SPECIAL_PATH:
  299. return VimPathFinder
  300. else:
  301. raise ImportError
  302. sys.path_hooks.append(hook)
  303. vim.VIM_SPECIAL_PATH *python-VIM_SPECIAL_PATH*
  304. String constant used in conjunction with vim path hook. If path hook
  305. installed by vim is requested to handle anything but path equal to
  306. vim.VIM_SPECIAL_PATH constant it raises ImportError. In the only other
  307. case it uses special loader.
  308. Note: you must not use value of this constant directly, always use
  309. vim.VIM_SPECIAL_PATH object.
  310. vim.find_module(...) *python-find_module*
  311. vim.path_hook(path) *python-path_hook*
  312. Methods or objects used to implement path loading as described above.
  313. You should not be using any of these directly except for vim.path_hook
  314. in case you need to do something with sys.meta_path. It is not
  315. guaranteed that any of the objects will exist in the future vim
  316. versions.
  317. vim._get_paths *python-_get_paths*
  318. Methods returning a list of paths which will be searched for by path
  319. hook. You should not rely on this method being present in future
  320. versions, but can use it for debugging.
  321. It returns a list of {rtp}/python3 and {rtp}/pythonx
  322. directories for each {rtp} in 'runtimepath'.
  323. ==============================================================================
  324. Buffer objects *python-buffer*
  325. Buffer objects represent vim buffers. You can obtain them in a number of ways:
  326. - via vim.current.buffer (|python-current|)
  327. - from indexing vim.buffers (|python-buffers|)
  328. - from the "buffer" attribute of a window (|python-window|)
  329. Buffer objects have two read-only attributes - name - the full file name for
  330. the buffer, and number - the buffer number. They also have three methods
  331. (append, mark, and range; see below).
  332. You can also treat buffer objects as sequence objects. In this context, they
  333. act as if they were lists (yes, they are mutable) of strings, with each
  334. element being a line of the buffer. All of the usual sequence operations,
  335. including indexing, index assignment, slicing and slice assignment, work as
  336. you would expect. Note that the result of indexing (slicing) a buffer is a
  337. string (list of strings). This has one unusual consequence - b[:] is different
  338. from b. In particular, "b[:] = None" deletes the whole of the buffer, whereas
  339. "b = None" merely updates the variable b, with no effect on the buffer.
  340. Buffer indexes start at zero, as is normal in Python. This differs from vim
  341. line numbers, which start from 1. This is particularly relevant when dealing
  342. with marks (see below) which use vim line numbers.
  343. The buffer object attributes are:
  344. b.vars Dictionary-like object used to access
  345. |buffer-variable|s.
  346. b.options Mapping object (supports item getting, setting and
  347. deleting) that provides access to buffer-local options
  348. and buffer-local values of |global-local| options. Use
  349. |python-window|.options if option is window-local,
  350. this object will raise KeyError. If option is
  351. |global-local| and local value is missing getting it
  352. will return None.
  353. b.name String, RW. Contains buffer name (full path).
  354. Note: when assigning to b.name |BufFilePre| and
  355. |BufFilePost| autocommands are launched.
  356. b.number Buffer number. Can be used as |python-buffers| key.
  357. Read-only.
  358. b.valid True or False. Buffer object becomes invalid when
  359. corresponding buffer is wiped out.
  360. The buffer object methods are:
  361. b.append(str) Append a line to the buffer
  362. b.append(str, nr) Idem, below line "nr"
  363. b.append(list) Append a list of lines to the buffer
  364. Note that the option of supplying a list of strings to
  365. the append method differs from the equivalent method
  366. for Python's built-in list objects.
  367. b.append(list, nr) Idem, below line "nr"
  368. b.mark(name) Return a tuple (row,col) representing the position
  369. of the named mark (can also get the []"<> marks)
  370. b.range(s,e) Return a range object (see |python-range|) which
  371. represents the part of the given buffer between line
  372. numbers s and e |inclusive|.
  373. Note that when adding a line it must not contain a line break character '\n'.
  374. A trailing '\n' is allowed and ignored, so that you can do: >vim
  375. :py b.append(f.readlines())
  376. Buffer object type is available using "Buffer" attribute of vim module.
  377. Examples (assume b is the current buffer) >vim
  378. :py print(b.name) # write the buffer file name
  379. :py b[0] = "hello!!!" # replace the top line
  380. :py b[:] = None # delete the whole buffer
  381. :py del b[:] # delete the whole buffer
  382. :py b[0:0] = [ "a line" ] # add a line at the top
  383. :py del b[2] # delete a line (the third)
  384. :py b.append("bottom") # add a line at the bottom
  385. :py n = len(b) # number of lines
  386. :py (row,col) = b.mark('a') # named mark
  387. :py r = b.range(1,5) # a sub-range of the buffer
  388. :py b.vars["foo"] = "bar" # assign b:foo variable
  389. :py b.options["ff"] = "dos" # set fileformat
  390. :py del b.options["ar"] # same as :set autoread<
  391. ==============================================================================
  392. Range objects *python-range*
  393. Range objects represent a part of a vim buffer. You can obtain them in a
  394. number of ways:
  395. - via vim.current.range (|python-current|)
  396. - from a buffer's range() method (|python-buffer|)
  397. A range object is almost identical in operation to a buffer object. However,
  398. all operations are restricted to the lines within the range (this line range
  399. can, of course, change as a result of slice assignments, line deletions, or
  400. the range.append() method).
  401. The range object attributes are:
  402. r.start Index of first line into the buffer
  403. r.end Index of last line into the buffer
  404. The range object methods are:
  405. r.append(str) Append a line to the range
  406. r.append(str, nr) Idem, after line "nr"
  407. r.append(list) Append a list of lines to the range
  408. Note that the option of supplying a list of strings to
  409. the append method differs from the equivalent method
  410. for Python's built-in list objects.
  411. r.append(list, nr) Idem, after line "nr"
  412. Range object type is available using "Range" attribute of vim module.
  413. Example (assume r is the current range):
  414. # Send all lines in a range to the default printer
  415. vim.command("%d,%dhardcopy!" % (r.start+1,r.end+1))
  416. ==============================================================================
  417. Window objects *python-window*
  418. Window objects represent vim windows. You can obtain them in a number of ways:
  419. - via vim.current.window (|python-current|)
  420. - from indexing vim.windows (|python-windows|)
  421. - from indexing "windows" attribute of a tab page (|python-tabpage|)
  422. - from the "window" attribute of a tab page (|python-tabpage|)
  423. You can manipulate window objects only through their attributes. They have no
  424. methods, and no sequence or other interface.
  425. Window attributes are:
  426. buffer (read-only) The buffer displayed in this window
  427. cursor (read-write) The current cursor position in the window
  428. This is a tuple, (row,col).
  429. height (read-write) The window height, in rows
  430. width (read-write) The window width, in columns
  431. vars (read-only) The window |w:| variables. Attribute is
  432. unassignable, but you can change window
  433. variables this way
  434. options (read-only) The window-local options. Attribute is
  435. unassignable, but you can change window
  436. options this way. Provides access only to
  437. window-local options, for buffer-local use
  438. |python-buffer| and for global ones use
  439. |python-options|. If option is |global-local|
  440. and local value is missing getting it will
  441. return None.
  442. number (read-only) Window number. The first window has number 1.
  443. This is zero in case it cannot be determined
  444. (e.g. when the window object belongs to other
  445. tab page).
  446. row, col (read-only) On-screen window position in display cells.
  447. First position is zero.
  448. tabpage (read-only) Window tab page.
  449. valid (read-write) True or False. Window object becomes invalid
  450. when corresponding window is closed.
  451. The height attribute is writable only if the screen is split horizontally.
  452. The width attribute is writable only if the screen is split vertically.
  453. Window object type is available using "Window" attribute of vim module.
  454. ==============================================================================
  455. Tab page objects *python-tabpage*
  456. Tab page objects represent vim tab pages. You can obtain them in a number of
  457. ways:
  458. - via vim.current.tabpage (|python-current|)
  459. - from indexing vim.tabpages (|python-tabpages|)
  460. You can use this object to access tab page windows. They have no methods and
  461. no sequence or other interfaces.
  462. Tab page attributes are:
  463. number The tab page number like the one returned by
  464. |tabpagenr()|.
  465. windows Like |python-windows|, but for current tab page.
  466. vars The tab page |t:| variables.
  467. window Current tabpage window.
  468. valid True or False. Tab page object becomes invalid when
  469. corresponding tab page is closed.
  470. TabPage object type is available using "TabPage" attribute of vim module.
  471. ==============================================================================
  472. pyeval() and py3eval() Vim functions *python-pyeval*
  473. To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()|
  474. functions to evaluate Python expressions and pass their values to Vim script.
  475. |pyxeval()| is also available.
  476. ==============================================================================
  477. Python 3 *python3*
  478. As Python 3 is the only supported version in Nvim, "python" is synonymous
  479. with "python3" in the current version. However, code that aims to support older
  480. versions of Nvim, as well as Vim, should prefer to use "python3" variants
  481. explicitly if Python 3 is required.
  482. *:py3* *:python3*
  483. :[range]py3 {stmt}
  484. :[range]py3 << [trim] [{endmarker}]
  485. {script}
  486. {endmarker}
  487. :[range]python3 {stmt}
  488. :[range]python3 << [trim] [{endmarker}]
  489. {script}
  490. {endmarker}
  491. The `:py3` and `:python3` commands work similar to `:python`. A
  492. simple check if the `:py3` command is working: >vim
  493. :py3 print("Hello")
  494. <
  495. To see what version of Python you have: >vim
  496. :py3 import sys
  497. :py3 print(sys.version)
  498. < *:py3file*
  499. :[range]py3f[ile] {file}
  500. The `:py3file` command works similar to `:pyfile`.
  501. *:py3do*
  502. :[range]py3do {body}
  503. The `:py3do` command works similar to `:pydo`.
  504. *E880*
  505. Raising SystemExit exception in python isn't endorsed way to quit vim, use:
  506. >vim
  507. :py vim.command("qall!")
  508. <
  509. *has-python*
  510. You can test if Python is available with: >vim
  511. if has('pythonx')
  512. echo 'there is Python'
  513. endif
  514. if has('python3')
  515. echo 'there is Python 3.x'
  516. endif
  517. Python 2 is no longer supported. Thus `has('python')` always returns
  518. zero for backwards compatibility reasons.
  519. ==============================================================================
  520. Python X *python_x* *pythonx*
  521. The "pythonx" and "pyx" prefixes were introduced for python code which
  522. works with Python 2.6+ and Python 3. As Nvim only supports Python 3,
  523. all these commands are now synonymous to their "python3" equivalents.
  524. *:pyx* *:pythonx*
  525. `:pyx` and `:pythonx` work the same as `:python3`. To check if `:pyx` works: >vim
  526. :pyx print("Hello")
  527. To see what version of Python is being used: >vim
  528. :pyx import sys
  529. :pyx print(sys.version)
  530. <
  531. *:pyxfile* *python_x-special-comments*
  532. `:pyxfile` works the same as `:py3file`.
  533. *:pyxdo*
  534. `:pyxdo` works the same as `:py3do`.
  535. *has-pythonx*
  536. To check if `pyx*` functions and commands are available: >vim
  537. if has('pythonx')
  538. echo 'pyx* commands are available. (Python ' .. &pyx .. ')'
  539. endif
  540. ==============================================================================
  541. vim:tw=78:ts=8:noet:ft=help:norl: