Checking if the current word is spelled wrong and correct it in script

0 views
Skip to first unread message

TheLonelyStar

unread,
Jul 9, 2009, 10:12:07 AM7/9/09
to vim...@googlegroups.com

Hi,

I have a my tab key mapped to a function which should react different
depending on the situation
1. If I am in a comment, the current word is completet from dictonary
2. If I am in code, curstom completions is called (elim sits behind it here)
Now I want a third thing:
3. If I am in a comment and the current word is misspelled, spell correct
it.

The function works for the first 2 things, but the last thing I do not know
how to do:
This is the function:

function TabDo()
let col = col('.') == col('$') ? col('.') - 1 : col('.')
let syntax = synIDattr(synID(line('.'), col, 1), "name")
if syntax =~ 'Comment' || syntax =~ 'String'
" let badword = spellbadword()
" if badword =~ ''
return "\<c-x>\<c-k>"
" endif
" return 'z='
endif
return "\<c-x>\<c-u>"
endfunction

The commented part are my tries for adding the extra option. What am I doing
wrong?

Thanks!
Nathan
--
View this message in context: http://www.nabble.com/Checking-if-the-current-word-is-spelled-wrong-and-correct-it-in-script-tp24410540p24410540.html
Sent from the Vim - General mailing list archive at Nabble.com.

Christian Brabandt

unread,
Jul 9, 2009, 1:54:47 PM7/9/09
to vim...@googlegroups.com
Hi TheLonelyStar!

On Do, 09 Jul 2009, TheLonelyStar wrote:

> I have a my tab key mapped to a function which should react
> different depending on the situation

> 1. If I am in a comment, the current word is completet from dictonary
> 2. If I am in code, curstom completions is called (elim sits behind it here)
> Now I want a third thing:
> 3. If I am in a comment and the current word is misspelled, spell correct
> it.
>
> The function works for the first 2 things, but the last thing I do not know
> how to do:
> This is the function:
>

I have never used spellbadword() but this works for me:

fu! Spell()
let badword = spellbadword(expand("<cword>"))
if badword == [ '', '']
echo "Current word is good"
else
echo "Found: " . badword[0] . " Type: " . badword[1]
endif
endfu

Hope that helps.

regards,
Christian
--
:wq!

Reply all
Reply to author
Forward
0 new messages