-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
1. Tutorial: Getting Started
To get started check out the installation instructions in order to follow along with the tutorial.
Create a new text file and open it with Helix by running hx file.txt
.
In the bottom left corner, you'll notice a NOR
, which indicates that you are currently in Normal mode.
In this mode, typing letters like e and n won't insert them as text, but rather have specific commands which we will explore later.
To actually insert some text, press i, which is the command to get into Insert mode, indicated by the INS
in the bottom-left corner.
In Insert mode, the letters you type will be inserted directly into the document.
Try it out by writing Hello helix!
.
Hello helix!
To get back into Normal mode press Esc. This will change the color of your cursor and you will see NOR
again, indicating that you are in normal mode now.
To move your cursor you could use arrow keys, both in Normal and Insert modes:
- ↑ move cursor up
- ↓ move cursor down
- → moves cursor right
- ← moves cursor left
However, this isn't encouraged as that hand will be doing a lot of back-and-forth movement between the arrow keys and the keyboard.
Instead, it is recommended to rest your fingers on the "home row", which is comprised of the row of keys a s d f g h j k l
.
Instead of stretching to reach the arrow keys, use normal mode and h, j, k and l to move your cursor:
- h: moves cursor 1 character to the left.
- j: moves cursor 1 line above.
- k: moves cursor 1 line below.
- l: moves cursor 1 character to the right.
Try holding down h and l to move horizontally across the text you just wrote!
The Esc key is quite far away from the home row on most keyboards; many people remap Caps Lock to Esc.
You can find out how to do this in Remap Caps Lock to Escape.
We only have one line of text, so let's duplicate it several times. Type:
- x, which will select the entire line.
- y, which will yank (copy) the selection to clipboard.
- p, which will paste the contents of the selection after the cursor.
Spam p a few times to create several lines.
Hello helix!
Hello helix!
Hello helix!
Hello helix!
Hello helix!
Now you can try using the h, j, k and l motions to traverse the text!
Let's say we want to replace one of the helix
words with world
. To do this, place your cursor on one of the h letters.
e is a motion which moves to the end of the current word. Type e and it will move your cursor to the end of the helix
.
It doesn't just move your cursor there, though. The entire helix
word becomes highlighted.
If we now press b, which moves to the beginning of the current word, it'll move us back to where we just were.
Try this out a few times, press e and then b to select various sections of the text. If you want to remove your selection press ;.
Helix's philosophy is that each action will act on a selection.
Every time text is modified (an action), you will fully anticipate the result -- because you can clearly see the area of text which is highlighted, and thus will be modified.
For example, if we currently have the word helix
selected, we can change it to world
by pressing c.
c removes the contents of the current selection and places us in Insert mode, where you can then write your new word. Exit back to Normal mode by pressing esc.
The d command deletes the current selection and copies what has been deleted into a clipboard.
Let's test it out by doing the following:
-
Select the line we just changed with x.
-
d to delete this line.
-
Spam p a few times to create some duplicates.
Let's remove all of our previous Hello helix!
by doing the following for each Hello helix!
line:
- Select the line with x.
- d to delete it.
What if we made a mistake, and want to go back? The u command will undo our most recent action. It's similar to Ctrl + z in other editors.
Try pressing down u a few times to get to our previous state, before we made all those modifications.
U is similar to Ctrl + Shift + z in other editors. It will undo the last undo. It's the inverse of u.
Press U until we get back to our most recent state.
Feel free to make modifications to your file using the commands we have learned so far:
- h, j, k and l moves 1 character left, down, up and right.
- i enters Insert mode.
- esc enters Normal mode.
- x selects the entire line.
- y yanks the selection.
- p pastes the recently copied selection.
- e selects and moves to the end of the current word.
- b selects and moves to the beginning of the current word.
- ; removes the extra selection.
- d deletes the current selection, without exiting Normal mode.
- c changes the current selection, by deleting it and entering Insert mode.
- u will undo the most recent change.
- U will undo the most recent undo.
Once you are happy with your modifications, enter Normal mode and type :.
: enters command mode, which has commands you type out.
-
:w
will write the current file. -
:q
will quit the current file. -
:q!
will quit without saving. -
:wq
will both write and quit.
Let's try out more Helix commands! Open the file again with hx file.txt
. Select the entire file by pressing %
Now, delete the selection with d.
Using b to go to the beginning of the word and e to go to the end is useful if you are already at the word you want. But if you are far away, a very powerful command is goto word -- gw.
Let's say we have the following file:
The plates will
and the clouds will
The sun will
and the clouds will
and the moon will
gw will create two letters at the start of every word in sight. When you type those two letters, you instantly jump to the specified word.
Let's say we want to jump to the plates
word. The first two characters have been replaced by at
and highlighted. If we write at
, we will highlight that word!
You can also replace a selection with contents of a register.
- Select the
moon
word by using gw and yank it with y. - Select the
sun
word and replace it withmoon
with R.
Go to the first line by using gg.
To search for a word, use / command. Type will
which is going to highlight the next will
keyword, and then Enter ↵ to select it.
Since there are several will
s in the text, you can cycle between them:
- n cycles to the next match.
- N cycles to the previous match.
Select the clouds
word using gw. If you press i, you will go into insert mode at the beginning of the selection. There are also 5 more ways to enter Insert mode:
- a for append go into insert mode at the end of the selection
- I go into insert mode at the beginning of the current line
- A to append at the end of the current line
- o add a newline below and go into insert mode
- O add a newline above and go into insert mode
Try all of them out!
Helix has a concept called registers, which is like having many clipboards at once.
To interact with them, prefix yank and delete commands with a " and then the name of the register.
For example, the contents of the system clipboard are stored inside the +
register.
On linux, you may need a clipboard provider like xclip to use the system clipboard.
-
Paste the following content into the file with "+p:
The plates will and the clouds will The sun will and the moon will
-
Navigate to the last line by using ge for goto end.
-
Select the last line with x and then yank it with y.
-
Navigate to the second line by using 2gg.
-
Select the second line by using x and then yank into into the e register with "ey.
-
Navigate to the third line by using 3gg.
-
Paste what we copied previously by using p.
Notice how we haven't pasted the 2nd line's contents, but rather the last lines'? Because we yanked the 2nd line's contents into the e register. To paste from it, use "ep.
- " signals to the editor that we are going to use a register.
- e uses the e register.
- p pastes contents of the e register.
Note that pressing p pastes the contents of the register after the line. To paste before, we undo with u and use P to paste before.
You can also search for individual characters by using t, which stands for till.
-
Copy the text below
Twilight fades; stars—whispering, bold— "Hope," they hum; yet shadows unfold... Life? A riddle—endless! Who'll dare, to seek; to dream: to wander—where?
-
Select the entire file with %
-
Override the selection by using Space + R.
Instead of writing "+ to interact with the system clipboard every time, you can also prefix paste and delete motion with Space. For example, Space + p has the same effect as "+p.
Go to the first line with gg and use t; to go to the next semicolon. Repeat this several several times.
To move in the opposite direction, use T; to the previous semicolon.
Using t and T motions will move your cursor to just before the next or the previous occurrence of the character.
For example, te to go to the next e. T" to go to just before the previous double-quote.
The f for find is similar to t, but instead it places your cursor at the occurrence of the character. Try using f; several times. F goes the opposite way.
By using Alt + ., you can repeat the last t, T, f or F motion.
Each motion also accepts an optional count, which defaults to 1 if you don't provide it.
- For example, use 2f; which would be the same as f;f;.
- Or 7b which would be the same as bbbbbbb.
Currently the text is fairly short, but we can fix that. Select everything with %, yank y and then paste it 100 times with 100p. This will create a very big file.
We can use these commands to scroll large chunks of text at once:
- Ctrl + d to scroll down half a page
- Ctrl + u to scroll up half a page