As a vim user, I spend most of my day working with the command line. Here are some a few tricks I’ve learned over the years that I couldn’t live without.
First a small word about the unix tools philosophy, unix programs were design from the start to have a single purpose. Instead of a huge programs that tries to do everything, unix tools are a set of small programs that do single things, they can then be easily combine to do more complex operation with the pipe |
, and ‘&&’ or i/o redirection > <
Some general tricks to start.
^W
to cut a line^Y
to paste^A
to move the cursor to the beginning of the lineYou will often find yourself repeating the same commands. Using the arrow key is probably the most easy way to navigate your command history, but it is highly unefficient.
Here a few tricks:
^R
. (Where ^ means the command key)!!
to repeat the last command.!$
!string
history
to repeat a command, you can use !number
where number is the number in front of the command. You can search your history by piping the command to grep like so history | grep string_to_search
Navigation is something that is important to master in order to work effectively at the command line.
The directory stack is a great tool to navigate quickly between different folders. You can view the current stack with the dirs
command. To add the current dir to the stack use the pushd
command. To retrieve the first element of the stack use popd
cd -
You can substitute part of a command by wrapping the original and the new variable in {}. For example, let’s say I want to move a file to a different folder, rather than using this command:
mv dir/original/a.txt dir/new/a.txt
I could write:
mv dir/{original,new}/a.txt
That’s all for now, please share your favorite tricks!