Last updated: Aug 17, 2026

API Reference

This page documents the Python functions available to Koi workflows and plugins.

Example usage:


# This is the default scripts-file for Koi Editor

@command("Word count")
def word_count():
    import re

    text = selected_text()
    count = len(re.findall(r"\b[\w'-]+\b", text))

    message(f"Word count: {count:,} words")

@command("Insert UUID")
def insert_uuid():
    from uuid import uuid4
    insert_text(text=str(uuid4()))

@command("Markdown: Selection to link")
def insert_link():
    text = selected_text()
    insert_text(text=f"[{text}](https://{text})")

@command("Markdown: Insert unchecked box")
def insert_unchecked_box():
    insert_text(text="- [ ] ")

@command("Markdown: Wrap selection in fenced block")
def fenced_block():
    text = selected_text()
    insert_text(text=f"```\n{text}\n```")

@command("Markdown: Bold")
def make_bold():
    text = selected_text()
    insert_text(text=f"**{text}**")

API overview

CodeEditor

CodeEditor.insert_text

def insert_text(text: str = '')

Insert text at the current cursor position.

CodeEditor.unselect_other_active_tabs

def unselect_other_active_tabs()

Unselect other active tabs. Keep active editor as only selected tab.

CodeEditor.format_csv_columns

def format_csv_columns()

Formats CSV columns to align them.

CodeEditor.submit_prompt

def submit_prompt()

Submit the current line as a prompt.

CodeEditor.tear_off_buffer

def tear_off_buffer()

Tear off active buffer into new window.

CodeEditor.toggle_word_wrap

def toggle_word_wrap()

Toggle word wrap mode. If enabled, the editor will wrap lines at word boundaries.

CodeEditor.auto_detect_lexer

def auto_detect_lexer()

Auto detect lexer based on file extension.

CodeEditor.detach_lexer

def detach_lexer()

Detach the lexer. Useful for very large files.

CodeEditor.accept_first_completion_item

def accept_first_completion_item()

Accept the first item in the completion list.

CodeEditor.accept_ghost_text

def accept_ghost_text()

Accept the ghost text in the editor.

CodeEditor.toggle_read_only

def toggle_read_only()

Toggle read-only mode on the editor.

CodeEditor.find_next

def find_next(needle, forward = True)

Find the next occurrence of 'needle' in the document. Forward search is enabled by default.

CodeEditor.select_next_match

def select_next_match()

Multi-cursor editing. Selects the next match of the current selection.

CodeEditor.unselect_last_match

def unselect_last_match()

Multi-cursor editing. Unselect the last match.

CodeEditor.select_matches

def select_matches()

Multi-cursor editing. Select all matches of the current word.

CodeEditor.add_cursors_to_line_starts

def add_cursors_to_line_starts()

Replace the current selection with one cursor at the start of each selected line, including empty lines.

CodeEditor.get_token_at

def get_token_at(line, index)

Returns the token type and color at the given position in the specified line.

CodeEditor.get_indent_level

def get_indent_level(line_text)

Returns the indentation level of the given line text.

CodeEditor.replace_tabs_with_spaces

def replace_tabs_with_spaces()

Replace all tabs with spaces in the document.

CodeEditor.read_file

def read_file(_file)

Read file into editor. Replaces current text.

CodeEditor.inline_command

def inline_command()

Execute inline command.

CodeEditor.python_eval_line

def python_eval_line()

Evaluate the current line as Python code.

CodeEditor.new_file

def new_file()

Open a new file. Returns the new file buffer.

CodeEditor.new_window

def new_window()

Open a new window. Returns the new window object.

CodeEditor.open_file_in_new_window

def open_file_in_new_window()

Open the current file in a new window.

CodeEditor.reopen_last_closed_file

def reopen_last_closed_file()

Reopen the last closed file.

CodeEditor.close_file

def close_file()

Close the current file.

CodeEditor.close_other_files

def close_other_files()

Close all files except the current one.

CodeEditor.fold_line

def fold_line(line = None)

Fold the line at the given line number. If no line number is given, the current line is used.

CodeEditor.fold_all

def fold_all()

Fold all foldable lines.

CodeEditor.open_config_file

def open_config_file()

Open the config file in the current window.

CodeEditor.open_scripts_file

def open_scripts_file()

Open the scripts file in the current window.

CodeEditor.move_up_to_empty_line

def move_up_to_empty_line()

Move the cursor up to the previous empty line.

CodeEditor.move_up_to_empty_line_extend

def move_up_to_empty_line_extend()

Extend the selection up to the previous empty line.

CodeEditor.move_down_to_empty_line

def move_down_to_empty_line()

Move the cursor down to the next empty line.

CodeEditor.move_down_to_empty_line_extend

def move_down_to_empty_line_extend()

Extend the selection down to the next empty line.

CodeEditor.open_file

def open_file(file_with_path = None)

Open a file in the current window.

CodeEditor.save_file

def save_file()

Save the current file.

CodeEditor.save_file_as

def save_file_as()

Save a the current file as a new file.

CodeEditor.save_file_copy_as

def save_file_copy_as()

Save a copy of the current file as a new file.

CodeEditor.reload_from_disk

def reload_from_disk()

Reload the current file from disk.

CodeEditor.line_comment

def line_comment()

Toggle line comment for the current line or selection.

CodeEditor.reset_zoom

def reset_zoom()

Reset the zoom level to 0.

CodeEditor.replace_all_eol

def replace_all_eol()

Replace all EOLs with the current buffer EOL mode.

CodeEditor.eol_mode_lf

def eol_mode_lf()

Set EOL mode to LF for the current buffer only.

CodeEditor.eol_mode_crlf

def eol_mode_crlf()

Set EOL mode to CRLF for the current buffer only.

CodeEditor.eol_mode_cr

def eol_mode_cr()

Set EOL mode to CR for the current buffer only.

CodeEditor.toggle_eol_symbols

def toggle_eol_symbols()

Toggle visible EOL symbols for the current buffer only. This is not persistent.

CodeEditor.zoom_in

def zoom_in()

Zoom in by 1 point. This is for current buffer only and not persistent on close.

CodeEditor.zoom_out

def zoom_out()

Zoom out by 1 point. This is for current buffer only and not persistent on close.

CodeEditor.toggle_split_editor

def toggle_split_editor()

Toggle the split editor mode.

CodeEditor.copy_path_to_file

def copy_path_to_file(file_with_path = None)

Copy the path to the file to the clipboard.

CodeEditor.select_all

def select_all()

Selects all text in the editor.

CodeEditor.undo

def undo()

Undo the last edit action.

CodeEditor.redo

def redo()

Redo the last edit action.

CodeEditor.copy

def copy()

Copy the selected text to the clipboard.

CodeEditor.cut

def cut()

Cut selected text to the clipboard.

CodeEditor.paste

def paste()

Paste the text from the clipboard.

CodeEditor.lowercase

def lowercase()

Convert the selected text to lowercase.

CodeEditor.uppercase

def uppercase()

Convert the selected text to uppercase.

CodeEditor.cancel

def cancel()

Cancel the current operation.

CodeEditor.newline

def newline()

Insert a newline while preserving indentation.

CodeEditor.insert_line_above

def insert_line_above()

Insert a line above the current line. This collapses multiple selections to single selection.

CodeEditor.insert_line_below

def insert_line_below()

Insert a line below the current line. This collapses multiple selections to single selection.

CodeEditor.tab

def tab()

Insert a tab character.

CodeEditor.selected_text

def selected_text()

Returns the selected text as a string.

CodeEditor.backtab

def backtab()

Remove one indentation level from the current line or selected lines. Alias for line_unindent().

CodeEditor.center_on_cursor

def center_on_cursor()

Center the view on the cursor.

CodeEditor.line_indent

def line_indent()

Indent selected lines.

CodeEditor.line_unindent

def line_unindent()

Unindent selected lines.

CodeEditor.selection_duplicate

def selection_duplicate()

Duplicate the selection.

CodeEditor.move_line_up

def move_line_up()

Move the current line up.

CodeEditor.move_line_down

def move_line_down()

Move the current line down.

CodeEditor.document_start

def document_start()

Move the cursor to the start of the document. This collapses multiple selections to single selection.

CodeEditor.document_start_extend

def document_start_extend()

Move the cursor to the start of the document and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.document_end

def document_end()

Move the cursor to the end of the document. This collapses multiple selections to single selection.

CodeEditor.document_end_extend

def document_end_extend()

Move the cursor to the end of the document and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.home

def home()

Move the cursor to the start of the line. This collapses multiple selections to single selection.

CodeEditor.home_extend

def home_extend()

Move the cursor to the start of the line and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.line_up

def line_up()

Move the cursor up one line. This collapses multiple selections to single selection.

CodeEditor.line_up_start

def line_up_start()

Move the cursor up one line and to the start of the line. This collapses multiple selections to single selection.

CodeEditor.line_up_start_extend

def line_up_start_extend()

Move the cursor up one line and to the start of the line and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.line_down_end

def line_down_end()

Move the cursor down one line and to the end of the line. This collapses multiple selections to single selection.

CodeEditor.line_down_end_extend

def line_down_end_extend()

Move the cursor down one line and to the end of the line and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.line_up_extend

def line_up_extend()

Move the cursor up one line and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.line_down

def line_down()

Move the cursor down one line. This collapses multiple selections to single selection.

CodeEditor.line_down_extend

def line_down_extend()

Move the cursor down one line and extend the selection. This collapses overlapping selections into single selection.

CodeEditor.line_scroll_up

def line_scroll_up()

Scroll the view up one line.

CodeEditor.line_scroll_down

def line_scroll_down()

Scroll the view down one line.

CodeEditor.line_add_caret_up

def line_add_caret_up()

Multi-cursor editing. Add a cursor above the current cursor.

CodeEditor.line_add_caret_down

def line_add_caret_down()

Multi-cursor editing. Add a cursor below the current cursor.

CodeEditor.duplicate_line

def duplicate_line()

Duplicate the current line. This collapses multiple selections to single selection.

CodeEditor.sort_selected_lines_reverse

def sort_selected_lines_reverse()

Sort selected lines alphabetically, reversed. Expands the selection to whole lines.

CodeEditor.sort_selected_lines

def sort_selected_lines(reverse = False, case_sensitive = False)

Sort selected lines alphabetically. Expands the selection to whole lines.

CodeEditor.move_caret_paragraph_above

def move_caret_paragraph_above()

Move caret to the start of the current paragraph. Or paragraph above if caret at the start of the current paragraph. This collapses multiple selections to single selection.

CodeEditor.move_caret_paragraph_below

def move_caret_paragraph_below()

Move caret to the start of the paragraph below. This collapses multiple selections to single selection.

CodeEditor.extend_selection_paragraph_above

def extend_selection_paragraph_above()

Extend selection to the start of the current paragraph. Or paragraph above if caret at the start of the current paragraph. This collapses multiple selections to single selection.

CodeEditor.extend_selection_paragraph_below

def extend_selection_paragraph_below()

Extend selection to the start of the paragraph below. This collapses multiple selections to single selection.

CodeEditor.move_caret_to_fold_above

def move_caret_to_fold_above()

Move the caret to the nearest fold header above. This collapses multiple selections to single selection.

CodeEditor.move_caret_to_fold_below

def move_caret_to_fold_below()

Move the caret to the nearest fold header below. This collapses multiple selections to single selection.

CodeEditor.extend_selection_to_fold_above

def extend_selection_to_fold_above()

Extend the selection to the nearest fold header above. This collapses multiple selections to single selection.

CodeEditor.extend_selection_to_fold_below

def extend_selection_to_fold_below()

Extend the selection to the nearest fold header below. This collapses multiple selections to single selection.

CodeEditor.move_caret_back

def move_caret_back()

Move caret back one character.

CodeEditor.extend_selection_back

def extend_selection_back()

Extend selection back one character.

CodeEditor.move_caret_forward

def move_caret_forward()

Move caret forward one character.

CodeEditor.extend_selection_forward

def extend_selection_forward()

Extend selection forward one character.

CodeEditor.move_caret_back_word

def move_caret_back_word()

Move caret back one word.

CodeEditor.move_caret_forward_word

def move_caret_forward_word()

Move caret forward one word. Start of word.

CodeEditor.extend_selection_back_word

def extend_selection_back_word()

Extend selection back one word.

CodeEditor.extend_selection_forward_word

def extend_selection_forward_word()

Extend selection forward one word.

CodeEditor.move_caret_back_word_end

def move_caret_back_word_end()

Move caret back one word. End of word.

CodeEditor.move_caret_forward_word_end

def move_caret_forward_word_end()

Move caret forward one word. End of word.

CodeEditor.extend_selection_back_word_end

def extend_selection_back_word_end()

Extend selection back one word. End of word.

CodeEditor.extend_selection_forward_word_end

def extend_selection_forward_word_end()

Extend selection forward one word. End of word.

CodeEditor.move_caret_back_word_part

def move_caret_back_word_part()

Move caret back one word part.

CodeEditor.extend_selection_back_word_part

def extend_selection_back_word_part()

Extend selection back one word part.

CodeEditor.move_caret_forward_word_part

def move_caret_forward_word_part()

Move caret forward one word part.

CodeEditor.extend_selection_forward_word_part

def extend_selection_forward_word_part()

Extend selection forward one word part.

CodeEditor.move_caret_line_start

def move_caret_line_start()

Move caret to the start of the line.

CodeEditor.move_caret_line_end

def move_caret_line_end()

Move caret to the end of the line. Accepts ghost text, if any.

CodeEditor.extend_selection_line_start

def extend_selection_line_start()

Extend selection to the start of the line.

First jump goes to visual/home indentation. Second jump goes to absolute line start.

CodeEditor.extend_selection_line_end

def extend_selection_line_end()

Extend selection to the end of the line.

CodeEditor.page_up

def page_up()

Move caret up one page.

CodeEditor.page_down

def page_down()

Move caret down one page.

CodeEditor.page_up_stuttered

def page_up_stuttered()

Move caret up one page, stuttered.

CodeEditor.page_down_stuttered

def page_down_stuttered()

Move caret down one page, stuttered.

CodeEditor.delete_back

def delete_back()

Delete the character to the left of the caret. In leading indentation, delete back to the previous tab stop.

CodeEditor.delete_back_not_newline

def delete_back_not_newline()

Delete the character to the left of the caret without joining lines.

CodeEditor.delete_forward

def delete_forward()

Delete the character to the right of the caret.

CodeEditor.delete_back_word

def delete_back_word()

Delete the word to the left of the caret.

CodeEditor.delete_forward_word

def delete_forward_word()

Delete the word to the right of the caret.

CodeEditor.delete_line

def delete_line()

Delete the current line.

CodeEditor.delete_to_line_start

def delete_to_line_start()

Delete from the caret to the start of the line.

CodeEditor.delete_to_line_end

def delete_to_line_end()

Delete from the caret to the end of the line.

CodeEditor.previous_tab

def previous_tab()

Switch to the previous tab.

CodeEditor.previous_tab_extend

def previous_tab_extend()

Extend active tabs to the previous tab.

CodeEditor.next_tab

def next_tab()

Switch to the next tab.

CodeEditor.next_tab_extend

def next_tab_extend()

Extend active tabs to the next tab.

CodeEditor.reset_window_position

def reset_window_position()

Reset the window position.

CodeEditor.reset_file_explorer

def reset_file_explorer()

Reset the root folder for file explorer.

CodeEditor.reload_file_explorer

def reload_file_explorer()

Reload the root folder for file explorer.

CodeEditor.detect_tab_width

def detect_tab_width()

Detect indentation width from the current buffer and apply it. This is for the current buffer only and is not persistent.

CodeEditor.tab_width_2_spaces

def tab_width_2_spaces()

Set the tab width to 2 spaces. This is for current buffer only and not persistent on close.

CodeEditor.tab_width_4_spaces

def tab_width_4_spaces()

Set the tab width to 4 spaces. This is for current buffer only and not persistent on close.

CodeEditor.tab_width_8_spaces

def tab_width_8_spaces()

Set the tab width to 4 spaces. This is for current buffer only and not persistent on close.

CodeEditor.indent_with_tabs

def indent_with_tabs()

Set the indentation to use tabs. This is for current buffer only and not persistent on close.

CodeEditor.indent_with_spaces

def indent_with_spaces()

Set the indentation to use spaces. This is for current buffer only and not persistent on close.

CodeEditor.open_diff_from_buffers

def open_diff_from_buffers()

Open a diff between the first two open buffers in a new buffer.

CodeEditor.open_diff_from_git

def open_diff_from_git()

Open the Git diff for the current file in a new buffer.

EditorWindow

EditorWindow.open_folder

def open_folder(path_to_folder)

Open a folder in the default file manager.

EditorWindow.show_message

def show_message(title = None, text = '')

Show a message box with the given title and text. The default title is "System Message".

EditorWindow.move_buffer_to_window

def move_buffer_to_window(buffer, new_window)

Move a buffer to a new window.

EditorWindow.drop_to_open_file

def drop_to_open_file(file_with_path, line_number = None, text_to_highlight = None, line = None, index = None)

Open a file or folder in the current editor window.

App

App.system_message

def system_message(title = None, text = '')

No description provided.