How do I get the current visually selected text into a Vim variable
or register? You can get the current visually selected text into a Vim variable by yanking the text into Vim register and then assigning the contents of the register into the variable:
:normal! gvy :let myvar = @"
The above command copies the visually selected text into the variable “myvar”. You can also use the command:
In the above command, gv reselects the last visually selected text and the rest of the command copies the selected text into the * (clipboard) register. Alternatively, you can set the ‘a’ flag in the ‘guioptions’ option to automatically copy a visually selected text into the * register. To do this as part of a visual map, you can use a command similar to the one shown below:
:vmap "*y:call ...