title: In search and replacing using VIM, how do I keep a grouped text and reuse it in the replacement part?
body: <p>In VIM (<strong>edit</strong> MacVim snapshot 64), I am looking for a way to convert these lines of text</p>
  
  <pre><code>can_check_steps = 1
  can_edit_work_type = 1
  can_edit_vendor = 1
  can_edit_place = 1
  </code></pre>
  
  <p>to</p>
  
  <pre><code>'can_check_steps': can_check_steps,
  'can_edit_work_type': can_edit_work_type,
  'can_edit_vendor': can_edit_vendor,
  'can_edit_place': can_edit_place,
  </code></pre>
  
  <p>I know how to add the leading single quote and convert the <code>=</code> into <code>:</code> with multi-line character replacement (something I learned from <a href="https://stackoverflow.com/questions/9549729/in-vim-how-do-i-effectively-insert-the-same-characters-across-multiple-lines">this question</a>) and basic search and replace, respectively.</p>
  
  <p>But I can't really figure out how to repeat that the variable name per line. I'm also starting to think there should be a way to do this all in one command using like grouped expressions (using <code>(</code> and <code>)</code> to "capture" in regular expression).</p>
  
  <p>I know how to do it in Python with lines of code, but I don't really know how to do it in VIM using the <code>s/search_for_this/replace_that/options</code> format.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After reading the answers, why doesn't this work?</p>
  
  <pre><code>^\s*(\w+) = 1\s*$/'\1': \1,/g
  </code></pre>
  
  <p>For @Jonathan Leffler, <strong>:set all</strong> in MacVim produces</p>
  
  <pre><code>--- Options ---
    aleph=224           bufhidden=          cscopequickfix=   noerrorbells          fsync               includeexpr=      nomacmeta             omnifunc=           report=2            showmatch           tabline=          nottimeout          nowildignorecase
    antialias           buflisted         nocscoperelative      esckeys           nofullscreen          incsearch           magic               operatorfunc=     norevins              showmode            tabpagemax=10       ttimeoutlen=-1      wildmenu
  noarabic              buftype=          nocscopetag           eventignore=      nogdefault            indentexpr=         makeef=           nopaste             norightleft           showtabline=1       tabstop=4           ttybuiltin          wildmode=full
    arabicshape         cdpath=,,           cscopetagorder=0    expandtab           guifont=          noinfercase           makeprg=make        pastetoggle=        ruler               sidescroll=0        tagbsearch        nottyfast             wildoptions=
  noallowrevins         cedit=^F          nocscopeverbose     noexrc                guifontwide=      noinsertmode          matchtime=5         patchexpr=          rulerformat=        sidescrolloff=0     taglength=0         ttymouse=           window=83
  noaltkeymap           charconvert=      nocursorbind          fileencoding=       guipty              isprint=@,161-255   maxcombine=2        patchmode=          scroll=41           smartcase           tagrelative         ttyscroll=999       winheight=1
    ambiwidth=single  nocindent           nocursorcolumn        fileformat=unix     guitablabel=%M%t    joinspaces          maxfuncdepth=100  nopreserveindent    noscrollbind          smartindent         tags=./tags,tags    undodir=.         nowinfixheight
    autochdir           cinoptions=         cursorline          filetype=           guitabtooltip=      key=                maxmapdepth=1000    previewheight=12    scrolljump=1        smarttab            tagstack          noundofile          nowinfixwidth
    autoindent          cmdheight=1         debug=            nofkmap               helpheight=20       keymap=             maxmem=751782     nopreviewwindow       scrolloff=0         softtabstop=0       term=builtin_gui    undolevels=1000     winminheight=1
  noautoread            cmdwinheight=7    nodelcombine          foldclose=          helplang=en         keymodel=           maxmemtot=751782    printdevice=      nosecure            nospell             notermbidi            undoreload=10000    winminwidth=1
  noautowrite           colorcolumn=        dictionary=         foldcolumn=0      nohidden              keywordprg=man -s   menuitems=25        printencoding=      selectmode=         spellfile=        noterse               updatecount=200     winwidth=20
  noautowriteall        columns=269       nodiff                foldenable          history=1000        langmap=            modeline            printfont=courier   shell=/bin/bash     spelllang=en        textauto            updatetime=4000     wrap
    background=dark   nocompatible          diffexpr=           foldexpr=0        nohkmap               langmenu=none       modelines=5         printmbcharset=     shellcmdflag=-c     spellsuggest=best notextmode            verbose=0           wrapmargin=0
  nobackup              concealcursor=      diffopt=filler      foldignore=#      nohkmapp              laststatus=2        modifiable          printmbfont=        shellquote=       nosplitbelow          textwidth=0         verbosefile=        wrapscan
    backupcopy=auto     conceallevel=0    nodigraph             foldlevel=0         hlsearch          nolazyredraw        nomodified            printoptions=       shelltemp         nosplitright          thesaurus=          virtualedit=        write
    backupext=~         completefunc=       display=            foldlevelstart=-1   icon              nolinebreak           more                prompt              shellxquote=        startofline       notildeop           novisualbell        nowriteany
    balloondelay=600  noconfirm             eadirection=both    foldmethod=manual   iconstring=         lines=84            mouse=a             pumheight=0       noshiftround          suffixesadd=        timeout             warn                writebackup
  noballooneval       nocopyindent        noedcompatible        foldminlines=1    noignorecase          linespace=0       nomousefocus          quoteescape=\       shiftwidth=4        swapfile            timeoutlen=1000   noweirdinvert         writedelay=0
    balloonexpr=        cpoptions=aABceFs   encoding=utf-8      foldnestmax=20    noimcmdline         nolisp                mousehide         noreadonly          noshortname           swapsync=fsync      title               whichwrap=b,s
  nobinary              cryptmethod=zip     endofline           formatexpr=         imdisable         nolist                mousetime=500       redrawtime=2000     showbreak=          switchbuf=          titlelen=85         wildchar=&lt;Tab&gt;
  nobomb                cscopepathcomp=0    equalalways         formatoptions=tcq   iminsert=2          listchars=eol:$     number            norelativenumber      showcmd             synmaxcol=3000      titlestring=        wildcharm=0
    browsedir=last      cscopeprg=cscope    equalprg=           formatprg=          imsearch=2          loadplugins         numberwidth=4       remap             noshowfulltag         syntax=             transparency=0      wildignore=
    backspace=indent,eol,start
    backupdir=.,~/tmp,~/
    backupskip=/tmp/*,/var/folders/70/f8c54mjn4vg_wztz9bd17lp40000gn/T/*
    breakat= ^I!@*-+;:,./?
    casemap=internal,keepascii
    cinkeys=0{,0},0),:,0#,!^F,o,O,e
    cinwords=if,else,while,do,for,switch
    clipboard=autoselect
    comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:&gt;,fb:-
    commentstring=/*%s*/
    complete=.,w,b,u,t,i
    completeopt=menu,preview
    define=^\s*#\s*define
    directory=.,~/tmp,/var/tmp,/tmp
    errorfile=errors.err
    errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file
   included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory `%f',%X%*\a[%*\d]: Leaving directory `%f',%D%*\a: Entering directory `%f
  ',%X%*\a: Leaving directory `%f',%DMaking %*\a in %f,%f|%l| %m
    fileencodings=ucs-bom,utf-8,default,latin1
    fileformats=unix,dos
    fillchars=vert:|,fold:-
    foldmarker={{{,}}}
    foldopen=block,hor,mark,percent,quickfix,search,tag,undo
    foldtext=foldtext()
    formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
    fuoptions=maxvert,maxhorz
    grepformat=%f:%l:%m,%f:%l%m,%f  %l%m
    grepprg=grep -n $* /dev/null
    guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
    guioptions=egmrLtT
    helpfile=/Applications/MacVim.app/Contents/Resources/vim/runtime/doc/help.txt
    highlight=8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete
  ,T:DiffText,&gt;:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn
    include=^\s*#\s*include
    indentkeys=0{,0},:,0#,!^F,o,O,e
    isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=
    isident=@,48-57,_,192-255
    iskeyword=@,48-57,_,192-255
    lispwords=defun,define,defmacro,set!,lambda,if,case,let,flet,let*,letrec,do,do*,define-syntax,let-syntax,letrec-syntax,destructuring-bind,defpackage,defparameter,defstruct,deftype,defvar,do-all-symbols,do-external-symbols,do-symbols,dolist,dotimes,ecase,etypecase,eva
  l-when,labels,macrolet,multiple-value-bind,multiple-value-call,multiple-value-prog1,multiple-value-setq,prog1,progv,typecase,unless,unwind-protect,when,with-input-from-string,with-open-file,with-open-stream,with-output-to-string,with-package-iterator,define-condition,h
  andler-bind,handler-case,restart-bind,restart-case,with-simple-restart,store-value,use-value,muffle-warning,abort,continue,with-slots,with-slots*,with-accessors,with-accessors*,defclass,defmethod,print-unreadable-object
    matchpairs=(:),{:},[:]
    maxmempattern=1000
    mkspellmem=460000,2000,500
    mousemodel=popup_setpos
    mouseshape=i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow
    nrformats=octal,hex
    paragraphs=IPLPPPQPP TPHPLIPpLpItpplpipbp
    path=.,/usr/include,,
    printexpr=system('open -a Preview '.v:fname_in) + v:shell_error
    printheader=%&lt;%f%h%m%=Page %N
    rightleftcmd=search
    runtimepath=~/.vim,/Applications/MacVim.app/Contents/Resources/vim/vimfiles,/Applications/MacVim.app/Contents/Resources/vim/runtime,/Applications/MacVim.app/Contents/Resources/vim/vimfiles/after,~/.vim/after
    scrollopt=ver,jump
    sections=SHNHH HUnhsh
    selection=inclusive
    sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize
    shellpipe=2&gt;&amp;1| tee
    shellredir=&gt;%s 2&gt;&amp;1
    shortmess=filnxtToO
    spellcapcheck=[.?!]\_[\])'"^I ]\+
    statusline=%F%m%r%h%w[%L][%{&amp;ff}]%y[%p%%][%04l,%04v]
    suffixes=.bak,~,.o,.h,.info,.swp,.obj
    termencoding=utf-8
    titleold=Thanks for flying Vim
    toolbar=icons,tooltips
    toolbariconsize=small
    ttytype=builtin_gui
    viewdir=~/.vim/view
    viewoptions=folds,options,cursor
    viminfo='100,&lt;50,s10,h  
  </code></pre>