You are not logged in.

#1 2016-11-24 11:59:52

bstaletic
Member
Registered: 2014-02-02
Posts: 658

[SOLVED] Vim CursorHold and CursorHoldI autocommands not working

Hello,

I've been trying to make vim exit insert mode automatically after 'updatetime' if already in insert mode and write the buffer to a file after the same 'updatetime' if in normal mode. The way I tried to do it is by declaring a cursorgold augroup like the one below:

augroup cursorhold
	autocmd!
	autocmd cursorholdi * <Esc>
	autocmd cursorhold * w
augroup END

However the CursorHoldI returns an error:

Error detected while processing CursorHoldI Auto commands for "*":
E492: Not an editor command: <Esc>

The CursorHold autocmd is seemingly never triggered, but when I start vim it displays

--- Auto-Commands ---
Press ENTER or type command to continue

and waits for any key press before opening a vim window.

I've also tried prefixing <Esc> with \ but it made no difference.

EDIT:
The second autocmd works now that I've changed it to:

autocmd CursorHold * update

Still, I have no idea why it didn't work earlier.

Last edited by bstaletic (2017-01-27 14:09:21)

Offline

#2 2017-01-25 00:48:32

sabreuBR
Member
Registered: 2017-01-25
Posts: 1

Re: [SOLVED] Vim CursorHold and CursorHoldI autocommands not working

I suspect autocmd doesn't allow special chars < > .
But you can do it inside a function, usually au call functions.

this information is in the fantastic book "Learn Vim the Hard way".

Other thing: typing, if I am not wrong demands a "normal" keyword before.
Typing via script usually is
normal \<Esc>

Try:

function! MyIdle()
   normal <Esc>
endfunction

           au  ...      ...... *   call MyIdle()

Last edited by sabreuBR (2017-01-25 11:14:16)

Offline

#3 2017-01-27 14:08:57

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: [SOLVED] Vim CursorHold and CursorHoldI autocommands not working

sabreuBR,

Thanks for the reply. Unfortunately I gve up on that idea and have made many changes ot my configuration in the mean time.
Using normal is a great advice. I'll keep that in mind.

I'll mark this as solved.

Offline

Board footer

Powered by FluxBB