On the command line hit
<C-u> then type
@* and enter.
<C-u> will delete the visual range
'<,'> that has been automatically inserted if some text is visually selected.
:@* will execute the content of the
* register which contains whatever is visually selected at the moment.
Even if the text that is selected / highlighted is in your web browser (firefox, chrome, ...), it will work, the
* register will allow you to access it directly in vim.
If your text is selected in a vim buffer, another solution is to copy it in a named register, for example the a register by typing
Then, on the command line, type :
<C-r>a and enter.
Ctrl + r will give you a sort of prompt represented by the character
" (for more information read
At this new prompt, if you give the name of a register, its content will be inserted on the command line, where you'll be able to edit it before execution.
Besides if you copy some text without specifying a register, it will be accessible from the unnamed register ".
So suppose you've got a line of vimscript in a file and want to source it quickly, you can copy it with
Y, then source it on the command line with :
:<C-r>" and enter.
Finally, if you use this last solution, there's just a problem you must be aware of.
If you see a strange character on the command line like this
^M, it's the caret notation of the carriage return. You should delete it, otherwise you'll probably get an error.
In summary, you :
- copy your line of vimscript with
- switch to command mode with
<C-r> to enter the registers prompt
" to call the unnamed register
- hit backspace to delete the
- and hit enter.