How do I create a mapping that works only in visual mode?

You can create mappings that work only in specific modes (normal, command, insert, visual, etc). To create a mapping that works only in the visual mode, use the “:vmap” command:

    :vmap  

This mapping will work in visual and select mode. If you want the map to work only in visual mode (excluding select mode), use:

    :xmap  

and to have the mapping only work in select mode (but not visual mode), use:

    :smap  

Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.

Introduction to Recursion and Backtracking

Sorting Algorithms

Introduction to C Programming Language

And More...

Speak Your Mind