Skip to content

General editing

Luke edited this page Nov 7, 2024 · 12 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.

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.

Clone this wiki locally