diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ead8445 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.swp diff --git a/plugin/rubyhash.vim b/plugin/rubyhash.vim index 9531d66..5828d88 100644 --- a/plugin/rubyhash.vim +++ b/plugin/rubyhash.vim @@ -9,46 +9,13 @@ if g:rubyhash_map_keys==1 endif function! ToSymbolKeysLinewise() - :ruby Convert::to_symbols + call setline('.', substitute(substitute(getline('.'), '[''"]\(\w\+\)[''"]\(?=\s*=>\)', '\1:', 'g'), '\(\(?:\{|,|^\)\s*\)\(\w\+\):', '\1:\2 =>', 'g')) endfunction function! To19KeysLinewise() - :ruby Convert::to_19 + call setline('.', substitute(substitute(getline('.'), ':\(\w\+\)\s*=>', '\1:', 'g'), '[''"]\(\w\+\)[''"]\s*=>', '\1:', 'g')) endfunction function! ToStringKeysLinewise() - :ruby Convert::to_strings + call setline('.', substitute(substitute(getline('.'), ':\(\w\+\)\(?=\s*=>\)', '"\1"', 'g'), '\(\(?:\{|,|^\)\s*\)\(\w\+\):', '\1"\2" =>', 'g')) endfunction - -ruby << EOF -module Convert - def self.to_symbols - search_and_replace([ - { :search => /['"](\w+)['"](?=\s*=>)/, :replace => ':\1' }, - { :search => /((?:\{|,|^)\s*)(\w+):/, :replace => '\1:\2 =>'} - ]) - end - - def self.to_strings - search_and_replace([ - { :search => /:(\w+)(?=\s*=>)/, :replace => '"\1"'}, - { :search => /((?:\{|,|^)\s*)(\w+):/, :replace => '\1"\2" =>'}, - ]) - end - - def self.to_19 - search_and_replace([ - { :search => /:(\w+)\s*=>/, :replace => '\1:'}, - { :search => /['"](\w+)['"]\s*=>/, :replace => '\1:'}, - ]) - end - - private - - def self.search_and_replace(patterns=[]) - contents = VIM::Buffer.current.line - patterns.each { |params| contents.gsub!(params[:search], params[:replace]) } - VIM::Buffer.current.line = contents - end -end -EOF