This can be done with a macro. (q[register] to begin a macro, then q to end it).
0W"ayiWW"by$:let g:<C-r>a = "<C-r>b"<cr>0j
I am unsure of how to insert the special characters here but replace C-r and cr with their respective codes ^R and ^M using Ctrl-V (or Ctrl-Q on windows) in insert mode when writing the macro directly, or just replace with the actual key sequences (cr : enter) when recording the macro.
What this does is goes to the beginning of the line, to the next WORD of the line, then yanks the WORD into the a-register. Then, to the next WORD, it yanks the rest of the line into the b-register.
Now, in command mode, it will run the command to define a global variable with variable name equal to the contents of the a-register (using C-r a) and value equal to the contents of the b-register (using C-r b).
Finally, the macro moves the cursor to the beginning of the line and moves down one line so it can easily be repeated.
Now, you may want to take a file and execute this macro on all matching lines.
You can go to command mode and run:
:%g/^set /normal! @q
This uses the global command over the given range, running a command on all matching lines (lines starting with "set "). If there are other lines you don't want to match that also start with "set " you will need to fiddle with the regex. The command that is run executes a normal-mode command which executes the macro stored in the q-register, which will define the global variable according to the contents of the line (if it is correctly formed, with incorrectly formed lines the macro may mess up and create bad behaviour).
Now this is a lot of work to go through each time, if you overwrite the q-register and lose the macro. So a function would be nice.
In your ~/.vimrc or ~/_vimrc or equivalent, include:
function! TCLLineToVariable()
execute "normal! 0W\"ayiWW\"by$:let g:\<C-r>a = \"\<C-r>b\"\<cr>0j"
endfunction
function! CreateTCLGlobals()
%g/^set /call TCLLineToVariable()
endfunction
Escape sequences and execute "normal! ..." are needed because execute preprocesses the escape sequences to pass to a normal! command.
This function, when run, will operate on all lines in the file (% range), creating globals dynamically.
If you want this to happen with any tcl file, use autocommands in your vimrc.
autocmd BufRead *.tcl call CreateTCLGlobals()
If you are using an extension other than .tcl, replace this part with your extension. Add BufEnter, BufWritePost, as well if you want all globals to be updated while you are editing the file (when you switch to the buffer or write it, at least). You may also want to surround this with an autocommand group so you don't duplicate the autocmd every time you source your vimrc.
augroup TCL
autocmd!
autocmd BufRead,BufEnter,BufWritePost *.tcl call CreateTCLGlobals()
augroup END
set foo /bar/bazform I'd be happy to make the pattern more explicit. – B Layer Aug 26 '18 at 06:40