Jordi Enric

Software Engineer at Supabase logoSupabase

Back

March 13, 2024

Creating custom aliases in Oh-My-Zsh

Oh-My-Zsh simplifies the process of adding custom aliases to your Zsh configuration. Let's explore how to do this using Vim, a powerful terminal text editor, and how to edit the alias file visually:

Step 1: Navigate to the Custom Directory

Open a terminal and go to the custom directory within the Oh-My-Zsh configuration:

# bash
cd ~/.oh-my-zsh/custom

Step 2: Create an Alias File

Inside the custom directory, create a file to store your aliases. For example:

# bash
touch aliases.zsh

Step 3: Edit the Alias File with Vim

Open the file with Vim:

# bash
vim aliases.zsh

Step 4: Define Your Alias

In Vim, press i to enter insert mode. Add your custom aliases to the file:

# bash
# ~/.oh-my-zsh/custom/aliases.zsh
alias ll='ls -alF'
alias myalias='some_command'

After adding aliases, press Esc to exit insert mode, then type :wq and press Enter to save and quit Vim.

Step 5 (optional): Visual Editing Option

If you prefer to edit the file visually using a GUI text editor, you can open the file with the default editor:

Linux

# bash
xdg-open aliases.zsh # This command works on Linux with XDG

Mac

# bash
open -e aliases.zsh # macOS

Windows

# bash
start aliases.zsh # windows

Step 6: Save and Apply Changes

Finally, apply the changes by reloading your Zsh configuration:

# bash
source ~/.zshrc

Step 7: Test Your Alias

Your custom aliases are now ready to use. Test them in the terminal:

# bash
ll

You should see the result of ls -alF.

Hope this was helpful.

Back to all posts