Tuesday, March 27, 2012

maps in "if" statement can not work.

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

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