On 4/23/06, Suresh Govindachar <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> Earlier today, I asked: "Unless called from the statusline,
> mode() mostly returns c or n. So how can one know the mode
> from viml?"
>
> Searching the archives, I found a tip from Tony Mechelynck
> about setting a variable from the statusline. (I also found
> a post from Benji from 2002 or 2003 wondering why one would
> want to know the mode directly from viml -- so he is included
> in the cc.)
>
> Here's the solution to having blockwise changes be blockwise
> irrespective of tw (refer post "Visual mode block change -- bug
> or 'unchangeable'?"):
>
> Note: there are 3 very long lines below which might get split
> into several lines by the email process.
>
> function! MySetMode()
> let b:foo = mode()
> return ''
> endfunction
>
> set statusline=%<%f%h%m%r%=%{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\
> %Y\")}\ %{&ff}\ %l,%c%V\ %P%{MySetMode()}
>
> augroup BlockHold
> au!
> au InsertEnter * if(b:foo == '') | let b:blockhold_tw = &tw |
> setlocal tw=0 | endif
> au InsertLeave * if(exists("b:blockhold_tw")) | let &l:tw =
> b:blockhold_tw | unlet b:blockhold_tw | endif
> augroup END
>
> finish
Nice trick.
Yakov