Home

Fix Espanso Cursor Hint Positioning In Neovim

-- tldr/

Add this to your Neovim init.lua file to let
Espanso reposition the cursor properly

-- code
-- lua

vim.o.whichwrap="b,s,["


-- /tldr


-- h2

The Problem

I use Espanso for a text expander. One great 
feature is the ability to reposition the cursor
inside the expanded text with a `$|$`` cursor
hint. For example, this would position the
cursor between the two div tags after the
expansion:

-- code

<div>$|$</div>

-- p

Sadly, it didn't work in Neovim. Espanso 
simulates left arrow keypresses to move the cursor. 
Using the left arrow in Neovim works, but only 
up to a point. It won't move to the prior line. 
Any expansion that tries to do that ends up
with the cursor stuck at the first character
of the last line. 


-- h2

The Fix

Neovim has a `whichwrap`` config option that 
provides a fix for the issue.  The option defaults 
to "b" and "s" which let the backspace and space
keys to move to the preceding and following lines, 
respectively. Adding "[" to those (as shown above) 
lets left arrow move to prior lines in Insert 
and Replace mode. Insert mode being where Espanso
would be doing the expansion.

This works inside regular expansions and with
the output from scripts as well.

Took me a bit to figure out what was up. Now
that I've got it working, I'm using Espanso 
even more.


-- ref
-- title: Espanso
-- url: https://espanso.org

A very nice open-source text expander

-- ref
-- title: Neovim
-- url: https://neovim.io

The hyperextensible Vim-based text editor

-- ref
-- title: Espanso - Cursor Hints
-- url: https://espanso.org/docs/matches/basics/#cursor-hints

This is how to setup where you want the cursor to go. Note that
if editors do additional formatting (e.g. tabbing) it won't 
work as expected since it can't the editor changes

-- ref
-- title: Neovim: whichwrap option
-- url: https://neovim.io/doc/user/options.html#'whichwrap'

One of the one-zillion config options in Neovim
~ fin ~