Change cursor shape in command-line mode

30 views
Skip to first unread message

Enan Ajmain

unread,
Jun 16, 2023, 2:42:41 AM6/16/23
to vim...@googlegroups.com
Vim allows changing cursor shapes according to the current mode: insert,
replace, or normal. Vim does this using terminal escape sequences.
Details are in ':h termcap-cursor-shape'.

I was wondering if I could change the cursor shape in command-line mode.
I'm fairly certain it's not possible, but I thought it wouldn't hurt to
ask.

--
Enan

P.S. I mistakenly sent this email to vim-dev list. Apologies if it
cluttered your mailbox.

Bram Moolenaar

unread,
Jun 17, 2023, 4:06:07 PM6/17/23
to vim...@googlegroups.com, Enan Ajmain

Enan Ajmain wrote:

> Vim allows changing cursor shapes according to the current mode: insert,
> replace, or normal. Vim does this using terminal escape sequences.
> Details are in ':h termcap-cursor-shape'.
>
> I was wondering if I could change the cursor shape in command-line mode.
> I'm fairly certain it's not possible, but I thought it wouldn't hurt to
> ask.

You should be able to make this work with the CmdlineEnter and
CmdlineLeave autocommand events. You can use echoraw() to output the
terminal codes. As a starting point, this appears to work:

au CmdlineEnter * call echoraw("\<Esc>]12;red\x7")
au CmdlineLeave * call echoraw("\<Esc>]12;blue\x7")

--
What is the difference between a professional and an amateur?
The ark was built by an amateur; professionals gave us the Titanic.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Enan Ajmain

unread,
Jun 18, 2023, 11:54:26 AM6/18/23
to Bram Moolenaar, vim...@googlegroups.com
On Sat, 17 Jun 2023 21:05:58 +0100
Bram Moolenaar <Br...@moolenaar.net> wrote:
> Enan Ajmain wrote:
>
> > Vim allows changing cursor shapes according to the current mode: insert,
> > replace, or normal. Vim does this using terminal escape sequences.
> > Details are in ':h termcap-cursor-shape'.
> >
> > I was wondering if I could change the cursor shape in command-line mode.
> > I'm fairly certain it's not possible, but I thought it wouldn't hurt to
> > ask.
>
> You should be able to make this work with the CmdlineEnter and
> CmdlineLeave autocommand events. You can use echoraw() to output the
> terminal codes. As a starting point, this appears to work:
>
> au CmdlineEnter * call echoraw("\<Esc>]12;red\x7")
> au CmdlineLeave * call echoraw("\<Esc>]12;blue\x7")
>

Works perfectly. I thought of using autocommands but didn't know about
"echoraw()". The helpdoc says to use it carefully because it may mess
up the console, but I'll see to it when it happens.

Thank you.

--
Enan
Reply all
Reply to author
Forward
0 new messages