vimtricks.wiki Concise Vim tricks, one at a time.

How do I enable mouse support in Vim?

Answer

:set mouse=a

Explanation

How it works

The :set mouse=a command enables mouse support in all Vim modes. With this setting, you can click to position the cursor, scroll with the mouse wheel, drag to select text in visual mode, and resize splits by dragging the dividers.

The mouse option accepts different mode flags:

  • a - Enable mouse in all modes (most common)
  • n - Enable mouse only in normal mode
  • v - Enable mouse only in visual mode
  • i - Enable mouse only in insert mode
  • c - Enable mouse only in command-line mode
  • (empty) - Disable mouse entirely: :set mouse=

You can combine flags, for example :set mouse=nv enables mouse in normal and visual modes only.

With mouse enabled, you can:

  • Click to position the cursor anywhere
  • Click and drag to make visual selections
  • Scroll with the mouse wheel to move through the file
  • Double-click to select a word
  • Triple-click to select a line
  • Drag split borders to resize window splits
  • Right-click for a context menu (in some terminals)

Note: Mouse support depends on your terminal emulator. Most modern terminals support it, but some older or minimal terminals may not.

Example

Add to your ~/.vimrc for permanent mouse support:

set mouse=a

Or to temporarily enable it in a session, type :set mouse=a. To disable it again, use :set mouse= (empty value).

Some users prefer to keep the mouse disabled to enforce keyboard-only navigation, which is generally faster for experienced Vim users. A good middle ground is :set mouse=n which allows clicking in normal mode to position the cursor but does not interfere with terminal text selection in insert mode.

Next

How do you yank a single word into a named register?