开发者

VIM spelling function

开发者 https://www.devze.com 2023-02-23 13:35 出处:网络
I wan\'t to have a function that turns spell check on then go\'s to the next misspelled word and replaces with the first suggestion heres what I\'ve got so far:

I wan't to have a function that turns spell check on then go's to the next misspelled word and replaces with the first suggestion heres what I've got so far:

function! Spell_new_word()
  set spell=true
  exe ']s'
  exe '1z='
  set spell=false
endfunction

but it only seems to set spelling to true and doesn't do anything.... what am I doing wrong?

UPDATE:

I've tired changing exe to normal, but still no luck:

function! Spell_new_word()
  set spell!
  normal ']s'
  normal '开发者_运维知识库1z='
  set spell!
endfunction

UPDATE 2:

I've tired this and it still doesn't work:

function! Spell_new_word()
  set spell
  normal ]s
  normal 1z=
  set nospell
endfunction

But I don't think that is the problem I think thats its not binding to ,d:

let mapleader = ","
namp ,d Spell_next_word()


nnoremap ,d :call Spell_next_word()^M

things to note:

  1. choose mode (normal mode, no remapping)
  2. include : to enter command mode
  3. call the function
  4. Execute it! The ^M is normally entered with C-vEnter on linux, or C-QEnter on Windows

Additionally, perhaps include

inoremap ,d ^O:call Spell_next_word()^M

(again typeing the ^O as C-vC-o or C-QC-o)


Change exe to normal. exe is for executing command line commands.


In addition to implementing Austin's answer (see my comment underneath), you need to learn how to toggle vim's settings on and off. This is explained in the various entries under :help :set. Specifically, you should use set spell to enable spelling and set nospell to disable it.

There are some other configurations which may need to be done to get spelling correction working, like setting 'spelllang'. Have a read through :help spell.txt for the details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号