Monday, April 2, 2012

Re: maps in "if" statement can not work.

=> On [2012-03-28 07:20:26 +0200]:
Jürgen Krämer Said:
>
> Hi,
>
> stardiviner wrote:
> > I found a tips on wikia, it can autocapitalize first character in sentence.
> > Bellowing is the code in my vimrc.
> > But I found that those mappings in "if" statement can not work.
> > Is there anyone know why ?
> > (The original code does not have the "if" statement. I add it by myself.)
> >
> > "Inputing '/' cancels capitalizing without delay
> > function! CapNextKey(prev)
> > redraw
> > let input = nr2char(getchar())
> > let input = (input == '/' ? "\e" : input)
> > if input=~'[.?!\r[:blank:]]' "punctuations, return, spaces
> > exe 'normal! i' . input . "\<Right>"
> > return CapNextKey(input)
> > elseif input=="\e"
> > return "\<del>"
> > elseif a:prev=~'[\r[:blank:]]'
> > return toupper(input) . "\<del>"
> > else
> > return input . "\<del>"
> > endif
> > endfunction
> >
> > function! InsertEnterCheck()
> > let trunc = getline(".")[0:col(".")-2]
> > if col(".")==1
> > return CapNextKey("\r")
> > elseif trunc=~'[?!.]\s*$\|^\s*$' "ie, 'text.[t]ext'
> > return CapNextKey(trunc[-1:-1])
> > else
> > return "\<Del>"
> > endif
> > endfunction
> >
> > " FIXME those maps can not run in "if" statement.
> > if &filetype == "markdown" || &filetype == "mail"
> > inoremap <silent> . ._<Left><C-R>=CapNextKey(".")<CR>
> > inoremap <silent> ? ?_<Left><C-R>=CapNextKey("?")<CR>
> > inoremap <silent> ! !_<Left><C-R>=CapNextKey("!")<CR>
> > inoremap <silent> <CR> <CR>_<Left><C-R>=CapNextKey("\r")<CR>
> > nnoremap <silent> o o_<Left><C-R>=CapNextKey("\r")<CR>
> > nnoremap <silent> O O_<Left><C-R>=CapNextKey("\r")<CR>
> > nnoremap <silent> a a_<Left><C-R>=InsertEnterCheck()<CR>
> > nnoremap <silent> A A_<Left><C-R>=InsertEnterCheck()<CR>
> > nnoremap <silent> i i_<Left><C-R>=InsertEnterCheck()<CR>
> > nnoremap <silent> I I_<Left><C-R>=InsertEnterCheck()<CR>
> > endif
>
> putting this in your .vimrc is too early. .vimrc is sourced before file
> type detection takes place. At the &filetype is checked in your code it
> is thus still empty.
>
> You might consider to put your code in a separate file and source it
> from your markdown and mail filetype plugins. Or leave the function
> definitions in .vimrc, but put only the part the if and endif in your
> filetype plugins.
Put them in other file like ftplugin/{markdown,mail}.vim ???
>
> Regards,
> Jürgen
>
>
> --
> Sometimes I think the surest sign that intelligent life exists elsewhere
> in the universe is that none of it has tried to contact us. (Calvin)
>
> --
> 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
>

--
[stardiviner] <fuck you, world!> GPG key ID: 47C32433
IRC(freeenode): Evanescence Twitter: @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433
http://stardiviner.dyndns-blog.com/author.html

No comments:

Post a Comment