Skip to content

General editing

Luke edited this page Dec 24, 2024 · 16 revisions

Quick reference

Ox is not modal, and is controlled by various key bindings by default, which are listed in the table below.

You can type straight into the document and use the backspace, return, tab and delete keys to also help modify text.

Keybinding What it does
Ctrl + Q Exits the current tab or the editor if only one tab open.
Ctrl + S Saves the open file to the disk.
Alt + S Prompts you for a file name and saves it to disk as that file name.
Alt + A Saves all the currently open files to the disk.
Ctrl + N Creates a new tab with a blank document.
Ctrl + O Prompts you for a file and opens that file in a new tab.
Ctrl + F Searches the document for a search query. Allows pressing of to move the cursor to the previous occurance fof the query and to move to the next occurance of the query. Press Return or Esc to leave the search. Note: you can use regular expressions for search queries.
Ctrl + Z Undoes your last action. The changes are committed to the undo stack every time you press the space bar, create / destroy a new line and when there is no activity after a certain period of time which can be used to capture points where you pause for thought or grab a coffee etc...
Ctrl + Y Redoes your last action. The changes are committed to the undo stack every time you press the space bar, create / destroy a new line and when there is no activity after a certain period of time which can be used to capture points where you pause for thought or grab a coffee etc...
Ctrl + R Allows replacing of occurances in the document. Uses the same keybindings as the search feature: to move the cursor to the previous occurance of the query and to move to the next occurance of the query. You can also press Return to carry out the replace action. To exit replace mode once you're finished, you can press Esc. You can also use Space to replace every instance in the document at once. Note: you can use regular expressions for search queries.
Ctrl + K Opens the command line.
Alt + Left Navigates to the previous tab.
Alt + Right Navigates to the next tab.
Ctrl + C Copy text from document.
Ctrl + V Paste text from clipboard. Note this might be Ctrl + Shift + V on certain systems.
Ctrl + A Select all text in the document.
Up Move the cursor up.
Down Move the cursor down.
Left Move the cursor left.
Right Move the cursor right.
Shift + Up Move the cursor up whilst selecting.
Shift + Down Move the cursor down whilst selecting.
Shift + Left Move the cursor left whilst selecting.
Shift + Right Move the cursor right whilst selecting.
Ctrl + Up Move to the top of the document.
Ctrl + Down Move to the bottom of the document.
Ctrl + Left Move to the previous word.
Ctrl + Right Move to the next word.
Home Go to the beginning of the current line.
End Go to the end of the current line.
PageUp Move one whole viewport up.
PageDown Move one whole viewport down.
Alt + Up Move the current line up one.
Alt + Down Move the current line down one.
Ctrl + D Delete the current line.
Ctrl + W A shortcut to quickly delete a word (the one to the left of the cursor).
Alt + V Shift the editor to make sure the cursor comes into view.
Esc Cancel selection.
Alt + C Comment or uncomment a line.
Ctrl + Tab Indent a line / selection of lines.
Shift + Tab Dedent a line / selection of lines.
Shift + Home / End Select to the start / end of the current line.
Ctrl + Shift + Left / Right Select by word.
Shift + PageUp / PageDown Select by page.
Ctrl + Space Toggle the file tree open or closed.
Ctrl + F5 Attempts to compile and run the program you're editing, showing output in a terminal.

Feel free to play around with these command shortcuts to get familiar with them.

You can also use the mouse to move between tabs and navigate to a part of the document.

The Command Line

This is a neat feature of ox that lets you modify the state of the editor while the editor is open.

To access the command line, use the keyboard shortcut Ctrl + K

You will be greeting with a prompt, where you can type in a command and press enter to run it.

At this prompt, you can use some of the following commands:

  • help - This will toggle a help message to the right hand side to provide a handy reference if you are just starting out. Run this command once to turn it on, and run it again to turn it off.
  • readonly [boolean] - This will change the read only status of the document. If you want the document that is currently open to be resistant to modification and saving, then you can run the command readonly true, and if you don't, you can run readonly false.
  • filetype [file type] - This will set the filetype of the document. If you have open a file that contains python code, for example, but the editor has not realised it is python code, then you can force it with the command filetype Python, the parameter to this command is the file type name, e.g. Rust for rust, Lua for lua, etc etc. You can find the full list of all the file type names here

Bulk Editing

If you often find yourself having to do repetitive and laborious tasks when editing your code or text, then these features may help you automate the boring stuff.

Multiple Cursors

When you're in Ox, you can put down multiple different cursors and edit them all at once.

When you're in a document, follow the following procedure:

  1. Navigate to a part of the document you want to edit
  2. Press Ctrl + L Click in locations of your document where you wish to put down a secondary cursor (shown in white by default). You can also click again in the same location to remove that secondary cursor.
  3. Start editing!
  4. Click anywhere in the document to get rid of the secondary cursors once you've finished

See an example below

Let's say we have a document (cursor is marked as |):

true|
true
true

we want to change all these true to false, we can do this by positioning our cursor at the end of the first line, then laying down other cursors by pressing Ctrl + L Click at the end of the other two lines, leaving us with the following:

(our main / existing cursor is marked as | and our secondary cursors are marked as _)

true|
true_
true_

Now we can press backspace 4 times, and then write false

This will result in the following document:

false|
false_
false_

With all cursors applying the edits we make on their own.

Now, to get rid of all the secondary cursors and go back into normal editing mode, we can click anywhere in the document, which will remove the cursors.

Try following this on your own to get used to the feeling of multiple cursors.

Macros

If using multiple cursors isn't appropriate for the job, then you can use macros.

This is where you can record editing events, and then play them back numerous times.

To record a macro, run the command macro record, then you can perform editing events as you see fit. After you've finished press Ctrl + Esc to finish your recording.

With your macro recorded, you can then run the command macro play to play back the editing events you just did. You can also run macro play n where n is some integer to run the macro n times back to back e.g. macro play 3 to replay the events 3 times one after the other.

Find an example below:

Let's say we have this document:

hello => there
inter => net
roller => coaster

say we wanted to, for each line, remove the => between each word

This can be done as follows

  1. Position the cursor behind hello (where we will start our editing events)
  2. Press Ctrl + K to access the command line (unless you've manually changed this shortcut)
  3. Type the command macro record and press Enter
  4. Now we're recording a macro, we can start our editing events:
    • Ctrl + F to access search, then search for =>, exiting at the first match
    • Press Delete twice
    • Move the cursor down and then press Home to go to the beginning of the line
  5. So we've recorded our editing events, and set the cursor up ready on the next line, we can finish recording our macro with Ctrl + Esc
  6. We can now replay our macro by running the command macro play 2 (which will replay the macro twice, thus removing the => on the two remaining lines)

Give the above instructions a try in your editor to get used to the feel of recording and playing macros.

Splits

By default, when you open Ox, you may only view one file at a time. If you want to compare files or just see multiple on the same screen at the same time, then splits is the feature that can do that for you.

You can control splits through the split command. Access the command line using Ctrl + K by default.

See the sections below for commands you can use to control splits

Opening Splits

How to actually make use of the splits feature by opening them

  • split left [file path] - opens the specified file to the left hand side of the file you're currently editing
  • split right [file path] - opens the specified file to the right hand side of the file you're currently editing
  • split up [file path] - opens the specified file above the file you're currently editing
  • split down [file path] - opens the specified file below the file you're currently editing

Resizing Splits

You might want to have one file smaller and another file bigger in terms of space used on the screen

  • split grow width - Grows the current file's width in the editor (so you have more space when editing)
  • split grow height - Grows the current file's height in the editor (so you have more space when editing)
  • split grow width [amount] - Grows the current file's width in the editor by a certain amount, which should be between 0 and 1
  • split grow height [amount] - Grows the current file's height in the editor by a certain amount, which should be between 0 and 1
  • split shrink width - Shrinks the current file's width in the editor (leaving more space for other files in other splits)
  • split shrink height - Shrinks the current file's height in the editor (leaving more space for other files in other splits)
  • split shrink width [amount] - Shrinks the current file's width in the editor by a certain amount, which should be between 0 and 1
  • split shrink height [amount] - Shrinks the current file's height in the editor by a certain amount, which should be between 0 and 1

Moving Around

If you are currently editing a file, but you want to start editing a different file opened in another split, you can use the following commands

  • split focus up - Move the cursor to the split above the currently focused one
  • split focus down - Move the cursor to the split below the currently focused one
  • split focus left - Move the cursor to the split to the left of the currently focused one
  • split focus right - Move the cursor to the split to the right of the currently focused one

You can also use Ctrl + Alt + Up / Down / Left / Right to quickly move between splits

Closing Splits

If you have decided you want to close a split, then you may navigate to the split (by changing the focus using the commands above) and then press Ctrl + Q by default to close the files held within that split.

Example Usage

Let's say that you had two files (file1.txt and file2.txt) you wanted to be side by side:

  1. Open the editor by typing in ox file1.txt
  2. Press Ctrl + K to activate the command line
  3. Type split right file2.txt to open the second file to the right of the first
  4. By default, your cursor will now be editing the file2.txt we've just opened, to focus back to the first file, you may type split focus left to move back to the left hand file (file1.txt).
  5. I've now finished with file1.txt, so I can press Ctrl + Q to close it, leaving just file2.txt open
  6. I've now also finished with file2.txt so I can again press Ctrl + Q to close it, and as no more files are open in Ox, it will exit.

File Tree

If you want to be able to perform file operations whilst inside the editor, then you will want to make use of the file tree.

Here's how to use it:

You can open and close it using Ctrl + Space, try this key binding a few times and notice how the file tree opens and closes.

When you open the file tree, by default, your focus (cursor) will move out of the document you were editing and into the file tree, at which point, you can use the following key bindings:

Key Action
Up Move the selection up
Down Move the selection down
Enter If you have a directory selected, expand that directory, if you have a file selected, open that file in the editor
Ctrl + Up Move selection to the top of the file tree
Ctrl + Down Move selection to the bottom of the file tree
Ctrl + Enter If you are selecting a directory, this will move the file tree into that directory
n New file
d Delete the selected file
m Move (or rename) the selected file or folder
c Copy the selected file

You can also use the mouse feature to click on certain files to open them, or expand directories, but keep in mind clicking in the file tree will NOT move your focus, so you will still have a cursor in your file.

You can navigate out of the file tree by clicking out of it, or you can navigate out of it to the right, just as you would with file splits (i.e. using Ctrl + Alt + Right, or the command split focus right)

You can navigate back into the file tree by using the command split focus left to enter it or using the key binding Ctrl + Alt + Left.

See the Configuration page in this wiki if you desire to see how to change the icons / colours / behaviour of the file tree.

Terminal

You can access in-editor terminals. These can be used to test code that you're writing or just run various commands in your workspace.

You can open terminals with the same command you use to open splits:

split [left/right/up/down] [terminal/term]

Start your command with split and then choose a direction to open the terminal (left, right, up, down), and then you can tell ox that you wish to open an editor by adding terminal or term at the end (there is no difference between the two, one is just a shorthand).

Runner

This is a feature that allows you to run your code

By default, you can use the Ctrl + F5 to toggle it. It will try to compile and run your file or project based on the file type.

Whilst compiling and running, you'll be able to see the output on the right hand side.

By default, only a few languages are supported at the moment out of the box: Python, Ruby and Rust. If you wish to have more, please open an issue.

You can also add your own custom ones using the following in your configuration file:

runner["filetype name"] = {
    compile = "command to run", --  nil if there is no command to compile e.g. it's an interpreted language
    run = "command to run", -- nil if there is no command to run e.g. it's some form of markup language
}

Filetype names are the same as the ones over in this part of the wiki.

Commands can use {file_path}, which will be interpolated with the absolute path of the file the user is currently looking at.

Here are a few examples:

runner["Python"] = {
    compile = nil, -- nil because python isn't a compiled language
    run = "python -i {file_path}", -- run the current file interactively using python
}

runner["Rust"] = {
    compile = "cargo build", -- compile the entire project
    run = "cargo run", -- run the entire project
}