Available actions

ezvi offers many different tools that can be used to manipulate text files.

  • Commands that can be used to automate typing are under the Vi tools section.

  • Commands that can be used to search text or create configuration files are under the Parsing tools section.

Vi tools

These are the currently available tools for the Vi editor. They can all be used in the YAML config file and directly in Python when the mododule is imported.

To use the Vi tools, simply import the tools part of 1 this package to your program like this:

import ezvi.tools

You can then add any function from the section below the same way they are presented under the Using the API section.

To declutter your program, you can also import every Vi tool individually.

from ezvi.tools import *

This can be read as from ezvi’s tools module, import all. This will allow you to directly use the functions without specifying that they come from the ezvi module. For example, to type three new lines, you would use

new_line(3)

Caution

Using this second method to import a module is less specific than the first method. This could result into namespace collisions if you are using multiple modules with methods which are named similarly.

ezvi.tools module

tools.py contains functions used in the funcmodule to interact with the vi editor. Most functions can be mapped to existing vi commands.

This module is also where the API is documented. Each funcion’s docstring contains documentation on how to use the function with the API and with the command line interface.

ezvi.tools.force_quit_editor()

To force quit the editor.

From the command mode, force_quit_editor uses Vi’s :q! command to force quit the editor. All unsaved progress will be lost.

Usage:

In a config file:

- force_quit_editor:

Using the API:

ezvi.tools.force_quit_editor()
Return type

str

Returns

:q! and a newline character.

ezvi.tools.goto_column(column_num)

To go to a certain column.

This function uses the l command to move the cursor to a certain column on the current line.

Usage:

In a config file:

- goto_column: 5

Using the API:

ezvi.tools.goto_column(5)
Parameters

column_num (int) – The number of the column to move the cursor to.

Return type

str

Returns

0 plus a column position appended with l.

ezvi.tools.goto_line(line_num)

To go to a certain line.

This function uses the G command to move the cursor to the beginning of a certain line.

Usage:

In a config file:

- goto_line: 5

Using the API:

ezvi.tools.goto_line(5)
Parameters

line_num (int) – The number of the line to move the cursor to.

Return type

str

Returns

A line number appended with G.

ezvi.tools.new_line(amount=1)

Creates an amount of new lines.

new_line inserts a certain number of new lines to the file. From Vi’s command mode, ezvi first presses o. This ensures that the current line won’t be split even if the cursor is not at the end of the line.

Usage:

In a config file:

- new_line: 3

Using the API:

ezvi.tools.new_line(3)
Parameters

amount (int) – The number of new lines to create.

Return type

str

Returns

A string that contains the characters that would be used

to create a certain amount of new lines in Vi.

ezvi.tools.new_line_over()

Creates a new line over the cursor.

The cursor is also moved to the beginning of the new line. It is not possible to create more than one new line over the cursor at a time for now.

Usage:

In a config file:

- new_line_over:

Using the API:

ezvi.tools.new_line_over()
Return type

str

Returns

Characters that would be used in Vi to add a new line

over the cursor.

ezvi.tools.quit_editor()

To quit the editor.

From the command mode, quit_editor uses Vi’s :q command to quit the editor. Since Vi makes sure that the current buffer is saved before quitting, force_quit_editor should be used instead if the buffer must not be saved.

Usage:

In a config file:

- quit_editor:

Using the API:

ezvi.tools.quit_editor()
Return type

str

Returns

:q and a newline.

ezvi.tools.replace(start, end, new)

Replaces text on the current line.

This function replaces from the column number start to the column number end with the new text. replace moves the cursor to the starting position and then uses the change command (c) to replace the text.

Usage:

In a config file:

- replace: 0, 4, "Snek"

Using the API:

ezvi.tools.replace(0, 4, "Snek")
Parameters
  • start (int) – The number of the column to start replacing (inclusively).

  • end (int) – The number of the column to stop replacing (exlusively).

  • new (str) – The new text to type.

Return type

str

Returns

Keystrokes that can be used to replace text from start to end.

ezvi.tools.replace_line(new)

Replaces text on the current line.

replace moves the cursor to the beginning of the line using 0 from the command mode and then uses command (c$) to replace the whole line.

Usage:

In a config file:

- replace_line: "Hello there."

Using the API:

ezvi.tools.replace_line("General Kenobi.")
Parameters

new (str) – The new text to replace the current line.

Return type

str

Returns

Characters that can be typeed to change the current line

with new content.

ezvi.tools.write_after_char(to_write)

To write to_write after the cursor’s position (current char).

to_write is written after the cursor position using the a command.

Usage:

In a config file:

- write_after_char: "Greetings!"

Using the API:

ezvi.tools.write_after_char("Greetings!")
Parameters

to_write (str) – What to write after the cursor.

Return type

str

Returns

Characters that would be used to add contents after the

current cursor position.

ezvi.tools.write_after_line(to_write)

To write to_write after the current line.

This function uses $ from the command mode to go to the end of the line. to_write is then written after the cursor position using the a command. This function does not add a space to the beginning of ``to_write``.

Usage:

In a config file:

- write_after_line: " General Kenobi."

Using the API:

ezvi.tools.write_after_line(" General Kenobi.")
Parameters

to_write (str) – What to write after the line.

Return type

str

Returns

Characters that would be used to append content to a line.

ezvi.tools.write_after_word(to_write)

To write to_write after the current word.

This function uses e from the command mode to go to the end of the word. to_write is then written after the end of the word using the a command. This function does not add a space to the beginning of ``to_write``.

Usage:

In a config file:

- write_after_word: " General Kenobi."

Using the API:

ezvi.tools.write_after_word(" General Kenobi.")
Parameters

to_write (str) – What to write after the word.

Return type

str

Returns

Characters that would be used to type contents after the

current word.

ezvi.tools.write_before_char(to_write)

To write to_write at the beginning of the line.

write_before_line uses 0 from the command mode to move the cursor to the beginning of the current line. to_write is then written before the cursor’s position using the i command.

Usage:

In a config file:

- write_before_line: "Hello there."

Using the API:

ezvi.tools.write_before_line("Hello there.")
Parameters

to_write (str) – What to write before the current line.

Return type

str

Returns

Keystrokes that can be used to add content before the

current cursor position.

ezvi.tools.write_before_line(to_write)

To write to_write at the beginning of the line.

write_before_line uses 0 from the command mode to move the cursor to the beginning of the current line. to_write is then written before the cursor’s position using the i command.

Usage:

In a config file:

- write_before_line: "Hello there."

Using the API:

ezvi.tools.write_before_line("Hello there.")
Parameters

to_write (str) – What to write before the current line.

Return type

str

Returns

Characters that can be used to prepend content to a line.

ezvi.tools.write_before_word(to_write)

To write to_write before the current word.

write_before_word uses b from the command mode to move the cursor to the beginning of the current word. to_write is then written before the cursor’s position using the i command.

Usage:

In a config file:

- write_before_word: "Hello there."

Using the API:

ezvi.tools.write_before_word("Hello there.")
Parameters

to_write (str) – What to write before the current word.

Return type

str

Returns

Keystrokes that can be used to prepend a word with new contents.

ezvi.tools.write_chars(to_write: str) list

To type to_write to the file.

write_chars will type the passed string after the cursor position. From Vi’s command mode, it types a to insert after and then types the string.

Usage:

In a config file:

- write_chars: "snek"

Using the API:

ezvi.tools.write_chars("snek")
Parameters

to_write (str) – The characters to write.

Return type

str

Returns

A string that corresponds to the keys that would be

pressed to insert text after the current cursor position.

ezvi.tools.write_file(filename)

Write the current buffer.

From the command mode, write_file uses Vi’s :w command to write the current buffer.

Usage:

In a config file:

- write_file: "message.txt"

Using the API:

ezvi.tools.write_file("message.txt")
Parameters

filename (str) – The path towards where to save the current buffer.

Return type

str

Returns

:w plus a file name and a newline.

ezvi.tools.write_line(to_write: str) str

To type to_write and create a new line.

Starts typing after the current cursor position by pressing a from the command mode. to_write is then typed and a new line is created.

Usage:

In a config file:

- write_line: "Python is fun."

Using the API:

ezvi.tools.write_line("Python is fun.")
Parameters

to_write (str) – The characters to write.

Return type

str

Returns

A string that contains the keystrokes that would be used

to write a whole line in Vi.

Parsing tools

Most of these tools have not been implemented yet. Please refer to the latest branch.

Generating a config file

To automatically generate a config file, you can simply use the generate-config command. generate-config will create a config file to type the original file line by line.

ezvi generate-config [PATH/TO/FILE]
  • The -s option tells the program to write it’s output to a file instead of the terminal’s standard output. The path towards where the file should be saved must be provided.

    ezvi generate-config -s [PATH/TO/SAVE] [PATH/TO/FILE]
    

Note

A diff function will be added soon. This will allow for the creation of config file based upon the differences between two files. See the latest branch for the most recent updates.

Footnotes

1

Make sure that the package is properly installed first.