Basic Linux and Vim commands

Anthony C
5 min readFeb 19, 2022

One of the most useful things I’ve learned over the last few weeks is some basic linux commands and Vim. Linux is a fantastic operating system that is open source and available on any machine. If you’re using a Mac, your terminal is already something similar to it, called Zsh. However, if you’re running an older operating system, then you could be using Bash, which is part of the Linux operating system.

The easiest way to get started with Linux is to start with one of the distributions called Ubuntu, and the way that I use this is with a Virtual Machine. Now this might sounds complicated if you haven’t heard this before, but it’s actually really easy to setup.

Here is a fantastic video on how to get started. https://www.youtube.com/watch?v=9rUhGWijf9U

Just follow the steps.

The reason why you would want to do this is that it’s way easier setting up a virtual box than uninstalling your operating system and setting up linux from scratch. With a virtual box you can turn it on and turn it off and it’s like having a whole other computer inside your exiting computer.

Linux Basic Commands

Hopefully by now you have installed your new operating system with Ubuntu. If you have the first thing you need to check out is the terminal. You might think what is so special about it. It looks just like the terminal I already had. If you have a Mac, then yes it is very similar, but if not it is very different than a windows terminal.

Here are some basic commands to get you started…

  • ls, lists all the files and directories in the directory you are in at the moment.
  • mkdir <name of directory>, will make a directory.
  • touch <name of file>.<extension>, will make a new file with the extension you decide.
  • cd .. , will bring you back to the previous directory
  • rm <filename>, removes a file
  • rm -r <directory name>, removes a directory

Each of these commands can be modified and used in more advanced ways. The best way to learn about these are the linux man pages.

Linux Man Pages

There are plenty of ways to learn about linux commands, but the most convenient ways to learn are the linux man pages that are contained and accessible in the terminal itself.

Here’s what you do …

On the terminal line, type …

man <command you want to learn>

man ls

man rm

After you do this you will get a detailed file that you can study for further reference.

While you are in there, you might get stuck in there and wonder how you can control what you see. This is where you need to know a little more about the linux terminal.

You can control everything in the terminal without using a mouse.

To quit, the window and return to the terminal, you can hit q. To move around in the window you can use j to move down and k to move up. If you hit the h button, you can see a summary of the commands you can use.

Using only your keyboard is kind of jarring at first, but I’ve been using my keyboard for over a week now and it’s feels hard to use a mouse all the sudden.

Using the man pages can be a little challenging to find exactly what you want, so if you’re struggling I found this website which was a big help.

Vim

My favorite new tool that is actually part of both Linux and Mac terminals is Vim. It’s one of the most advanced text editors you can find and you can set it up so that you can use it with your keyboard only.

I know what you’re thinking, and I thought the same thing. Why would you care about using only your keyboard, well, at first, it’s not that big a deal. However, when you adjust to it, it’s like the difference between using a pen and paper and a computer.

So, where is Vim and how do you access it?

Vim is accessible in your terminal too.

Type vim <filename>

In this case, I type vim stack.js. This brought up a file that I created in javascript for a stack program. The great thing is that you can do this for any file, even text files, which makes Vim a great way for you to write the next great American novel.

When you get in the file, to move around you use…

  • j to move down
  • k to move up
  • h to go left
  • l to go right

If you want to move multiple lines at once just put a number in front of it the key, so 9 then J to move 9 lines down or 99 then k to move 99 lines up.

You can also search for words and symbols by accessing the command line.

press : that will take you to the command line.

then type: ?<word or symbol>

then use n or N to move about looking for occurrences of the search.

Editing with Vim

Now, that you’re moving around, it’s time to show you how to make changes to the content of the file.

The first thing is how to delete lines. Get on the line you want to delete and hit dd. If you hit the wrong line, then bring it back with u, which stands for undo. That going to be a pretty important one. Also, ctrl + r, is redo.

dd also cuts a line, and you can use p to paste the line.

yy will yank or copy a line and then you can use p to paste the line.

Here’s a cheat sheet I found to get you started…

Saving or Quitting without Saving

I really hope you made this far, because this is probably the most important part of the article.

If you don’t know how to do this, you really will be frustrated with Vim.

To quit, save, or quit without saving you need to access the command line, with :.

q will quit the program.

q! will quit the program without saving

w will save the program

wq will save and quit.

These basic commands are great way to improve your speed and make your computer experience better than before. All you have to do is practice for a week and you’ll get the hang of it.

After that, you should look into making your Vim experience better. You can fully customize it and there are a ton of ways to do it. You can make Vim your own and I’m slowing making it more and more my dream editor.

--

--