How to use mouse clicks in Vim and Neovim
To use the mouse in Vim, run :set mouse=a, or put it in ~/.vimrc to keep it. Then you can click to move the cursor, drag to select (Visual mode), scroll with the wheel and resize splits.
Neovim already has the mouse on by default (mouse=nvi: Normal, Visual and Insert mode). If clicks still do nothing, the cause is usually your vimrc, your Vim build, tmux or the terminal. Each has a one-line fix below.
Enable the mouse in Vim
Section titled “Enable the mouse in Vim”" ~/.vimrcset mouse=a " all modes: n (Normal), v (Visual), i (Insert), c (Command-line)set ttymouse=sgr " modern mouse encoding; needed for clicks past column 223The letters of mouse pick the modes: n, v, i, c, or a for all of them. set mouse= turns it off again.
What you get:
- Left click moves the cursor (and focuses a split).
- Drag selects in Visual mode; double-click selects a word.
- The wheel scrolls.
- Dragging a status line or vertical separator resizes splits.
Enable or change the mouse in Neovim
Section titled “Enable or change the mouse in Neovim”Neovim turns the mouse on by default with mouse=nvi. Right-click opens a small popup menu with common actions.
To change it, in init.lua:
vim.opt.mouse = "a" -- also in command-line mode-- vim.opt.mouse = "" -- turn it offvim.opt.mousemodel = "extend" -- right-click extends the selection instead of the menuNeovim removed Vim’s ttymouse option; its terminal UI handles mouse encodings itself.
Why doesn’t the mouse work in Vim?
Section titled “Why doesn’t the mouse work in Vim?”Check these in order.
- You have a vimrc, so
defaults.vimis skipped. Vim’sdefaults.vimturns the mouse on (mouse=ain xterm-like terminals), but only when there is no~/.vimrc. Creating any vimrc silently drops it. Addset mouse=ayourself. - Your Vim has no mouse support. Run
:versionand look for+mouse. Minimal builds (often the “tiny” packages on servers) may not have it. Install a fuller Vim package. - Clicks stop working on the right side of a wide window. The old xterm mouse encoding cannot report columns past 223. Set
ttymouse=sgr. Vim usually detects SGR support, but some terminals report an old xterm version and need it set by hand. TERMis wrong. IfTERMis something likevt100ordumb, Vim may not expect mouse codes.echo $TERMshould showxterm-256color,tmux-256coloror similar.
Why doesn’t the mouse work in Vim over SSH?
Section titled “Why doesn’t the mouse work in Vim over SSH?”Mouse clicks are escape sequences your terminal sends, just like keys, so they travel over SSH unchanged. When the mouse fails over SSH, the problem is on the remote side:
- the remote Vim has no
set mouse=a(your local vimrc is not there), - it lacks
+mouse, - or the remote
TERMis not set to a terminal it knows.
Copy your vimrc lines to the server, or run :set mouse=a in the session to test.
Why doesn’t the mouse work in Vim inside tmux?
Section titled “Why doesn’t the mouse work in Vim inside tmux?”tmux needs its own mouse mode to pass events through and to let you click panes:
set -g mouse onReload with tmux source-file ~/.tmux.conf. In Vim inside tmux, also set ttymouse=sgr; tmux understands it.
How do I select text with the mouse to copy it?
Section titled “How do I select text with the mouse to copy it?”When Vim owns the mouse, a drag makes a Vim selection, not a terminal selection. To copy to your system clipboard, either:
- yank to the clipboard register: select, then
"+y(needs a Vim with+clipboard, or Neovim with a clipboard provider), or - hold Shift while dragging to bypass the app and use the terminal’s own selection. Most terminals support this; some macOS terminals use Option or Fn instead.
Over SSH, the clipboard register has no access to your local clipboard. Use OSC 52; see copy and paste over SSH.
The modeless alternative: Skink
Section titled “The modeless alternative: Skink”If what you actually want is an editor where the mouse behaves like in a desktop editor, Skink has it on with no setup. It works in any terminal, locally or over SSH:
- Click to place the cursor, drag to select (or Shift+arrows from the keyboard).
- Alt+click adds or removes a cursor.
- Click a tab to switch, its
xor a middle-click to close it. - Drag split dividers and the file tree’s border; click gutter marks to peek at git changes or open folds.
- The wheel scrolls; Shift+wheel or a trackpad swipe scrolls long lines sideways.
- Copy (Ctrl+C) reaches your local clipboard over SSH via OSC 52.
There is no mode to be in when you click. Typing types.
curl -fsSL https://skink.cc/install.sh | shMore: mouse and trackpad in Skink, Skink vs Vim, Skink vs Neovim, terminal editors with mouse support.