0

I use vim in xterms on Arch linux. Wanting to automatically set marks for subsequent command ranges I wrote this mapping

map <LeftMouse> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>:call cursor(g:nc[1], g:nc[2])<cr>  

but now the mouse no longer places the cursor at the clicked location. How can I keep standard mouse function, and add to it rather than replacing it?

2 Answers 2

2

It seems its not possible to modify LeftMouse, but you can achieve the effect of it using LeftRelease. So my mapping does what I want as

nmap <LeftRelease> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>

and the standard function of is unchanged.

Sign up to request clarification or add additional context in comments.

Comments

1

You can :set mouse=a for using visual select mode. (This is not what you wanted but it is a trick). Then, click on text, you will see that it is getting selected. Then, you can release it.

A mapping like

 :map gv ma

will set the last recently selected text as mark a.

Other way:

Instead of :set mouse=a, you can press v and then select a letter or a word, depending upon your convenience and then ma for marking it as mark a. A short mapping for it will be

:map vly ma

2 Comments

Thanks, but I wanted to achieve the result, marking ranges for commands/functions, by using something i already was doing - clicking the mouse to relocate the cursor. I finally settled on this mapping: 'nnoremap <silent> <LeftMouse> <LeftMouse>:call setpos("'o", getpos("'p"))<cr>mp'. I hadn't understood the use of nnoremap, without it the mapping would just produce an endlessly repeated click.
Now, you have found a solution, isn't?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.