Question

My mswin.vim contains the following command for Ctrl-A

inoremap <C-A> <C-O>gg<C-O>gH<C-O>G

This command correctly selects all lines in the file but also makes the cursor jump to the end of the file (undesired side effect). Is there a way to "select all" without moving the cursor?

Thanks in advance for any help or suggestion.

Was it helpful?

Solution

I am afraid that this cannot be achieved. Since in visual selection mode, the cursor will be either at the beginning or end of the visual range. Any motion in visual mode will lead to the visual selected range changes ( depends on the visual mode: char/line/block-wise).

The point is, what do you want to do after select-all and kept the cursor position? It may be a X->Y problem, just tell us what is your final goal. There could be better solution for it.

Btw, C-A is so useful to increment numbers, maybe you want to reconsider the map trigger?

OTHER TIPS

The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste.

You might take a look at getpos setpos - maybe you can wrap what you want in something like this:

function! TestFunc()
    let save_cursor = getpos(".")
    normal ggVG
    " -- do something
    call setpos('.', save_cursor)
endfunction

In vim you can do this by going to the text you want to delete. Instead of typing I for insert type v starting from the text you want to delete. Next, you can arrow down to where you want to delete the text, then press v again. You now have selected the text range you want to get rid of. next press I and backspace. source https://www.cs.swarthmore.edu/oldhelp/vim/selection.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top