Live Chat!

commenting your source code with combo keys in vim

* * * * * 1 votos

May 31st, 2007 mysurface

When I saw my colleague commenting his lines of source code with some special combo key in VC++, I would like to do that in vim too. Vim is great that it is highly flexible to extend features with your own define key combos.
Vim by default bundle with many default key bindings, fortunately you can [...]

Posted in Text Manipulation, vi, vim | Hits: 17231 | 5 Comments »

Printing in vim: Using programs other than the default lpr

* * * * * 1 votos

May 25th, 2007 Felix Leong

Printing in vim is as easy as entering the :hardcopy (or its shorthand equivalent :ha), that command is equivalent to creating a temporary Postscript file and passing it through lpr.
But what if you want to modify the printing behaviour of vim? Say, printing 2 pages on a page using the a2ps command?* Luckily that can [...]

Posted in vim | Hits: 15095 | 4 Comments »

Save typing using vi abbrevations

* * * *   1 votos

May 11th, 2007 Felix Leong

Do you find yourself typing some long text too often that it’s getting tiresome (especially when it comes to hard to remember and long email addresses)? Or that you are so bad at remembering today’s date that you have to fumble through the calendar before you are able to type away?
If you are using vi, [...]

Posted in vi, vim | Hits: 18373 | 2 Comments »

CLI magic: programable bash completion

* * * * * 3 votos

May 4th, 2007 mysurface

Ubuntu, a Linux distribution that is getting popular because it has successfully improves it’s user friendliness with simple User interface. You can install any applications with few clicks, configuration under GUI dialogs etc. People usually have the thinking of maybe one day, Ubuntu will become another new operating system like Microsoft Windows.
Never! The concept of [...]

Posted in Bash, apt-cache, apt-get, complete, pipeline, sort, svn | Hits: 32526 | 5 Comments »

Sort grep -c results

          0 votos

April 17th, 2007 toydi

grep -c “TODO:” *.c

foo.c:1
bar.c:0
spam.c:44
egg.c:32
matrix.c:0
grep -c displays the total count of matching lines for each input file, just like above.
Now, to sort the results by total count:
grep -c “TODO:” *.c | sort -nt: -k2

bar.c:0
matrix.c:0
foo.c:1
egg.c:32
spam.c:44
It sorts the list by total count or the 2nd field (-k2) by comparing them as numbers (-n). Don’t forget to [...]

Posted in Text Manipulation, grep, sort | Hits: 17071 | No Comments »

Squeeze multiple blank lines to one

* * * * * 2 votos

March 10th, 2007 toydi

Documents like RFCs may contain many blank-line blocks.
To save the trees, i always squeeze multiple blank lines down to single blank line, before printing.
Once I did this manually (yes, it’s like hell), but now I use cat -s:
cat -s rfc2324.txt | tr -d ‘\\f’ | lpr
I use tr -d to remove any form feed character, [...]

Posted in Text Manipulation, cat, lpr, tr | Hits: 11626 | No Comments »

Convert newline between UNIX & DOS

          0 votos

February 10th, 2007 toydi

There are several ways to convert newlines between UNIX-style (LF) and DOS-style (CR+LF).
I like todos, fromdos commands (or unix2dos, dos2unix) for their simplicity. Sometimes they are not installed by default, try to search your repository for a tofrodos package .
Let’s try. Simply create a text file, foo.txt that contains a newline:
aaa
bbb
A UNIX newline (LF) is [...]

Posted in Text Manipulation, fromdos, hexdump, todos | Hits: 13247 | No Comments »

vim tips, goto line

          0 votos

February 10th, 2007 mysurface

If you have search for vim tips at here, you may remember to go to the desire line while opening file with vim is like this
vim hello.c +12
And while edit with vim, to move to desire line, type the line number and press shift g or G. With the search forward and backward tips examples [...]

Posted in Misc, Text Manipulation, vi, vim | Hits: 10768 | 2 Comments »

Remove all .svn directories at once

* * * * ½ 2 votos

January 19th, 2007 toydi

When you check out a project code base from a svn repository, each downloaded directory (from top to the deepest) contains a .svn hidden directory that keeps svn’s necessary metadata.
If you want to remove them all at once, here’s one way to do it:
~/project_dir $> find -name .svn -print0 | xargs -0 rm -rf
find [...]

Posted in Common, find, rm, xargs | Hits: 21206 | 5 Comments »

disable text wrapping at vim

* * * * * 1 votos

January 3rd, 2007 mysurface

vim wrapping the text by default. When a line is exceed the width of your viewable screen, the text will be wrap to next line. Sometimes, it is messy. Especially when you read the log file with many columns.
To disable wrapping in vim
:set nowrap
You can write that to ~/.vimrc, so that it will disable [...]

Posted in Text Manipulation, vi, vim | Hits: 13722 | 1 Comment »