Skip to main content
API module

window API

All 40 public APIs exported from the window module, with declarations, documentation, and source-backed examples.

Generated from typings/index.d.ts @ 555f5ceon

window

window.activeTextEditor

The currently active editor or undefined. The active editor is the one that currently has focus or, when none has focus, the one that has changed input most recently.

Source

API signature

window.activeTextEditor: TextEditor | undefined
Returns
TextEditor | undefined
Declaration
typings/index.d.ts:11689
window

window.visibleTextEditors

The currently visible editors or an empty array.

Source

API signature

window.visibleTextEditors: readonly TextEditor[]
Returns
readonly TextEditor[]
Declaration
typings/index.d.ts:11694
window

window.onDidChangeActiveTextEditor

An Event which fires when the active editor has changed. Note that the event also fires when the active editor changes to undefined.

Source

API signature

window.onDidChangeActiveTextEditor: Event<TextEditor | undefined>
Returns
Event<TextEditor | undefined>
Declaration
typings/index.d.ts:11701
window

window.terminals

The currently opened terminals or an empty array. onDidChangeTerminalState doesn't exist since we can't detect window resize on vim.

Source

API signature

window.terminals: readonly Terminal[]
Returns
readonly Terminal[]
Declaration
typings/index.d.ts:11713
window

window.onDidOpenTerminal

Event fired after terminal created, only fired with Terminal that created by window.createTerminal

Source

API signature

window.onDidOpenTerminal: Event<Terminal>
Returns
Event<Terminal>
Declaration
typings/index.d.ts:11719
window

window.onDidCloseTerminal

Event fired on terminal close, only fired with Terminal that created by window.createTerminal

Source

API signature

window.onDidCloseTerminal: Event<Terminal>
Returns
Event<Terminal>
Declaration
typings/index.d.ts:11725
window

window.createTerminal

Creates a Terminal with a backing shell process. The terminal is created by (neo)vim.

Source

API signature

window.createTerminal(opts: TerminalOptions): Promise<Terminal>

Parameters

ParameterTypeDescription
optsTerminalOptions

A TerminalOptions object describing the characteristics of the new terminal.

Returns
Promise<Terminal>

A new Terminal. @throws When running in an environment where a new process cannot be started.

Declaration
typings/index.d.ts:11735
window

window.createFloatFactory

Create float window factory for create float window/popup around current cursor. Configuration "floatFactory.floatConfig" is used as default float config. Configuration "coc.preferences.excludeImageLinksInMarkdownDocument" is also used.

Float windows are automatic reused and hidden on specific events including:

  • BufEnter
  • InsertEnter
  • InsertLeave
  • MenuPopupChanged
  • CursorMoved
  • CursorMovedI
Source

API signature

window.createFloatFactory(conf: FloatWinConfig): FloatFactory

Parameters

ParameterTypeDescription
confFloatWinConfig

Configuration of float window.

Returns
FloatFactory

FloatFactory

Declaration
typings/index.d.ts:11754
window

window.runTerminalCommand

Run command in vim terminal for result

Source

API signature

window.runTerminalCommand(cmd: string, cwd?: string, keepfocus?: boolean): Promise<TerminalResult>

Parameters

ParameterTypeDescription
cmdstring

Command to run.

cwd?string

Cwd of terminal, default to result of |getcwd()|.

keepfocus?boolean
Returns
Promise<TerminalResult>
Declaration
typings/index.d.ts:11771
window

window.openTerminal

Open terminal window.

Source

API signature

window.openTerminal(cmd: string, opts?: OpenTerminalOption): Promise<number>

Parameters

ParameterTypeDescription
cmdstring

Command to run.

opts?OpenTerminalOption

Terminal option.

Returns
Promise<number>

buffer number of terminal.

Declaration
typings/index.d.ts:11780
window

window.showQuickpick

Show quickpick for single item, use window.menuPick for menu at current current position. Use window.showPickerDialog() for multiple selection.

Deprecated use window.showQuickPick() instead.
Source

API signature

window.showQuickpick(items: string[], placeholder?: string): Promise<number>

Parameters

ParameterTypeDescription
itemsstring[]

Label list.

placeholder?string

Prompt text, default to 'choose by number'.

Returns
Promise<number>

Index of selected item, or -1 when canceled.

Declaration
typings/index.d.ts:11791
window

window.showQuickPick

Shows a selection list allowing multiple selections.

Source

Overloads (4)

  1. Signature 1
    window.showQuickPick(items: readonly string[] | Thenable<readonly string[]>, options: QuickPickOptions & { canPickMany: true }, token?: CancellationToken): Thenable<string[] | undefined>
    items: readonly string[] | Thenable<readonly string[]>

    An array of strings, or a promise that resolves to an array of strings.

    options: QuickPickOptions & { canPickMany: true }

    Configures the behavior of the selection list.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Thenable<string[] | undefined>
  2. Signature 2
    window.showQuickPick(items: readonly string[] | Thenable<readonly string[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<string | undefined>
    items: readonly string[] | Thenable<readonly string[]>

    An array of strings, or a promise that resolves to an array of strings.

    options?: QuickPickOptions

    Configures the behavior of the selection list.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Thenable<string | undefined>
  3. Signature 3
    window.showQuickPick<T extends QuickPickItem>(items: readonly T[] | Thenable<readonly T[]>, options: QuickPickOptions & { canPickMany: true }, token?: CancellationToken): Thenable<T[] | undefined>
    items: readonly T[] | Thenable<readonly T[]>

    An array of items, or a promise that resolves to an array of items.

    options: QuickPickOptions & { canPickMany: true }

    Configures the behavior of the selection list.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Thenable<T[] | undefined>
  4. Signature 4
    window.showQuickPick<T extends QuickPickItem>(items: readonly T[] | Thenable<readonly T[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<T | undefined>
    items: readonly T[] | Thenable<readonly T[]>

    An array of items, or a promise that resolves to an array of items.

    options?: QuickPickOptions

    Configures the behavior of the selection list.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Thenable<T | undefined>

API signature

window.showQuickPick(items: readonly string[] | Thenable<readonly string[]>, options: QuickPickOptions & { canPickMany: true }, token?: CancellationToken): Thenable<string[] | undefined>

Parameters

ParameterTypeDescription
itemsreadonly string[] | Thenable<readonly string[]>

An array of strings, or a promise that resolves to an array of strings.

optionsQuickPickOptions & { canPickMany: true }

Configures the behavior of the selection list.

token?CancellationToken

A token that can be used to signal cancellation.

Returns
Thenable<string[] | undefined>

A promise that resolves to the selected items or undefined.

Declaration
typings/index.d.ts:11801
window

window.showMenuPicker

Show menu picker at current cursor position, |inputlist()| is used as fallback.

Source

API signature

window.showMenuPicker(items: string[] | MenuItem[], option?: MenuOption | string, token?: CancellationToken): Promise<number>

Parameters

ParameterTypeDescription
itemsstring[] | MenuItem[]

Array of texts or menu items.

option?MenuOption | string

Optional config of the picker, a string is treated as the title of the window.

token?CancellationToken

A token that can be used to signal cancellation.

Returns
Promise<number>

Selected index (0 based), -1 when canceled.

Declaration
typings/index.d.ts:11841
window

window.showPrompt

Prompt user for confirm, a float/popup window would be used when possible, use vim's |confirm()| function as callback.

Source

API signature

window.showPrompt(title: string): Promise<boolean>

Parameters

ParameterTypeDescription
titlestring

The prompt text.

Returns
Promise<boolean>

Result of confirm.

Declaration
typings/index.d.ts:11850
window

window.showDialog

Show dialog window at the center of screen. Note that the dialog would always be closed after button click.

Source

API signature

window.showDialog(config: DialogConfig): Promise<Dialog | null>

Parameters

ParameterTypeDescription
configDialogConfig

Dialog configuration.

Returns
Promise<Dialog | null>

Dialog or null when dialog can't work.

Declaration
typings/index.d.ts:11859
window

window.requestInput

Request input from user, input() is used when window.env.dialog not true.

Source

API signature

window.requestInput(title: string, defaultValue?: string, option?: InputOptions): Promise<string>

Parameters

ParameterTypeDescription
titlestring

Title text of prompt window.

defaultValue?string

Default value of input, empty text by default.

option?InputOptions

for input window, other preferences are read from user configuration.

Returns
Promise<string>
Declaration
typings/index.d.ts:11868
window

window.createInputBox

Creates and show a InputBox to let the user enter some text input.

Source

API signature

window.createInputBox(title: string, defaultValue?: string, option?: InputPreference): Promise<InputBox>

Parameters

ParameterType
titlestring
defaultValue?string
option?InputPreference
Returns
Promise<InputBox>

A new InputBox.

Declaration
typings/index.d.ts:11875
window

window.createQuickPick

Creates and show a QuickPick to let the user pick an item or items from a list of items of type T.

Note that in many cases the more convenient window.showQuickPick is easier to use. window.createQuickPick should be used when window.showQuickPick does not offer the required flexibility.

Note that unlike VSCode, promise is returned for wait other inputs finished.

Source

API signature

window.createQuickPick<T extends QuickPickItem>(config?: QuickPickConfig<T>): Promise<QuickPick<T>>

Parameters

ParameterTypeDescription
config?QuickPickConfig<T>

Deprecated: config of quickpick, use properties of QuickPick instance instead.

Returns
Promise<QuickPick<T>>

A new QuickPick.

Declaration
typings/index.d.ts:11890
window

window.createStatusBarItem

Create statusbar item that would be included in g:coc_status.

Source

API signature

window.createStatusBarItem(priority?: number, option?: StatusItemOption): StatusBarItem

Parameters

ParameterTypeDescription
priority?number

Higher priority item would be shown right.

option?StatusItemOption
Returns
StatusBarItem

A new status bar item.

Declaration
typings/index.d.ts:11899
window

window.openLocalConfig

Open local config file

Source

API signature

window.openLocalConfig(): Promise<void>
Returns
Promise<void>
Declaration
typings/index.d.ts:11904
window

window.createOutputChannel

Create a new output channel

Source

API signature

window.createOutputChannel(name: string): OutputChannel

Parameters

ParameterTypeDescription
namestring

Unique name of output channel.

Returns
OutputChannel

A new output channel.

Declaration
typings/index.d.ts:11912
window

window.createTreeView

Create a TreeView instance, call show() method to render.

Source

API signature

window.createTreeView<T>(viewId: string, options: TreeViewOptions<T>): TreeView<T>

Parameters

ParameterTypeDescription
viewIdstring

Id of the view, used as title of TreeView when title doesn't exist.

optionsTreeViewOptions<T>

Options for creating the TreeView

Returns
TreeView<T>
Declaration
typings/index.d.ts:11921
window

window.showOutputChannel

Reveal buffer of output channel.

Source

API signature

window.showOutputChannel(name: string, cmd?: string, preserveFocus?: boolean): void

Parameters

ParameterTypeDescription
namestring

Name of output channel.

cmd?string

Command used to reveal the output channel, default to vs.

preserveFocus?boolean

Preserve window focus when true.

Returns
void
Declaration
typings/index.d.ts:11930
window

window.echoLines

Echo lines at the bottom of vim.

Source

API signature

window.echoLines(lines: string[], truncate?: boolean): Promise<void>

Parameters

ParameterTypeDescription
linesstring[]

Line list.

truncate?boolean

Truncate the lines to avoid 'press enter to continue' when true

Returns
Promise<void>
Declaration
typings/index.d.ts:11938
window

window.getCursorPosition

Get current cursor position (line, character both 0 based).

Source

API signature

window.getCursorPosition(): Promise<Position>
Returns
Promise<Position>

Cursor position.

Declaration
typings/index.d.ts:11945
window

window.moveTo

Move cursor to position (line, character both 0 based).

Source

API signature

window.moveTo(position: Position): Promise<void>

Parameters

ParameterTypeDescription
positionPosition

LSP position.

Returns
Promise<void>
Declaration
typings/index.d.ts:11952
window

window.getOffset

Get current cursor character offset in document, length of line break would always be 1.

Source

API signature

window.getOffset(): Promise<number>
Returns
Promise<number>

Character offset.

Declaration
typings/index.d.ts:11960
window

window.getCursorScreenPosition

Get screen position of current cursor(relative to editor), both row and col are 0 based.

Source

API signature

window.getCursorScreenPosition(): Promise<ScreenPosition>
Returns
Promise<ScreenPosition>

Cursor screen position.

Declaration
typings/index.d.ts:11968
window

window.showPickerDialog

Show multiple picker at center of screen.

Source

Overloads (2)

  1. Signature 1
    window.showPickerDialog(items: string[], title: string, token?: CancellationToken): Promise<string[] | undefined>
    items: string[]

    A set of items that will be rendered as actions in the message.

    title: string

    Title of picker dialog.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Promise<string[] | undefined>
  2. Signature 2
    window.showPickerDialog<T extends QuickPickItem>(items: T[], title: string, token?: CancellationToken): Promise<T[] | undefined>
    items: T[]

    A set of items that will be rendered as actions in the message.

    title: string

    Title of picker dialog.

    token?: CancellationToken

    A token that can be used to signal cancellation.

    Returns
    Promise<T[] | undefined>

API signature

window.showPickerDialog(items: string[], title: string, token?: CancellationToken): Promise<string[] | undefined>

Parameters

ParameterTypeDescription
itemsstring[]

A set of items that will be rendered as actions in the message.

titlestring

Title of picker dialog.

token?CancellationToken

A token that can be used to signal cancellation.

Returns
Promise<string[] | undefined>

A promise that resolves to the selected items or undefined.

Declaration
typings/index.d.ts:11978
window

window.showInformationMessage

Shows an information message using coc.nvim message behavior and returns the selected action, when provided.

Source

Overloads (2)

  1. Signature 1
    window.showInformationMessage(message: string, ...items: string[]): Promise<string | undefined>
    message: string

    The message to show.

    ...items?: string[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<string | undefined>
  2. Signature 2
    window.showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T | undefined>
    message: string

    The message to show.

    ...items?: T[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<T | undefined>

API signature

window.showInformationMessage(message: string, ...items: string[]): Promise<string | undefined>

Example

import { window } from 'coc.nvim';

export async function activate() {
  const choice = await window.showInformationMessage(
    'Build completed successfully. Run tests now?',
    'Yes',
    'No'
  );
  if (choice === 'Yes') {
    // run tests
  }
}

Parameters

ParameterTypeDescription
messagestring

The message to show.

...items?string[]

A set of items that will be rendered as actions in the message.

Returns
Promise<string | undefined>

Promise that resolves to the selected item or undefined when being dismissed.

Declaration
typings/index.d.ts:11998
window

window.showWarningMessage

Show an warning message to users. Optionally provide an array of items which will be presented as clickable buttons.

Source

Overloads (2)

  1. Signature 1
    window.showWarningMessage(message: string, ...items: string[]): Promise<string | undefined>
    message: string

    The message to show.

    ...items?: string[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<string | undefined>
  2. Signature 2
    window.showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T | undefined>
    message: string

    The message to show.

    ...items?: T[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<T | undefined>

API signature

window.showWarningMessage(message: string, ...items: string[]): Promise<string | undefined>

Parameters

ParameterTypeDescription
messagestring

The message to show.

...items?string[]

A set of items that will be rendered as actions in the message.

Returns
Promise<string | undefined>

Promise that resolves to the selected item or undefined when being dismissed.

Declaration
typings/index.d.ts:12017
window

window.showErrorMessage

Show an error message to users. Optionally provide an array of items which will be presented as clickable buttons.

Source

Overloads (2)

  1. Signature 1
    window.showErrorMessage(message: string, ...items: string[]): Promise<string | undefined>
    message: string

    The message to show.

    ...items?: string[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<string | undefined>
  2. Signature 2
    window.showErrorMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T | undefined>
    message: string

    The message to show.

    ...items?: T[]

    A set of items that will be rendered as actions in the message.

    Returns
    Promise<T | undefined>

API signature

window.showErrorMessage(message: string, ...items: string[]): Promise<string | undefined>

Parameters

ParameterTypeDescription
messagestring

The message to show.

...items?string[]

A set of items that will be rendered as actions in the message.

Returns
Promise<string | undefined>

Promise that resolves to the selected item or undefined when being dismissed.

Declaration
typings/index.d.ts:12036
window

window.showNotification

Show notification window at bottom right of screen.

Source

API signature

window.showNotification(config: NotificationConfig): Promise<void>

Parameters

ParameterType
configNotificationConfig
Returns
Promise<void>
Declaration
typings/index.d.ts:12050
window

window.getSelectedRange

Get selected range for current document

Source

API signature

window.getSelectedRange(visualmode: string): Promise<Range | null>

Parameters

ParameterType
visualmodestring
Returns
Promise<Range | null>
Declaration
typings/index.d.ts:12075
window

window.selectRange

Visual select range of current document

Source

API signature

window.selectRange(range: Range): Promise<void>

Parameters

ParameterType
rangeRange
Returns
Promise<void>
Declaration
typings/index.d.ts:12080
window

window.diffHighlights

Get diff between new highlight items and current highlights requested from vim

Source

API signature

window.diffHighlights(bufnr: number, ns: string, items: ExtendedHighlightItem[], region?: [number, number] | undefined, token?: CancellationToken): Promise<HighlightDiff | null>

Parameters

ParameterTypeDescription
bufnrnumber

Buffer number

nsstring

Highlight namespace

itemsExtendedHighlightItem[]

Highlight items

region?[number, number] | undefined

0 based start line and end line (end inclusive)

token?CancellationToken

CancellationToken

Returns
Promise<HighlightDiff | null>
Declaration
typings/index.d.ts:12092
window

window.applyDiffHighlights

Apply highlight diffs, normally used with window.diffHighlights

Timer is used to add highlights when there're too many highlight items to add, the highlight process won't be finished on that case.

Source

API signature

window.applyDiffHighlights(bufnr: number, ns: string, priority: number, diff: HighlightDiff, notify?: boolean): Promise<void>

Parameters

ParameterTypeDescription
bufnrnumber

Buffer name

nsstring

Namespace

prioritynumber
diffHighlightDiff
notify?boolean

Use notification, default false.

Returns
Promise<void>
Declaration
typings/index.d.ts:12107
window

window.getVisibleRanges

Get visible ranges of bufnr, when winid specified, only visible range of winid returned. Return empty array when buffer is hidden or window with winid not exists.

Source

API signature

window.getVisibleRanges(bufnr: number, winid?: number): Promise<[number, number][]>

Parameters

ParameterTypeDescription
bufnrnumber

Buffer number

winid?number

Window ID.

Returns
Promise<[number, number][]>

List with [topline, botline], both 1 based and inclusive (returned by getwininfo()).

Declaration
typings/index.d.ts:12117