Skip to main content

Advanced Vim Concepts

Using Mouse Mode in Vim

Think of mouse mode in Vim like adding touchscreen controls to a cockpit - the physical switches and dials remain the primary interface, but the touchscreen provides intuitive access for certain operations.

Warp Terminal

I hope I am not committing blasphemy but you can use the mouse in Vim.

Press Esc to go to command mode in Vim and use:

:set mouse=a

It will enable mouse mode immediately in all Vim modes, i.e. normal, insert and visual. To disable the mouse mode, use this:

:set mouse=

If you want to use mouse mode all the time, I am not judging you, add this entry to your ~/.vimrc file:

set mouse=a

Save, restart Vim, and your mouse now works for clicking, scrolling, and selecting text.

What does mouse mode do in Vim?

First thing first, the mouse mode has limited usage in Vim. Don't expect to get a notepad like experience just because you enabled mouse mode.

It does add some functionality and ease of use like:

  • Jump to exact locations without counting lines or using search
  • Wheel scrolling while dealing with long files
  • Easy text selection: double click to select a word, triple click to select an entire line, use mouse click and drag for the desired text selection
  • Click between panes and resize them easily while using split windows in Vim
  • While using tabs in Vim, click on other tabs to switch, click on X (should be visible at top right in mouse mode) to close a tab, double click on tab bar to create new empty files in new tabs
  • Use middle click to paste from system clipboard

The video below shows some of the above discussed featured in action:

0:00
/0:21

Vim Mouse Mode demonstration

Mouse mode doesn't replace Vim's keyboard efficiency - it complements it. Think of it as having both a sports car's manual controls and cruise control available.

📋
Mouse mode behavior varies by terminal and some terminal emulators may require specific settings. If you are using tmux, ensure both Vim and tmux have mouse mode enabled for proper interaction.

Understanding mouse mode Options

Vim's mouse configuration works like a permission system:

set mouse=a     " All modes (normal, visual, insert, command)
set mouse=n     " Normal mode only
set mouse=v     " Visual mode only  
set mouse=i     " Insert mode only
set mouse=c     " Command mode only
set mouse=nv    " Normal and visual modes

Mostly, you would want mouse=a - which is like having universal access rather than mode-specific restrictions.

💡
You can refer to Vim's official mouse documentation: :help mouse-using

Conclusion

I am not a Vim purist and I won't judge you if you use mouse in Vim, which is known for its keyboard-centric approach to productivity.

Mouse mode doesn't diminish Vim's keyboard efficiency - it provides additional options for specific scenarios.

If you feel too uncomfortable with Vim at the beginning, opt for the hybrid approach where you use mouse for navigation and positioning, keyboard for editing operations.

I welcome your comments.

Abhishek Prakash