Last active
December 20, 2018 07:17
-
-
Save tsuyoshicho/7f9fb1d43f1feb6fbf010c06e70db814 to your computer and use it in GitHub Desktop.
vimでgithub emojiをUnicode emojiにする ref: https://qiita.com/tsuyoshi_cho/items/89bd707b536ed202efbe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [[plugins]] # completion <C-X><C-U> (user completion) | |
| repo = 'junegunn/vim-emoji' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " set default user completion function | |
| set completefunc=emoji#complete | |
| " replace :emoji: to <unicode-emoji> | |
| " try echo unicode | |
| function! s:emoji_unicode_echo () | |
| let l:keywords=&iskeyword | |
| setlocal iskeyword-=: | |
| let l:word = expand('<cword>') | |
| let l:gh_word = ':'.l:word.':' | |
| if '' !=? emoji#for(l:word) | |
| echo 'emoji :'.expand('<cword>').'-'.emoji#for(l:word) | |
| else | |
| echo 'emoji :'.expand('<cword>').'-'.'(no match)' | |
| endif | |
| let &iskeyword=l:keywords | |
| endfunction | |
| nnoremap <silent><Leader>e :call <SID>emoji_unicode_echo()<CR> | |
| function! s:emoji_unicode_replace () | |
| let l:keywords=&iskeyword | |
| setlocal iskeyword-=: | |
| let l:word = expand('<cword>') | |
| if word == '' | |
| let &iskeyword=l:keywords | |
| return | |
| endif | |
| let l:gh_word = ':'.l:word.':' | |
| if '' !=? emoji#for(l:word) | |
| " カーソル位置をword分前に動かしてから、その位置から後の最初のwordを置換する | |
| " 完了後、位置を移動 | |
| " 123456789ABCD | |
| " smile :smile: | |
| " ^____ origin cursor | |
| " ^____ replace match start (word match pos - colon_size (min:1)) | |
| " ^____ if success; search emoji start (same replace match) | |
| " smile :smile: | |
| " __^__ origin cursor | |
| " ^____ replace match start (word match pos - colon_size (min:1)) | |
| " ^____ if success; search emoji start (same replace match) | |
| " smile :smile: | |
| " ________^__ origin cursor | |
| " ___^_______ word matchs start (origin - word len(min:1)) | |
| " ______^____ replace match start (word match pos - colon_size (min:1)) | |
| " ______^____ if success; search emoji start (same replace match) | |
| let pos = getcurpos() | |
| let word_col = pos[2] | |
| let target_col = pos[2] | |
| if pos[2] != 1 | |
| " 行頭以外は位置補正する | |
| let word_col = pos[2] - strlen(l:word) | |
| if word_col < 1 | let word_col = 1 | endif | |
| let target_col = word_col | |
| if word_col != 1 | |
| call cursor(pos[1], word_col) | |
| call search(l:word) | |
| let target_pos = getcurpos() | |
| let target_col = target_pos[2] - 1 " : の分 | |
| if target_col < 1 | let target_col = 1 | endif | |
| endif | |
| endif | |
| call cursor(pos[1], target_col) | |
| let l:success = 0 | |
| try | |
| execute('substitute' . '/' . '\%#'.l:gh_word . '/' . '\=emoji#for(l:word)' . '/el') | |
| let l:success = 1 | |
| finally | |
| call cursor(pos[1], pos[2]) | |
| endtry | |
| if l:success | |
| call cursor(pos[1], target_col) | |
| call search(emoji#for(l:word)) | |
| endif | |
| " debug | |
| " echom 'emoji:' . 'pos:'.pos[2] . ',word:'.word_col . ',target:'.target_col . ',success:'.l:success | |
| endif | |
| let &iskeyword=l:keywords | |
| endfunction | |
| nnoremap <silent><Leader>E :call <SID>emoji_unicode_replace()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment