When writing Greek, sigmas at the ends of words should have a different form. Can I do something automatically to replace: μῖσοσ by μῖσος, and so in all such cases?

  • 1
    How about running %s/σ\>/ς/g whenever you save the file? – muru Nov 13 '15 at 17:58
  • Yes, but it would be better to have it corrected straight away. – Toothrot Nov 13 '15 at 18:09
  • 1
    It's even better to write it correctly from the start :P You could use (greek) dictionary-based autocompletion – VanLaser Nov 13 '15 at 18:10
  • 1
    The problem is distinguishing an end-of-word sigma from a normal one. I think you'll have to content yourself with typing some other key combination at the end of word (say inoremap σ<spac> ς), then any sigma followed by space will be replaced by the other form. But then you'd have to add another space manually. – muru Nov 13 '15 at 18:16

Since a final sigma is quickly followed with a space even if a punctuation marks immediately followf it (except for the end-of-line case), you could do this: define the folowwing function (in your ~/.vimrc file) and remap the space key in insert mode to this function.

" The function checks whether a final greek sigma to be fixed can be found
" on the same line at the left of the cursor; the function should be accessed
" through a mapping of the space key in insert mode (since even punctuation
" marks are flollowed with a space.
function! FixPreviousSigma()
    let l:l = line(".")
    let l:c = col(".")
    let l:s = search('σ\>', 'bcW', l:l)
    if l:s == l:l
        silent execute "normal rς"
    call cursor(l:l, l:c)

Then use the tricky mapping whenever you need to use this feature:

:inoremap <Space> <ESC>:call FixPreviousSigma()<CR>a<C-v><Space>

If you also want to take into account the end-of-line case, maybe you could also try:

:inoremap <Enter> <ESC>:callFixPreviousSigma()<CR>o
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.