Xargs is one of those commands I have never used. Recently I was looking into how I can use them in the scripts I use on a daily basis.
Here are some. These are for personal references. If you find it useful. Please go ahead and use them.
xargs, was actually used to get over the limitations of the number of arguments that a certain command can handle. But then it has been used for other purposes as well now I guess.
ls somefilepattern | xargs can convert the list that would have been displayed vertically into a list that is displayed on a single line seperated by spaces, since it is actually converting it to an argument list for some command. This can be a really useful oneliner.
- When you want it to act as an argument list for some command then
ls somefilepattern | xargs command will do. What this is doing is that it is taking a list of those files, converting them into an argument list and passing it to the command. Good!
- A good derivation of the last two points is that it can be used with commands like the cut command to get some vertical list, which can then be passed on to a command or just convert it to a oneline list. Ex:
ls * | cut -d "." -f1 | xargs
They say it is mostly used with find command but then I cannot relate to those uses.
Shell commands can be executed inside vim. You can use ! after the : and type in your command. You need to know just one more thing and you can be off. The current file is specified by the % character. For for example, if you want to find the word count of the current file, type in,
:! wc %. If you want for example to execute the script you are writing then
:! bash %, will run the current bash script you are writing. The display will momentarily go out of vim to display the results but will be back to vim as soon as you hit Enter.
Although I am typing this blog post on vim with html. I sometimes do not use Vim. I am all around the place with Atom sometimes, or Gedit or pluma or Visual Studio Code sometimes. But then I come back to vim for the simplicity of things. When I do, i sometimes forget what i need to know to get back to my old Vim state. This one is for me to read this blog post in two minutes and getting back to work.
I don’t think i have to say what mode these commands have to be used in.
i to insert text
Esc to exit edit mode
v for visual select
shift + v or
V for visual lines
ctrl + vfor visual block
y to yank/copy
x to cut/delete
p to paste on the next line.
shift + p or
P to paste right where the cursor is.
:w to write
:q to quit
:wq to save and quit
:e filename to open a new buffer with file specified
:ls to list all the buffers. # is the previous buffer. %a is the active buffer
:b buffernumber to switch to that buffer
:b # to switch to the previous buffer
:bd buffernumber to delete a particular buffer.
u to undo
This should be enought to get you going.
This is meant to be a quick revision of very basic Git commands for me. I am not yet a fully functional software developer at the moment. I do not use a lot of Git. But then i do rarely, once a year maybe for some small project?, and, this can be good starter for me.
git init to initialize a repository in a folder.
git status to know the status of what is staged, what is modified and such.
git add filenames to stage those files.
git commit -m "Commit Message" to commit staged files with a commit message.
- List files that need to be excluded when staging whole folders maybe, in
.git/info/exclude. Can be used for temporary files and media files maybe.
git rm --cached filename to remove a file from being monitored by git.
That should get you started dear future me! 🙂
Sometimes I write scripts without the usual extension “.sh” or “.scr” as some people do. I am also writing this blog post on vim on just a text file. But i use html tags on it. I don’t like the text file to have the “.html” extension on it. So i manually turn on the syntax highlighting. Vim also picks up the syntax from the shebang line, but this is for cases when even that isn’t present.
Pretty simple this one.
:set syntax=html or what ever your code is. Done!
In this post I want to talk about two things that I loved about Banshee the media player for Linux. Let me start off by first saying that I hate rhythm box. I cannot put my finger on it but it is bad. So I uninstalled it long back. I have been using VLC media player for everything from music to videos. It was pretty good but I still felt something was lacking. So I recently installed Banshee, I love it. But let me start off with two things for this post.
- The list of options you get when you right click on the task bar icon. My personal favorites?. “Stop when finished” and “Rating”. Stop when finished, is a great option. You want to stop listening to music and concentrate on your work but you just want this one beautiful song to end. Next, When you have a huge music database. You would like to rate those songs every now and then so that one fine day when you just want to listen to those top rated songs, it is easy. Well, the rating option is right on the task bar menu.
- The second thing I love about this are the shuffle options. Shuffle by either Song, Artist, Album, Rating or Score. Wow. Even the very best of audio players does not have that.
So there you go. Two really good features.
If you want to work with multiple files at the same time and if you are new to vim you might not know what buffers are about. They’re really useful. Here is a short blog on how to use them.
- When you start vim you can start with multiple file arguments in the first place. Then all of them are opened together in different buffers.
- When you want to open another file as another buffer you can say,
- You can say
:ls to list the active buffers. They are ordered and numbered.
- You can use the list number of the buffer to switch to that buffer, by saying
:b #. Replace # with the number.
- You can also switch using the file name by saying,
:b filename/path. Partially filling the name of the file and pressing tab also works.
- To delete a buffer say
:bd #. As previously mentioned, replace # with the list number. You can also use the filename/path.
- Before you can switch from one buffer to another it needed to be saved by saying,
:w. Not sure if this can be changed in some global settings.