Friday, July 23, 2010

Re: Howto execute VIM-commands in editing mode, needed forprototype

Excerpts from Romeyke, Andreas's message of Fri Jul 23 14:54:51 +0200 2010:
> Hello,
> Or in other words. It will be easier to reconfigure and use Vim as
> prototype of a specific edit-component instead of programming the
> prototype in any language.

Try this:

fun! ExecuteCommand(char)
let pos = getpos('.')
let beforeline=getline('.')[0:pos[1]]
let command = matchstr(beforeline, '.*!\zs[^ !]*$')
" check for !!, ignore that

let idx = len(beforeline)-len(command)-2
echoe
if command=="" || (idx >=0 && beforeline[idx] == '!')
return a:char
else
exec command
return repeat("\<bs>", len(command)+1)
endif
endf

inoremap <space> <c-r>=ExecuteCommand(" ")<cr>
" this <cr> does not work for some reason. If you care about it I'll
" investigae
inoremap <cr> <c-r>=ExecuteCommand("\<cr>")<cr>

Not that Vim can define custom commands starting with upper case letters
only.

Marc Weber

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment