20

I want to be able to select columnar blocks using only the keyboard when I use GVim on Windows, but I do not seem to be able to do so when using gvim (7.2) on Windows XP. Edit: For convenience, it is preferable to make the selection with arrow keys as is commonly done in other versions of vi/vim.

In a terminal, when using vim, to define a block, one may select columnar blocks by pressing Ctrl-V and by conveniently moving the cursor with the arrow keys.

When using GVim on mswin, Ctrl-V is mapped to a paste operation. Every reference found on this topic mentions that on mswin, Ctrl-Q is set to act the same way that Ctrl-V works on other platforms, but this does not work for me.

After research indicated that the Ctrl-Q behavior is implemented through the inclusion of mswin.vim, it seemed that perhaps mswin.vim was not being loaded by GVim. mswin.vim is apparently loaded via _vimrc. It seemed that perhaps mswin.vim was not loading, so perhaps _vimrc was not setup correctly, but...

C:\Program Files\Vim\_vimrc exists contains:

source $VIMRUNTIME/mswin.vim
behave mswin

C:\Program Files\Vim\vim72\mswin.vim exists and contains:

" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q>       <C-V>

C:\Program Files\Vim\_vimrc should load since Edit | Settings Window in the GVim graphical menu loads this file for editing, and it is clear that C:\Program Files\Vim\vim72\mswin.vim is loading because one can insert a syntax error in that file and GVim will complain about it when it starts up (it was backed it up for testing and restored to prevent accidental corruption).

When Ctrl-Q is pressed, the cursor changes in the same way that it changes when you block select text using the mouse, but any cursor movement at this point causes the cursor to change back to a normal cursor. It does not matter whether one continues to hold Ctrl, Ctrl-Q, or not.

Edit: Ctrl-Q enters block selection mode as indicated by the cursor change since other cursor movement commands extend the block, however, the original intent of this question was to learn how to use the arrow keys (in the same manner that they are able to be used in other implementations of the editor) though this was not explicitly stated in the original, unanswered revisions of the question.

It is possible to visually select columnar blocks by pressing Alt while holding down the left-mouse button, but Alt during arrow key motion after pressing Ctrl-Q also does not work.

Research also seemed to indicate that pressing v in command-mode would enter visual-mode, and that perhaps this was relevant, but using this does not seem to help the situation.

C:\Program Files\Vim\vimfiles does not contain anything except an empty directory structure. C:\Documents and Settings\username does not contain vim configuration files, nor does C:\Documents and Settings\username\My Documents. Other C:\Documents and Settings\username locations, where application-specific or local settings are commonly stored, also appear not to have vim settings. The same is true for %HOMEDRIVE% and for the environment variables.

kbulgrien
  • 4,384
  • 2
  • 26
  • 43

3 Answers3

21

One way to visually select column blocks in GVim on Win32 using only the keyboard is to press Ctrl-Q, release it, then press and hold down the Shift key while using the arrow keys to select the column block.

Why Ctrl-Q columnar selection behaves this way is not known, but it does not really matter since the goal was to select column blocks using only the keyboard. In Vim, Shift is not used when using Ctrl-V to select blocks.

:help mswin does not mention this nuance of the CTRL-V alternative.

kbulgrien
  • 4,384
  • 2
  • 26
  • 43
  • Though I upvoted `romainl`'s response and "selected" it by unloading `mswin.vim`, it does not answer the original question in the strictest sense. The original, unanswered revisions of the question omitted mention that use of arrow keys was desired (as used in other revisions of vi/vim), so `Ingo Karkat`'s suggested command sequence of `j`, `1`, `w` is understandable and educational, but still does not address the intent behind the question. In summary, this answer is still the one that answers the asked question, though `romainl`'s expanded perception of the problem is greatly appreciated. – kbulgrien Jan 07 '13 at 15:02
  • It's been a while, but you may find it interesting. You've wondered `Why Ctrl-Q columnar selection behaves this way`: because it **switches the selection type**. Current selection, not future highlight action! Please try this: move cursor to startpos of the desired block, press and hold shift, move cursor to endpos of the desired block (IGNORE that it does normal line selection), now release shift and press `Ctrl+Q`. The linear-selection from start-to-end will turn into vertical/block-selection from start-to-end. Now, if you then had instantly moved the cursor, you were cancelling selection! – quetzalcoatl Jul 01 '13 at 10:03
3

The best thing to do is to remove these lines from your vimrc. They are totally unecessary and change too many basic Vim features.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 1
    +1 After finding that GVim also did not do keyboard-only copy/paste the way I do in Vim, I am inclined to agree. I do not recall how _vimrc came to have this setup in it, but now wonder if it is installed that way by default. Your answer got me digging around and found that I had last edited _vimrc back in '09, and that the edited file was missing the source of mswin.vim while a backup copy marked "original" had it present. My old system crashed and I guess I forgot that I had customized my _vimrc. I've been avoiding GVim because of stuff like this - perhaps I can stop avoiding its use now. – kbulgrien Jan 04 '13 at 21:49
0

The noremap <C-Q> <C-V> in mswin.vim remaps the original command to Ctrl + Q.

If mswin.vim is included, after pressing Ctrl + Q, the indicated mode should switch to Visual Block, and any movement (e.g. j, l, w) extends the visual selection. If that doesn't work for you, you may have something interfering.

Are those movement commands itself remapped, or is there an autocmd on CursorMoved?! Try disabling your plugins (vim --noplugin) and most parts of your .vimrc.

Note that cursor keys do not normally constitute proper movement (and their use in Vim is frowned upon).

What you perceive as the right (and only) way to extend the selection (with shifted cursor keys) is just a consequence of :set selectmode=key, as done by :behave mswin.

kbulgrien
  • 4,384
  • 2
  • 26
  • 43
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 1
    "... cursor keys do not normally constitute propr movement (and their use in Vim is frowned upon" is quite unhelpful and indicates that a longstanding, normal way of using a keyboard to indicate movement is improper, though gvim itself support such input when `mswin.vim` is not included. – kbulgrien Jan 07 '13 at 13:56
  • The statement describing the perception of the OP with respect to a "right (and only) way to extend the selection" is presumptuously incorrect. The referenced answer simply documents a way to obtain the desired behavior and makes no assertion whatsoever that there are not other correct and proper ways to accomplish column selection. – kbulgrien Jan 07 '13 at 13:58
  • 1
    Re "longstanding, normal way of using a keyboard": When vi (Vim's predecessor) was created, there were no cursor keys. http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/ Due to their distant position, they are still ineffective for quick editing. – Ingo Karkat Jan 08 '13 at 01:03
  • 1
    It is certainly a blessing that we are not required to constrain ourselves to the limitations of the past. This issue makes me keenly aware that I am similarly thankful that Bram Moolenaar did not slavishly cripple himself to the limitations of the past. Distance of position is of minor consequence in this instance. When editing columns, I am rarely generating content, and any slowdown by distance is made up by the ease of remembering how to use a tool because so many other tools work that way too. I used vi on SVR3/SVR4. I am not about to go back. It should be easy to figure out why. – kbulgrien Jan 08 '13 at 13:58