junegunn / vim-emoji

:smiley: Emoji in Vim
605 stars 30 forks source link

way to automatically replace emoji_string with the actual emoji #33

Open Bhupesh-V opened 3 years ago

Bhupesh-V commented 3 years ago

The :emoji_string: sometimes are not rendered by default in HTML pages except GitHub ofc. It would be nice to have a switch to add the actual emoji instead of the string.

I have tried to automate this, but was unsuccessful.

autocmd CompleteDone *  call FixEmoji()
function! FixEmoji()
        let word = expand('<cWORD>')
                " remove colons :
        let current_word = word[1:strlen(word)-2]
        let acemoji = emoji#for(current_word)
        execute "%s/" . word . "/" . acemoji . "/e"
endfunction
TheLonelyGhost commented 3 years ago

At the bottom of the readme it gives a good example of how to do this: %s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g

I ended up adding the following to my vimrc:

nnoremap <silent> <Leader><Bslash> :s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g<CR>:noh<CR>
Bhupesh-V commented 3 years ago

At the bottom of the readme it gives a good example of how to do this: %s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g

I ended up adding the following to my vimrc:

nnoremap <silent> <Leader><Bslash> :s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g<CR>:noh<CR>

Yep, it's indeed good but I am trying to reduce the need for that one keystroke. Wouldn't it be great if there were a global setting for this? For example: let g:insert_emoji = 1 which will insert the emoji instead of the string?

dmiraj commented 2 years ago

I written this quick script that does the trick! It will substitute your emojis as soon as the autocomplete finishes. You won't need a mapping then.

fun! <SID>Sub_movend(lineno)
    if (match(getline(a:lineno), ':\([^:]\+\):') != -1) " There is a match
        exe a:lineno . 'su /:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g'
        star!
    endif
endfun

autocmd! CompleteDone * call <SID>Sub_movend(line('.'))

Then ofc, source the script in your .vimrc with line: runtime /path/to/scrip.vim