Created
January 15, 2014 06:43
-
-
Save moznion/8431877 to your computer and use it in GitHub Desktop.
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
au InsertLeave,CursorMovedI *.js call s:replaceFunctionKeyword2Kotobuki() | |
au BufWritePre,FileWritePre,FileAppendPre *.js call s:replaceAll('寿', 'function') | |
au BufRead,BufWritePost,FileWritePost,FileAppendPost *.js call s:replaceAll('function', '寿') | |
func! s:replaceFunctionKeyword2Kotobuki() | |
let l:line_num = line(".") | |
let l:line = getline(l:line_num) | |
if (l:line ==# '') | |
let l:line_num -= 1 | |
let l:line = getline(l:line_num) | |
endif | |
call setline(l:line_num, substitute(getline(l:line_num), 'function', '寿', '')) | |
endfunc | |
func! s:replaceAll(from, to) | |
let l:top_line = line("w0") | |
let l:bottom_line = line("w$") | |
let l:current_line = l:top_line | |
while l:current_line <= l:bottom_line | |
call setline(l:current_line, substitute(getline(l:current_line), a:from, a:to, '')) | |
let l:current_line += 1 | |
endwhile | |
endfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment