Pyvim

3.0.3 · active · verified Thu Apr 16

Pyvim is a pure Python implementation of the Vim text editor, built upon the `prompt_toolkit` library. It offers essential Vim-like features such as syntax highlighting (via Pygments), horizontal and vertical splits, tab pages, and Vi key bindings. The project, currently at version 3.0.3, serves as a demonstration of `prompt_toolkit`'s capabilities and includes integrations for Python code completion (Jedi) and linting (Pyflakes). Its release cadence is irregular, with the last update in May 2022.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically launch the `pyvim` editor using Python's `subprocess` module. It creates a temporary file, opens it in `pyvim`, and then displays the file's content after the editor is closed. Users interact with `pyvim` directly in their terminal.

import subprocess
import os

# Create a dummy file for editing
file_content = "Hello, pyvim!\nThis is a test file.\n"
with open("example.txt", "w") as f:
    f.write(file_content)

print("Launching pyvim to edit example.txt. Press ESC, then :wq to save and exit.")

try:
    # Launch pyvim as a subprocess
    # The input/output will be connected to the current terminal
    subprocess.run(["pyvim", "example.txt"])
except FileNotFoundError:
    print("Error: 'pyvim' executable not found. Make sure it's installed and in your PATH.")
except Exception as e:
    print(f"An error occurred: {e}")

# Optionally, print the content after editing
if os.path.exists("example.txt"):
    with open("example.txt", "r") as f:
        print("\nContent of example.txt after editing:")
        print(f.read())

view raw JSON →