Saturday, May 24, 2008

Normal command from Insert mode

Always forget the very useful shortcut which is apparently intended for "Vim Easy":

^O

When in insert mode (and, by definition, in easy vim you are always in the mode) to insert command from Normal mode, you press first ^O and then start typing the command.

e.g. to delete to the end of line press ^O followed by Shift-d. Pressing : you can also access all the ex commands too - but that will leave insert mode.

Sunday, March 30, 2008

Inserting command output from a function

How would I use a vim function to insert the output of these commands at the current cursor position?

Well, that would look like a crude hack, yet here it goes:


:function InsertCmd( cmd )
: exe ':silent !'.a:cmd.' > /tmp/vim.insert.xxx 2>/dev/null'
: let l = readfile( '/tmp/vim.insert.xxx', '', 1 )
: exe "normal a".l[0]
: redraw!
:endfunction

:imap <silent> <F5> <Esc>:call InsertCmd( 'hostname' )<CR><Insert>
:map <silent> <F5> :call InsertCmd( 'hostname' )<CR>



The function InsertCmd(cmd) runs in shell given command and redirects its stdout to a file. Then using readfile() function, first line of file is read into list l. Finally using :normal command and a (:help a) command we put the first line of output into buffer.

The two mappings for F5 key - for insert and for command mode show how to invoke the function to insert output of "hostname" into current cursor position. ":imap" probably needs extra <Right> on the end since due to switch between insert/normal modes cursor goes one position back.

Edit1. Better way to do it, from SO.

Friday, November 16, 2007

[off topic] Another monospace font: Droid Sans Mono

Accidentally came across new (at least to me) monospace font called "Droid Sans Mono."

Since I'm droid coder already, there is no real danger of using the font - with such terribly sounding name.

Link

Tuesday, October 30, 2007

[off topic] MSWindows - Minimize Window shortcut

Lack of shortcut to minimize current window had bothered me for very very long time.

But finally I found a solution. There is a wonderful program for M$Windows called AutoHotkey. Main purpose of program is to allow you to override particular shortcuts to perform custom action. Program is pretty cryptic, but allow for some automation of Windows what is definitely progress. (For example I have bunch of shortcuts to retrieve information from Firefox in half-automatic fashion.)

Now the magic to put into AutoHotkey.ahk (default) configuration file:

#x::
WinMinimize, A
return


"#x" is "Win-X" shortcut (hold the (otherwise worthless) key with Windows flag on it and press X). "WinMinimize, A" command tells to minimize active ("A") window. "return" tells to stop further script processing.

Edit1.
Bit of additional magic to disable the single-Alt menu silliness and to emulate Mac OS X input of German umlaut characters:

Alt::
return

>!u::Send {ASC 0252}
>!o::Send {ASC 0246}
>!a::Send {ASC 0228}
+>!u::Send {ASC 0220}
+>!o::Send {ASC 0214}
+>!a::Send {ASC 0196}

Monday, October 29, 2007

[off topic] VIM Plug-in for Eclipse

While wonders of KDE's VIM components are not new, that stroke me as ... funny.

Vimplugin and viPlugin allow one to use VIM editor as replacement of standard text editor of Eclipse SDK.

Funny.

P.S. Thanks God I'm safe from Java programming. For now.

Monday, August 13, 2007

VIM vs. broken OSs/terminals :: colors are forever!

The tip was found in VIM's help under :help color-xterm and works for HP-UX and Solaris. I conditionally exclude Linux to be unaffected by workaround, since F/LOSS folks - compared to the Unix old farts - have managed somehow to ship decent terminfo/termcap boasting color support out of box.


if &t_Co > 0
" Linux/etc has proper terminfo
else
if &term =~ "xterm"
if has("terminfo")
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
else
set t_Co=8
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
endif
endif
endif


The thing needs to be put into ~/.vimrc. The '^[' needs to be replaced by real escape character - ^V<Esc>.

Sunday, August 12, 2007

[off-topic] Hardcore vs. Casual gaming

In reply to one comment on Joystiq while discussing hardware sales.

> I'd really like for somebody to define "hardcore game" for me.

My definition of "hardcore game" is game which requires involved playing.

I would consider you to be hardcore gamer in "Madden and NCAA football games". Because you have extensive experience in football games, you would demand more of it from newer games. That's what makes gaming "hardcore": entry level is very high.

Casual gaming is all about "Pick and Play" e.g. WiiSports' Tennis or Baseball. One doesn't need to spend hours getting into game - s/he can pick WaggleMote and start playing right away.

Also, feat of many console games I consider "hardcore" is boss fights and poor/non-existent saving system. "Pick and Play" should really be "Pick, Play and Put it back". And that's where most console games fail miserably: you can't stop playing moment you want to stop playing - but the moment game allows you to stop playing. E.g. Metroid and it stupid save rooms: you came into room and door was locked behind you - now you are expected to spend time looking for way out or fight boss. But you can NOT save game and start doing something else. No. Game doesn't allow that.

Hardcore gaming: gaming demanding higher degree of involvement. Whether by mean of poor save system or by lots of tricks you need to keep in your head to be able to play game (and you easily start forgetting them if you do not play many hours daily; lengthy key combos are good example of that).

Casual gaming: gaming by formula "Pick, Play and Move on." You can start any moment you want to play. You can play and enjoy game as long you want and have time. And last (but not least) you can stop playing (preserving your progress) any moment you like or have to (the "have to"s are what adult life is all about).

P.S. Many PC games are much better suited for casual gaming, since most of them have good save system (or what console folks call "instant save/load"). And somehow PC games also manage to avoid the silliness of boss fights, which can bar you from making any progress in game for long time.

Monday, June 25, 2007

VIM :: man pages invokation shortcut

I have finally found it. The very important shortcut I was missing long time. I knew it was there - but never actually managed to dig it up.

K

That's simple. It replaces my now archaic ":!man ".expand("<cword>") - use word under cursor and invoke 'K'eyword program on it. Keyword program is normally man. Can be configured with option 'keywordprg' (:help 'keywordprg' for more info).

If keywordprg is man, then VIM provides another cool feature: repeat count when used with K now tells to go to particular man section. e.g. 3K would invoke "man 3" on current word. What is very very cool.

Wednesday, June 06, 2007