Skip to content

Instantly share code, notes, and snippets.

@farhaanbukhsh
Created April 10, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhaanbukhsh/935670c84deeb43dd43967187ce8ced9 to your computer and use it in GitHub Desktop.
Save farhaanbukhsh/935670c84deeb43dd43967187ce8ced9 to your computer and use it in GitHub Desktop.
This is vimscript to migrate to ES2015 standards
"" Put the following function in your `.vimrc` and place the cursor on the
"" `var <ComponentName>` line once the cursor is there in the `command` mode
"" press spacebar to execute the function, check that your spacebar is not
"" mapped to any other function enjoy the migration to ES2015
""
"" Author : Farhaan Bukhsh <farhaan@fedoraproject.org>
"" React migrate
function ReactMigrate()
let curr_line = getline('.')
let replaceVar = substitute(curr_line, 'var', 'class', 'g')
call setline('.', replaceVar)
let curr_line = getline('.')
let replaceClass = substitute(curr_line, '=
React.createClass', 'extends React.Component', 'g')
call setline('.', replaceClass)
normal f(
normal %2x``x
endfunction
nnoremap <space> :call ReactMigrate() <CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment