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:
:normal! gv"*y
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 ...
Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.
Introduction to Recursion and Backtracking