Welcome on DL4UNY's Radio-Page!



About me

I started to write my own How To's not to show the world what a geek I am but to help myself after a system reset or for faster configuring a new machine :-)

short introduction to vim
use vim as HTML-Editor
screenshot without x
change encoding of a text-file
convert mp3 to wav
analyzing data with gnu plot
replace a string in a text-file





Short introduction to vim
vi is the part of almost every unix-system (as far as I know) - but what's so special on it?
I like the vi, even without the add-ons and plug-ins and all the fancy stuff. It's quite comfortable to use, for example your fingers don't have to leave the main-keys for scrolling up and down, you can do it with the h-j-k-l-keys. Why? Ha, because the vi has different modes (visual, editing, command). So you need less short cuts than on other editors.
But I like it because I grew up 'in a terminal world'. Even now I don't like working on a graphical surface that much, I'm still using centerim, mutt, w3m and vi(m) :-). So let me tell you how to use this powerful tool. You can make it even more powerful by installing add-ons (e.g. from www.vim.org).

vim filestart vim and load the file
vim +n filestart vim, load a file and go to line n
vim + filestart vim, load a file and move the cursor to the end of the file
vim file1 file2start vim and load file1 and file2
vim -R fileopen the file in read-only-mode
:w'work' - Save the file (press Esc to leave edit-mode)
:w!force saving, even if the file loaded with -R
:w new_namesave the file with new filename
:wq'work and quit' - save file and exit vim
:q!force quit, don't save changes
iinsert-mode
oinsert empty line and change to edit-mode
0go to begin of the line
:0go to begin of the file
:ngo to line n
:$go to end of the file
$go to end of the line
wgo 1 word ahead
bmoving cursor 1 word back
)go to next sentence
(go to sentence before
}go to next paragraph
{go to paragraph before
Jremoves linebreak at the end of the line
xdelete the sign which is highlighted by the cursor
dwdelete the word
d n wdelete the nex n words
Ddelete all from present cursor position to the end of the line
d^delete all from present cursor position to the begin of the line
dddelete the present line
n dddelete the next n lines
venter visual mode
h-j-k-lmove your cursor, in v-mode you can mark the text
ycopy the marked text
ppaste the copied text
uundo (last command)
Uundo (on one line)
.repeat last command
~changes small and capital letters




Use vim as HTML-Editor
vim is my favourite editor for almost everything. I write all my code, mails, letters... with it :-) Here I want to show you how to improve your vim (so it turns into a vim+ hahaha) for html.
Just a few steps and you've a high quality html-editor on your machine, look at this screenshot


first, we need to get some stuff:
$ wget -c http://dl4uny.de/vim-addons.tar.gz a package with useful tools, I collected them from www.vim.org
and added some gimmicks to the html-files

$ mkdir ~/.vim & & mv vim-addons.tar.gz ~/ & & cd ~/.vim & & tar -xvf vim-addons.tar.gz
$ vi ~/.vimrcYou need to do some config-work...


Okay, first we have to do in vimrc is:
syntax onenables syntax highlighting
filetype plugin indent onvim knows what files we are editing
set numberso we can see the line numbers
au FileType html,xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vimfor using the close-tags
map :set nospell!:set nospell?to use spell-checking with F7


Now you can try your new html-editor: $ vi test.html
type doctype, followed by pressing tab, next line: type html and tab etc. :-)



Make a screenshot without x
Something's wrong with your X-server or you are working on a machine without X installed but you want to make a screenshot? No problem, just type
# screendump > /tmp/shot1.txt
now check your screenshot
# cat /tmp/shot1.txt




change enconding of a text file
To change a text file e.g. from utf-8 to ISO 8859-1 you can use the powerful conv-command:
iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt




convert a mp3 to a wav
Sometimes you need a wav-file, for example to test your device is working or not. You can use mpg123 :-)
mpg123 -w file.wav file.mp3




Short introduction in gnuplut
gnuplot is a very powerful data-analyzing-tool. It can be used for almost every kind of plots. Here's a small list of things I always forget...
First you need any input data, for example a simple textfile. gnuplot is happy with a column vector, BUT you have to include the x-variables, also! For example:

11
25
38
514.3
92
114
11.71.4

etc.
After calling gnuplot you can plot this file with
> plot "file"

If you want to plot to or more vectors on the same graph you just have to append the second filename, like
> plot "file1" "file2"

To discern the different types of plotted vectors you might want to use a different plotting style. This is possible with
> plot "file" with STYLE
where STYLE stands for lines, dots, linespoints, points, errorbars and impulses

To label the axis and donate a title of the graph you can add
> set xlabel "string"
> set ylabel "string"
> set title "string"

Okay, now you've a great plot on your screen, but how to get a printout? No problem, just set the terminal
> set terminal TERMINAL
where TERMINAL stands for jpeg, fig, x11, postscript or even latex

to set a filename for the plot just type
> set output "outfile.jpg"

More information get with the very detailed help-function of gnuplot. Just type e.g.
> help terminal
and you'll see all possible options. A very useful page can be found here:
GNUplot - not so frequently asked questions



Replace a string in a textfile
sometimes you need to replace a general string in very large text-file. I want to show you two ways to solve this problem:

with vi
it's very easy doing it with vi:
vi file
:s /string/replacement
for explame :s /1234/abcd will replace all "1234" in the present file with "abcd"


the second way is the way I prefer: using sed
sed "s/string/replacement/" infile > outfile
for example sed "s/1234/abcd/" numbers.txt > letters.txt will replace all "1234" in the file 'numbers.txt' with "abcd" BUT it will create a new file. So you still have the old one :-)