I was looking into configuration files for Vim today. I tried to read through them without using VS Code but it wasn’t easy.
TLDR;
Okay, so here are the highlights of what I did:
- Looked into Vim config files and watched a few videos on dot files in general.
- Learned how to run terminal commands in the background of the terminal. This was spurred by my desire to open a new terminal from within my current terminal.
- Practiced using Vim alone. Honestly, it sucked. The biggest issue I had was the syntax highlighting. It was very particular which frustrated me.
Vim Progress
I tried to be brave today and only use Vim from the terminal without openeing VS Code. Let me tell you first hand that it sucked. I was editing my notes which I usually write in Markdown. The syntax highlighting was there but it was lacking for sure. Additionally, the custom code snippets I wrote for myself in VS Code were no longer available which made things that much slower. I am adjusting overall to using Vim but I am still far from comfortable using it as a standalone code editor. Maybe, after I get more comfortable with the terminal in general, I might have a chance.
How to Run a Terminal Command in the Background
Since I was trying to use Vim alone with VS Code, I figured I should have more than one terminal window open. However, here’s the catch… How do I open a new terminal inside of the existing terminal?
Well we can just execute the program again… Close but now the terminal that you used to run the command to start the next terminal is linked and logging STDOUT
and STDERR
.
So here is the trick. For myself I am on a Windows PC so I’m using Git Bash (don’t judge):
/git-bash.exe & > /dev/null/ 2>&1
# or
/git-bash.exe & &> /dev/null
The key parts are:
/git-bash.exe
is the executable we need to run.- The first
&
after the command (git-bash.exe
) tells the terminal to run the command in the background. >
,2>&1
,&>
are different ways to redirect theSTDOUT
andSTDERR
of a program. In our case we are throwing away the output since we don’t need it.
This actually helps me with a few other programs. I have had the issue that executing some programs from the terminal leaves the terminal useless while it outputs info from the program I started. I still lack a complete understanding but this was definitely a step in the right direction. Here is the table from my notes on Input and Output Redirection in the shell.
Shell operator | Description | Overwrite existing file? |
---|---|---|
command > output.txt | Save terminal output (standard output) to a file named output.txt | Yes |
command >> output.txt | Append terminal output (standard output) to a file named output.txt | No |
command | Takes standard input from output.txt file | N/A |
command 0 | Takes standard input from output.txt file | N/A |
command 1> output.txt | Puts standard output to output.txt file | Yes |
command 1>> output.txt | Appends standard output to output.txt | No |
command 2> output.txt | Puts standard error to output.txt | Yes |
command 2>> output.txt | Appends standard error to output.txt file | No |
command &> output.txt | Puts both standard error and output to output.txt | Yes |
command > output.txt 2>&1 | {POSIX} Puts both standard error and output to file named output.txt. 2>&1 tells the error output ( 2> ) to go to the same place the standard output is going ( &1 ). | Yes |
command &>> output.txt | Appends both standard error and output to file named output.txt | No |
command >> output.txt 2>&1 | {POSIX} Appends both standard error and output to file called output.txt | No |
command | tee output.txt | Puts standard output to output.txt while displaying output on screen | Yes |
command | tee -a output.txt | Appends standard output to output.txt while displaying output on screen | No |
command |& tee output.txt | Puts both standard output and error to output.txt while displaying output on terminal | Yes |
command 2>&1 | tee output.txt | {POSIX} Puts both standard output and error to file named output.txt while displaying output on terminal | Yes |
command |& tee -a output.txt | Append both standard output and error to file called output.txt while displaying output on terminal | No |
command 2>&1 | tee -a output.txt | {POSIX} Append both standard output and error to file named output.txt while displaying output on terminal | No |
command & | The & makes the command run in the background. | No |
command && | The && executes the first command and conditionally proceeds to the second if it exits with success. | No |
Conclusion
That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!