Squeeze multiple blank lines to one

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 [...]

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

Convert newline between UNIX & DOS

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 [...]

Posted in fromdos, hexdump, Text Manipulation, todos | Hits: 38572 | 1 Comment »

vim tips, goto line

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 [...]

Posted in Misc, Text Manipulation, vi, vim | Hits: 38537 | 3 Comments »

Remove all .svn directories at once

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 [...]

Posted in Common, find, rm, xargs | Hits: 66023 | 8 Comments »

disable text wrapping at vim

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 [...]

Posted in Text Manipulation, vi, vim | Hits: 63675 | 4 Comments »

cut and paste source code to console

January 2nd, 2007 mysurface

If your vim have auto indent enabled, you may facing this problem. Vim are too smart to help you indent copied source code, and the comment line will kill your pasting very much. I usually do copy and paste source code from ebook or web page to a file so that I can compile and [...]

Posted in cat, Text Manipulation | Hits: 68540 | 15 Comments »

Print color text in command line.

December 24th, 2006 mysurface

Sometimes echo is not enough, if you need to print more advanced format of text. Lucky, we have printf. printf is a common function call in c programming language, if you learn c before, you should very familiar with this function. Simply illustrate the power of printf, do as follow: printf ‘\n\t\thello\tworld\n’ Besides readable character, [...]

Posted in clear, printf, read, Text Manipulation | Hits: 153535 | 19 Comments »

search next or backward and goto line tips for vim

December 16th, 2006 mysurface

To search in vim is very simple, even a noob vim user know that, /keyword To search for next? simply follow by pressing n for next keyword match point and search backward with shift+n or N. Wanna highlight the keyword and search for next keyword match point? Place your cursor at the desire word, and [...]

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

vim with ctags

December 10th, 2006 mysurface

If you are c/c++ programmer and vim user, maybe know ctags. Most of the time, source code are distributed to many folders and each of them consist of numbers of .cc/.c and .h. Sometimes to search the definition of a function, class, enums etc by using “/” is inefficient. ctags allow fast jumping to function [...]

Posted in ctags, Developer, ln, vi, vim | Hits: 152414 | 23 Comments »

regex in vim to clear the trailing character

December 6th, 2006 mysurface

Sometimes, the file created at windows may tag alone the trailing character at the end of every line, where user press enter. It may shows as ^M. It is very irritating! to clear it off is very easy in vim. :%s/\s*\r*$// %s is global search, change effect on every lines, \s is space \s* is [...]

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