Skip to content

Instantly share code, notes, and snippets.

@moznion
Created January 15, 2014 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moznion/8431877 to your computer and use it in GitHub Desktop.
Save moznion/8431877 to your computer and use it in GitHub Desktop.
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