syntagma
syntagma

Reputation: 24324

Change behaviour of <Space> when there is a specific character under the cursor

I would like to alter the behavior of <Space> when there is a specific character under the cursor, i.e. when " is under the cursor, I would like to add a space before it (without changing mode).

Is that possible (I am mainly interested in altering the behavior of space and recognizing character under the cursor - I think I will know how to go from there)?

Upvotes: 0

Views: 41

Answers (1)

Kent
Kent

Reputation: 195059

Yes, this can be achieved, you can use a <expr> map. there you check the char under the cursor, if it is ", you add a space before it, otherwise do same as press space. This is the line, you can :h xxx to check the details of functions used in case you don't understand what it does:

nnoremap <expr> <space> '"'==matchstr(getline('.'), '\%' . col('.') . 'c.')?"i <ESC>":"<space>"

Upvotes: 2

Related Questions