HomeОбразованиеRelated VideosMore From: theurbanpenguin

BASH Scripting Lesson 2 - using code snippets in vi and mapping keys

141 ratings | 21830 views
More videos like this online at http://www.theurbanpenguin.com I tnis video we are going to be unlocking the power off vi and seeing how we can create and use a code snippet library for vi. Vi supports reading in files :r~/snippets/if would read into the current file the if snippet. Of course we have to create the code snippets but once done that act as a great code repository to use with vi. Moreover vi can not just read in files but it can read the output of commands. We can add date stamps to our file using :r!date the exclamation mark saying we will execute a file to produce the input to read. The command date on its own is ok but has the full date and time, we probably want something like date +%x to output just the date. If we run this is vi though the % has a special meaning, (the filename) and will not work. We just have to escape the % as \% then all is fine. To bring it all toghetr we can map keys to the functions that we want.
Html code for embedding videos on your blog
Text Comments (26)
Chen Bai (6 months ago)
what is map?
hokage white (1 year ago)
hi just to let you know even this videos are old im enjoying watching it and its easy to follow :) thank you for the content <3
Tom B (1 year ago)
Brilliant tutorial--one of your best, along with the shared libraries video. I would agree about the blue comments on the black background, in terms of being marginally readable. But that's a very small price to pay for the knowledge you are passing on sir. Love your videos!
Vagelis Prokopiou (1 year ago)
Just awesome....
rot rose (1 year ago)
I am a great fan of theurbanpenguin, I hope I could have reached your page sooner. It is amazing you share all your unbelievable extensive Linux knowledge to everyone. I hope this project will go on and on, thank you.
Peter Muia (2 years ago)
I am unable to map F2 key and others because on my Toshiba laptop, these keys have additional functions like dimming the screen; increasing or decreasing voice/audio. Any suggests on how to resolve this issue.
Kristian Kirilov (2 years ago)
I think you can switch the keys to functional and to normal by pressing "fn" button. Am I right?
Francisco Parada (2 years ago)
Well done
lmind2 (2 years ago)
Agree with Jon Edwards.  Maybe in vi, do :color desert so it's more readable with a black background.  Real tough to read dark blue on black.
Cody Aldaz (3 years ago)
HAHA its July 2nd and my $LANG=en_US date +%x 07/02/15
Ivan Ivanov (4 years ago)
best ever
Jon Edwards (4 years ago)
these are excellent lessons, and I'm enjoying the pace (while I do programme, i come from a GUI/IDE background so learning vi is a bit of a crash course!) One minor note, your # calls (e.g. #!/bin/bash etc.) are set to the default navy blue making it very very hard to see on youtube. you may wish to modify this colour on later tutorials. 
Stephen Joe (4 years ago)
Good on yaaa Andrew !!!
Kevin Thomas (4 years ago)
Good work Andrew.
daveshomestead (4 years ago)
Wow great lesson! Thank you!
theurbanpenguin (4 years ago)
Thank you
Joe Riggs (5 years ago)
I figured it out, for some reason it does not work in double quotes for me. I have to use single quotes for that command in vi. r!date '+\%x' Not sure why, I'm running Ubuntu 13.04
Joe Riggs (5 years ago)
I AGREE! It is nearly impossible to see any of the Blue Text on your screen, if you could change that terminal preference before you do the videos. That would be epic man. Thanks.
Joe Riggs (5 years ago)
A bit of help: In vi, when I type... r!date "+\%x" vi comes back with this error: "/bin/bash: +%x: command not found" Yet in terminal when I do date +%x it works just fine. Any thoughts?
Anil Singh (5 years ago)
Sorry man, scripts were hardly visible, is it possible for you to have contrasting back and fore ground.
DoodahGurl (5 years ago)
Hi, Andrew. Thanks for these great videos. Is it possible for you to put the Bash scripting lessons into a playlist? Thanks!
DoodahGurl (5 years ago)
You show some really interesting stuff...but can I ask that you change the color in vi so the dark blue stands out more against the black background when you comment in vi? Thanks!
enthusiast93 (5 years ago)
why do you use vim? it has to be the most difficult editor out there! besides emacs
k3v1l (5 years ago)
Thank you Andrew!
thillaust (5 years ago)
That was fantastic, i did not now about those vi commands. Thank you
Vladimir Kuznetsov (5 years ago)
Very useful lecture, thanks! Andrew, use "set background=dark", please!

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.