Select the block of text:
1. Position the cursor at the beginning of the text you want to replace
2. Press v to enter visual mode. (or upper case V to select whole lines, or Ctrl-v for a vertical block).
3. Move the cursor to the end of the text to be replaced. (While selecting text, you can perform searches and other advanced movement, a feature that sets vim apart from most other editors.)
4. Press c. This deletes the selection and leaves you in insert mode.
5. Type your replacement text.
The selection is done in visual mode.
To cut (or copy) and paste using visual selection:
1. Position the cursor at the beginning of the text you want to cut/copy.
2. Press v to begin character-based visual selection (or upper case V to select whole lines, or Ctrl-v for a vertical block).
3. Move the cursor to the end of the text to be cut/copied. (While selecting text, you can perform searches and other advanced movement, a feature that sets vim apart from most other editors.)
4. Press d (as in “delete”) to cut, or y (as in “yank”, which I imagine meaning “yank so hard and fast that it leaves a copy behind”) to copy.
5. Move the cursor to the desired paste location.
6. Press p to paste after the cursor, or P to paste before it.
Bonus Tip: To replace the selected text with new text (to be entered by you), press c instead of d or y on step 4. This deletes the selection and leaves you in insert mode. Then, instead of (or prior to) steps 5-6, type your replacement text.
Recording is a really useful feature of Vim.
You start recording by pressing “Q” key followed by any other letter keystroke, and you can end it by typing “Q” again.
It records everything you type. You can then replay it simply by typing “@“ followed by the letter.
Record search, movement, replacement…
This is one of the best features of Vim.
One more thing to note is that you can hit any number before the “@“ to replay the recording that many times like (100@<letter>) will play your recorded actions 100 times.
To close a file, use the fclose() function.
int fclose( FILE *fp );
The function flushes any data still pending in the buffer to the file, closes the file, and releases any memory used for the stream’s input and output buffers. The fclose() function returns zero on success, or EOF if an error occurs.
When the program exits, all open field are closed automatically. Nonetheless, you should always close any file that you have finished processing. Otherwise, you risk losing data in the case of an abnormal program termination. Furthermore, there is a limit to the number of files that a program may have open at one time; the number of allowed open files is the value of the constant FOPEN_MAX.
To check out this value. we can do :
printf("Max # of open files = %d\n", FOPEN_MAX);
The program returns 16 on my platform.
Manipulate the nth bit of a int a
- get bit:
- a>>n & 1
- set bit:
- 1<<n | a
- clear bit:
~(1<<n) & a
By default, you can select an option from the auto-completion list by hitting Enter. But when the choosing dialogue pops up automatically, sometimes you just want to type a line break instead of choosing one from the list.
And when you hit Enter to type a line break, you get a completion selected instead.
So this could be very annoying.
Continue reading “Sublime Text 2 Trick: How to change the default auto-complete commitment keystroke to Tab”
Found a few videos just to give you a snapshot of the rich features of Sublime Text 2.
Continue reading “The best text editor ever: sublime text”
There are times that we just want to hide an element first, and shows it later when the user performs something like clicking on a button.
The strategy is to place the controlled element on a hidden layer (
div), and then change the
display attribute to make it show up.
Download and try the game at the end of the page.
What is Scheme:
Scheme is a functional programming language developed at the MIT AI Lab by Guy L. Steele and Gerald Jay Sussman, who introduced a thing called Lambda.
This language is applied to teaching students programming theories at MIT, and then is now used in may universities around the world.
Scheme IDE can be downloaded here. (It is now named “Racket”)
The Scheme Programming Language is a good book to begin with for self learning.
High level description:
Our ship is a fairlly big sized pink square,
whose posn is our mouse position.
The objects come from random position of four sides
Colliding with the following objects will have the following effects.
1. .(good): hitting one of these will give you points;
2..(better): hitting this will give you an even bigger points bonus
Continue reading “A Scheme Game Project from two years ago”
freopen("/dev/tty", "a", stdout);