2010-08-18 15:53:02
Vim tips
Almost 4PM...time for some vim tips. :-)
- autocmd
Vim's powerful autocmd feature can be used to automatically perform certain commands when a specific event occurs. The events that can be used as triggers range from creating a new file to resizing vim's window. A complete list of available triggers can be obtained by typing :help autocmd-events in vim. So, how's this useful?
Let's say you write most of your Perl scripts in vim, why should you insert the shebang and some other stuff manually in a new file, when the editor can do this for you? The following two steps show you how it's done:- Create a new file ~/.vim/skeletons/skeleton.pl containing a
shebang for Perl as well as the recommended use strict/warnings
statements:
p=$(which perl); mkdir -p ~/.vim/skeletons; cat << EOF > ~/.vim/skeletons/skeleton.pl #!$p use strict; use warnings; EOF
- Put the following in your ~/.vimrc
autocmd BufNewFile *.pl 0r ~/.vim/skeletons/skeleton.pl | :normal G
- Create a new file ~/.vim/skeletons/skeleton.pl containing a
shebang for Perl as well as the recommended use strict/warnings
statements:
- Syntax check
Everyone knows about vim's :make command, but did you know that it's possible to set the make program for each file type separately?autocmd FileType perl set makeprg=perl\ -c\ %\ $*
By adding this to your ~/.vimrc, :make will no longer invoke make file but perl -c file instead, when you're editing a Perl script. As usual, Perl is just an example - i.e. Ruby programmers might use ruby -c or the like. - Y?
There's some inconsistency between deleting and yanking in vim:
dd deletes the current line, D deletes from the cursor to the end of the line.
yy yanks the current line, but Y also yanks the current line...
To yank all characters from the cursor position to the end of the line, you either need to type y$, or add a custom mapping for Y to your ~/.vimrc:map Y y$
- Matchit
- Typing % in normal mode finds the next item in the current line or under the cursor and jumps to its match. Items include c-style comments, parenthesis and some preprocessor statements. Unfortunately, there's no native support for HTML or Latex, but there's a handy little plugin, that adds support for these and many other languages: Matchit.
2010-07-24 17:10:36
yaydl 1.5.2
yaydl 1.5.2 fixes the
support for youtube....
2010-07-20 22:08:42
Bandwidth monitors
There are many tools available, that allow you to monitor (among
other things) the current downstream of your internet connection.
Some of them, like dstat and bwm-ng are
handy console applications, whereas others integrate nicely into
your desktop. Two popular examples for this would be conky or gkrellm.
So, in general there's no real need for the following bash
one-liner, unless you're just an ordinary user working on some
poorly equipped linux box which doesn't offer any of the tools
mentioned above. In that case, you'll be glad to have a dirty
solution like the following available:
r=$(cat /sys/class/net/eth0/statistics/rx_bytes) ; while [ 1 ]; do n=$(cat /sys/class/net/eth0/statistics/rx_bytes); d=$(((n-r) / 1024 ));r=$n; echo "$d KB/s"; sleep 1;done
There is no need to mention,that eth0 must be replaced by your primary interface's name.
2010-07-18 21:24:27
Remove Exif data
Sometimes it's advantageous to remove Exif metadata from image files, for example when posting images online. Fortunately, that's not a big deal since we're using linux:
mogrify -strip image.jpg...or if you want to process more files:
mogrify -strip *.jpg
2010-04-21 00:40:45
Linux, mplayer and the ZDF Mediathek
While the idea behind the ZDF Mediathek is
not so bad at all, the actual implementation is a pain in the ass -
especially the flash version of the website, which causes my
Firefox to crash again and again...
So I tried the HTML version of the site, which has two major
advantages:
1.) Firefox doesn't crash anymore and
2.) one can watch the videos with any external program like vlc or
mplayer.
However, there's still a huge drawback: The videos are streamed via
the Real-Time
Streaming Protocol or the Microsoft
Media Server Protocol, so basic operations like
fast-forwarding, rewinding or pausing should be avoided.
Additionally, as no (significant) buffering is performed, your
internet connection will be in use for the whole runtime of a
video, limiting other online activities.
Looking for an easy solution for this, I checked mplayer's manpage
and found the -dumpstream option. The rest was some
elementary bash scripting:
mplayer -dumpfile "$(date +%y_%m_%d_%H_%M.dump)" -dumpstream "$(curl -s "$(curl -s "$LINK" | egrep "<li>DSL\s*2000\s*<a href=.*asx" | sed -r 's#.*href="([^"]+)".*#\1#')" | egrep -o 'mms://[^"]+')"This will save any(?) video from the Mediathek to a local file called *current_date*.dump. If you didn't figure it out by yourself, $LINK must be set to / replaced by the actual URL pointing to your video (you'll need the URL to the HTML version, or do some additional preprocessing first).
Before you ask: Of course I wrote an easy-to-use, ready-to-run script for this - it even does some limited error checking. It can be found here.
Update: Seems like this only works for just a few videos, so don't be too disappointed if it fails...
2010-04-10 21:40:47
yaydl 1.5.1
Version 1.5.1 comes with support for video.golem.de (ok....not
as big as youtube, but who cares...)
BTW: If you want to be informed about new versions without reading
my blog (shame on you!), you might want to subscribe to yaydl on
freshmeat.
2010-04-08 00:33:29
yaydl 1.5
2010-04-02 16:25:01
yaydl 1.4.5a
Still a alpha version, but youtube works again!
2010-02-15 00:20:45
yaydl 1.4a
It's already been more than one month since I released yaydl
1.3.7, so it's time for a small status update. The attached preview
of the upcoming release already includes two main new features:
support for playlists and 1080p videos on Youtube. Please note that
these improvements aren't fully stable yet and might include some
bugs - so if you're a fan of rock-stable software, keep your hands
off this alpha ;-)
2010-02-02 21:26:50
Lyrics fetcher for moc
As the newest alpha version of moc comes with the ability to display
song lyrics, I thought it might be a nice feature to fetch these
lyrics automatically. So I just cobbled together a few lines perl
code, that actually work pretty well. Nevertheless it's just a
quick hack with a lot of bugs, so don't expect too much.
:-)
2010-02-01 20:05:39
HowTo: Convert Windows-style line endings to Unix-style (and vice versa)
Though there are some tools (e.g. dos2unix) available to convert
between DOS/Windows (\r\n) and Unix (\n) line endings, you'd
sometimes like to solve this rather simple task with tools
available on any linux box you connect to. So, here are some
examples - just pick the one that fits you best:
Windows to Unix:
#Shell perl -pe '$_=~s#\r\n#\n#' < windows.txt [> linux.txt] sed -r 's/\r$//' windows.txt [> linux.txt] #Vim :%s/\r$// :set ff=unix
Unix to Windows (do you really want this?)
#Shell perl -pe '$_=~s#\n#\r\n#' < linux.txt [> windows.txt] sed -r 's/$/\r/' linux.txt [> windows.txt] #Vim :set ff=dosDon't forget to save your file, when you're using vim.
2010-01-06 21:19:48
yaydl 1.3.7
A new year - a new version of
yaydl. Apart from the usual bugfixes, one new feature found its
way into this release: From now on, yaydl has direct support for
inputfiles, which renders the workaround via shell I/O redirection
obsolete. As always, the commandline option for this and all other
functions can be found in the readme file. ;-)
2009-11-04 20:58:30
yaydl 1.3.6
After so many people asked me to waste some more blog entries on
yaydl, I eventually found some spare time to comply with their
request. ;-)
However, if you were expecting some fancy new features, don't get
too overexcited: v1.3.6 is just another bugfix release. Yet, I'm
confident I'll extend yaydl's functionality till autumn 2010.
:D
