Thursday, January 30, 2014

Re: Emulate a typewriter

Hey Andy,

Your script is awesome! The way that you capitalized on vim's handling of ambiguous mappings to slow down the input loop is pretty awesome. Coolest peice of vimscript I've ever seen.

Don't let it get to your head ;-)

- Leon

On Friday, May 22, 2009 8:40:20 AM UTC-4, Andy Wokula wrote:
> Tom Link schrieb:
> > Hi,
> >
> > What would be the best way to emulate this in vim:
> >
> > http://lifehacker.com/5263560/typewriter-forces-you-to-focus-while-you-write
> > http://www.lifehackingmovie.com/2009/05/18/typewriter-minimal-text-editor-freeware/
> >
> > I was thinking of putting vim into insert mode and of remapping all
> > keys that would get you out of it & of disabling cursor keys and the
> > like. Any other ideas? Any idea of how to remap all those keys
> > automatically via vimscript?
> >
> > Regards,
> > Thomas.
>
> Isn't getchar() the first thing that comes to mind?
> but ok: getchar() shows the cursor in the cmdline when waiting for input.
>
> here is a workaround (use incomplete mapping to delay getchar() until
> a char is available):
>
>
> let g:twm_allowed_pat = '^[[:alnum:] \t\r,.!?]$'
>
> " start typewrite mode (stop with CTRL-C):
> nmap <Leader>tw <Plug>twm
>
> nmap <script> <Plug>twm i<SID>m_
> imap <Plug>twm <SID>m_
>
> imap <SID>m_<Esc> <SID>m_
> ino <silent> <SID>m_ <C-R>=TwGetchar()<CR>
>
> func! TwGetchar()
> if getchar(1)
> let chr = s:getchar()
> else
> let chr = "\<Plug>"
> endif
> call feedkeys("\<Plug>twm")
> if chr =~ g:twm_allowed_pat
> return chr
> endif
> return ""
> endfunc
>
> func! s:getchar()
> let chr = getchar()
> if chr != 0
> let chr = nr2char(chr)
> endif
> return chr
> endfunc
>
>
> <SID>m_ causes a "_" to show up in the text.
> <SID>m_<Esc> is mapped to give Vim something to wait for.
>
> Tried on a win32 gVim.
>
> --
> Andy

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment