December 2009
4 posts
1 tag
Restore Cursor Position
Add the fallowing line to your .vimrc and when a file is opened, the cursor will be positioned to the same line it was left on, when this file previously was closed.
1 autocmd BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
3 tags
String Aggregation
Say you have the following data and you want to concatenate all queries for each year.
1 CREATE TABLE years (year smallint);
2 INSERT INTO years VALUES
3 (2008),
4 (2007),
5 (2009);
6
7 CREATE TABLE top_queries (year smallint, place smallint, query varchar(50));
8 INSERT INTO top_queries VALUES
9 (2009, 4, 'twitter'),
10 (2008, 2, 'beijing 2008'),
11 (2008, 9, 'euro...
1 tag
Autocompletion
Vim has quite a few features for automatic text completion. The most basic is keyword completion - 1) open a file, 2) write first few characters of any word you see in the file, 3) hit CTRL+N to automatically complete the word. Simple, easy to use and very useful.
To make this feature more intuitive, consider mapping CTRL+Space to CTRL+N:
1 inoremap <C-Space> <C-n>
2 inoremap...
3 tags
Generating a Range of Values
For example, lets generate a set of months, from 2010-01-01 to 2011-01-01.
In SQL Server:
1 WITH t AS (
2 SELECT CONVERT(date, '2010-01-01') AS d
3 UNION ALL
4 SELECT DATEADD(MONTH, 1, d) FROM t WHERE d < '2010-12-01'
5 )
6 SELECT * FROM t ORDER BY d;
Same in PostgreSQL:
1 WITH RECURSIVE t AS (
2 SELECT '2010-01-01'::timestamp AS d
3 UNION ALL
4 SELECT d + '1 months' FROM t...