mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
docs(if_pyth): make it work with Python 3 instead of Python 2 (#23620)
This commit is contained in:
@@ -17,7 +17,7 @@ Commands *python-commands*
|
|||||||
:[range]py[thon] {stmt}
|
:[range]py[thon] {stmt}
|
||||||
Execute Python statement {stmt}. A simple check if
|
Execute Python statement {stmt}. A simple check if
|
||||||
the `:python` command is working: >vim
|
the `:python` command is working: >vim
|
||||||
:python print "Hello"
|
:python print("Hello")
|
||||||
|
|
||||||
:[range]py[thon] << [trim] [{endmarker}]
|
:[range]py[thon] << [trim] [{endmarker}]
|
||||||
{script}
|
{script}
|
||||||
@@ -35,7 +35,7 @@ Example: >vim
|
|||||||
python << EOF
|
python << EOF
|
||||||
class StrawberryIcecream:
|
class StrawberryIcecream:
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
print 'EAT ME'
|
print('EAT ME')
|
||||||
EOF
|
EOF
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -100,11 +100,9 @@ To pass arguments you need to set sys.argv[] explicitly. Example: >vim
|
|||||||
|
|
||||||
Here are some examples *python-examples*
|
Here are some examples *python-examples*
|
||||||
>vim
|
>vim
|
||||||
|
|
||||||
:python from vim import *
|
:python from vim import *
|
||||||
:python from string import upper
|
:python current.line = str.upper(current.line)
|
||||||
:python current.line = upper(current.line)
|
:python print("Hello")
|
||||||
:python print "Hello"
|
|
||||||
:python str = current.buffer[42]
|
:python str = current.buffer[42]
|
||||||
|
|
||||||
Note that changes (such as the "import" statements) persist from one command
|
Note that changes (such as the "import" statements) persist from one command
|
||||||
@@ -143,7 +141,7 @@ module before using it: >vim
|
|||||||
:python import vim
|
:python import vim
|
||||||
|
|
||||||
Overview >vim
|
Overview >vim
|
||||||
:py print "Hello" # displays a message
|
:py print("Hello") # displays a message
|
||||||
:py vim.command(cmd) # execute an Ex command
|
:py vim.command(cmd) # execute an Ex command
|
||||||
:py w = vim.windows[n] # gets window "n"
|
:py w = vim.windows[n] # gets window "n"
|
||||||
:py cw = vim.current.window # gets the current window
|
:py cw = vim.current.window # gets the current window
|
||||||
@@ -175,10 +173,6 @@ vim.command(str) *python-command*
|
|||||||
# Note the use of single quotes to delimit a string containing
|
# Note the use of single quotes to delimit a string containing
|
||||||
# double quotes
|
# double quotes
|
||||||
normal('"a2dd"aP')
|
normal('"a2dd"aP')
|
||||||
< *E659*
|
|
||||||
The ":python" command cannot be used recursively with Python 2.2 and
|
|
||||||
older. This only works with Python 2.3 and later: >vim
|
|
||||||
:py vim.command("python print 'Hello again Python'")
|
|
||||||
|
|
||||||
vim.eval(str) *python-eval*
|
vim.eval(str) *python-eval*
|
||||||
Evaluates the expression str using the vim internal expression
|
Evaluates the expression str using the vim internal expression
|
||||||
@@ -190,8 +184,8 @@ vim.eval(str) *python-eval*
|
|||||||
Examples: >vim
|
Examples: >vim
|
||||||
:py text_width = vim.eval("&tw")
|
:py text_width = vim.eval("&tw")
|
||||||
:py str = vim.eval("12+12") # NB result is a string! Use
|
:py str = vim.eval("12+12") # NB result is a string! Use
|
||||||
# string.atoi() to convert to
|
# int() to convert to a
|
||||||
# a number.
|
# number.
|
||||||
|
|
||||||
vim.strwidth(str) *python-strwidth*
|
vim.strwidth(str) *python-strwidth*
|
||||||
Like |strwidth()|: returns number of display cells str occupies, tab
|
Like |strwidth()|: returns number of display cells str occupies, tab
|
||||||
@@ -467,7 +461,7 @@ A trailing '\n' is allowed and ignored, so that you can do: >vim
|
|||||||
Buffer object type is available using "Buffer" attribute of vim module.
|
Buffer object type is available using "Buffer" attribute of vim module.
|
||||||
|
|
||||||
Examples (assume b is the current buffer) >vim
|
Examples (assume b is the current buffer) >vim
|
||||||
:py print b.name # write the buffer file name
|
:py print(b.name) # write the buffer file name
|
||||||
:py b[0] = "hello!!!" # replace the top line
|
:py b[0] = "hello!!!" # replace the top line
|
||||||
:py b[:] = None # delete the whole buffer
|
:py b[:] = None # delete the whole buffer
|
||||||
:py del b[:] # delete the whole buffer
|
:py del b[:] # delete the whole buffer
|
||||||
|
Reference in New Issue
Block a user