Keyboard-only column block selection in GVim Win32, or why does Ctrl-Q not emulate Ctrl-V when mswin.vim is included? - windows

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.

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.

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

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.

Related

Sublime 4/Vintage: repeat key on key down only in edit mode

On my mac, I need to be able to access special characters such as accents for editing purposes and for now I access this by holding a key down and then get the suggestions shortcut.
However, I would like to use the Vim mode in Sublime as well so moving around with h, j, k, l is quite tedious if I can't hold the key down to move faster.
Is there any way to only repeat a key when pressing it down in edit mode, or to have this behaviour only for h, j, k, l?
Thanks
Probably unsurprisingly, the press-and-hold-for-special-characters behavior is a macOS feature. It doesn't seem possible to change the behavior on the fly. You can adjust it per app like this:
defaults write com.sublimetext.4 ApplePressAndHoldEnabled -bool false
So the question becomes: how can you enter special characters in insert mode? In vanilla vim, you could use inoremap to replace, say, Option+l with "ł". However, NeoVintageous (which I hope you're using, not the deprecated Vintage mode) does not support remaps in insert mode. It claims to support digraphs, which would be another way of achieving this. However, the keyboard command to insert a digraph is Ctrl+k, which conflicts with one of the default Sublime Text key bindings on macOS. (The one to kill from the cursor to EOL, which is copied from Emacs and available in standard macOS text fields.) It's presumably possible to work around this, but I felt like Ctrl+k+l+/ was kind of wordy anyway.
Fortunately, there IS a fast, simple solution: a Sublime key remap. Open your user key bindings (Sublime Text > Preferences > Key Bindings) and add this one:
{ "keys": ["option+l"], "command": "insert", "args": {"characters": "ł"} }
Now Option+l will add the l-slash character to your document. If you need the special character this is replacing (the not sign "¬"), you can of course choose another binding.
I presume this is the one you want, since it's the only special character available for me when I press-and-hold any of the hjkl keys. But this approach will work equally well for any other characters you might want to insert.

Using Alt Key in FakeVim mode of Qt Creator?

It's really handy when you work with VIM text editor to use Alt key to execute normal mode commands in insert mode, for example when you are in insert mode you can press Alt + j to go one line down. But in FakeVim mode of Qt creator this couldn't be done. Any suggestion is welcome.
Pressing Esc each time you want to go to normal mode really sucks.
(not a fix to your problem, just discussing it in a properly formatted text)
I never hit <ESC> as well, and this is a deal breaker for me. Note that it's not a vim feature, though : this behavior occurs because using Alt with an other key in terminals generates an escape sequence. So there's nothing wrong with FakeVim regarding Alt implementation, the problem is related to the IDE being a QT window. You can't use Alt sequence in GTK's Gvim as well, for the same reason, last time I checked.
A possible easy fix on the QCreator part : provide an option to not pass Alt combinations, like the one existing for Ctrl. That is, if QT allows that. We could then at the very least define vim bindings using Alt key to simulate the terminal behavior.
In the list of others exotic combinations from terminals that quickly lead to form habits in vim, I also use C-j in place of <return>, and C-h instead of <backspace>. Those would really be nice to have too :)

ConqueTerm bash in Vim, key input delayed

I've just found out that I can use ConqueTerm to bring up a terminal window in Vim. But I have an annoying issue regarding this.
Lets say I go into insert mode to type commands, and then want to exit insert mode, it will not work unless I press Esc key and a different key. It seems to be a set timeout or delay of some sort. Symbols and characters show up in the bottom right corner of the terminal window.
I had the same problem when editing files in vim, but added "set timeoutlen=1000 ttimeoutlen=0" to my .vimrc which sorted this out for me. But I've been looking around and I cannot seem to find anything similar for ConqueTerm. My guess is that something is to be put/edited in "~/.vim/autoload/conque_term.vim"?!
Any help would be most apprechiated!
Thanks

How do I switch tabs based on incremental search in vim?

For example, let's say I have three tabs open in vim:
1: nice_program.c
2: something_fun.h
3: super_script.sh
So if I hit some magic modifier key, and then type 'n' and hit enter I change tab to tab 1. Likewise, typing 'su' instead will navigate me to tab 3 instead.
Is such behavior possible? There are so many vim extensions, and I dont really get the whole vim extension lingo.
BTW, I am using gVim on XP and MacVim on OS X. Preferably the solution will work on both...
EDIT:
Note that I only want the incremental search to search across the names of the open tabs. That is, it's not supposed to actually search inside the tabs themselves.
Also, I never use buffers, it's tabs that I want this working for.
From the wording of the question it seems that you take the idea of tabs in
Vim not the way it is supposed to be taken by design of this feature. A Vim
tab page is not a form of a buffer or a window, it is a window layout
container, instead. No wonder there is no built-in way for switching to a tab
by the name of a buffer that is active (or the only one in its tab page, or
special in some other way). Semantically, that is switching to a buffer, not
a tab (but tab could be switched in order to show a buffer, if it is
necessary).
To switch to a buffer by its name use the :sbuffer command (:sb, for
short). It is not necessary to type the whole buffer name each time, since
the command has auto-completion. Usually one have to type only few letters of
a name to uniquely identify a buffer (the same way as you described
incremental search in the question).
By default, Vim open the requested buffer displacing one in the current
window. This behavior is governed by the switchbuf option. One of the
choices (called usetab) provided by that option allows to switch to a window
in another tab page if that window contains the buffer to edit. This is
exactly what suits your manner of work with tab pages.
To summarize, change the switching behavior as follows
:set switchbuf=usetab
and use the :sb command to open a buffer by typing a few letters of its name
and using Tab-completion.
I use this snippet I picked up in vim wiki to switch between open buffers (mapped to F5):
" switch between numbered buffers
:nnoremap <F5> :buffers<CR>:buffer<Space>
(put in your .vimrc file or whichever dotfile you use).
As for incremental search across open buffers, whenever I look up something using either /[something] or with */# on current word, it's automagically also highlighted in other buffers/tabs. Then I can switch buffers and hit n or N to move between matches in the currently viewed buffer. That's already baked into Vim.
Hope that helps.
The :set switchbuf=usetab solution given by ib never worked for me for whatever reason (even without loading plugins or my .vimrc) but :tab drop name-of-file works just the way you want (I found it on the Vim wiki).
Make it a custom mapping to save a few keystrokes with nnoremap <leader>t :tab drop.
Also I second ib's comment on the right and wrong way to use tabs in Vim.

Why does < C-a> (CTRL+A) not work under gvim on windows?

I'm trying to use the < C-a> (CTRL+A) shorcut under vim to increment a variable under the cursor. This works fine under vim running on Linux. However when I try to do this in gvim under windows it "selects all" (i.e. highlights or visually selects all text in the current window). How can I change this behaviour or alternatively how can I recover the increment variable functionality (e.g. perhaps with a different key mapping)?
This is because of mswin.vim that is sourced by the default _vimrc generated when you install vim.
Just override your _vimrc with the .vimrc you are using under *nix, or delete mswin.vim.
I know I'm late to the party, but I thought I'd share the following:
nnoremap <kPlus> <C-a>
nnoremap <kMinus> <C-x>
This remaps increment to the + key on the numeric keypad and decrement to the - key. It's the solution I've used in my own _vimrc file on Windows. It keeps the Windows compatibility and is easier to remember than the original Ctrl+A/Ctrl+X as well.
Vim on Windows has specialized key mappings by default to make shortcuts more "windows-y". These are specified in the $VIMRUNTIME\mswin.vim file, which is loaded via your vimrc unless you disabled it. You can edit the mswin.vim file (you may want to edit a copy instead, changing your vimrc to use your edited copy instead).
I'm not entirely sure it's a default Vim mapping, since the only reference I can find on Ctrl+A in the help file is this, which doesn't seem to do what you are referring to:
*c_CTRL-A*
CTRL-A All names that match the pattern in front of the cursor are
inserted.
so you may want to check your Linux box to see if any plugins or anything change the key mapping. (Of course, it may be that I just can't find the appropriate part of the Vim help.)
in the current version of mswin.vim provided with gvim, the file checks for the value of a global named skip_loading_mswin; If set, the rest of the file is skipped; thus it is sufficient to add
let skip_loading_mswin=1
to $HOME/_vimrc and normal vim bindings will be restored the next time you start vim.
If you just do not like CtrlA behaviour but are fine with other windows behaviours in VIM (like CtrlZ for undo), just disable that specific line:
Edit said file (c:\Program Files\Vim\vim73\mswin.vim for me)
Find the paragraph starting with CTRL-A is Select all
Prepend all (6) lines of that paragraph with opening brackets (")
Reopen your GVIM windows.
You can still "select all" by typing ggVG (position cursor at first line, select entire line, select until the last line of the document).
Happy incrementing!

Resources