How to rebind ctrl-space in vim running inside Windows Terminal Preview? - vim

So it seems like ctrl-space is being incorectly translated into ctrl-# by the Windows Terminal and I was wondering if there's any workaround for this? I've seen answers to this similar problem for other terminals but they don't seem to work.

This is fundamentally a limitation of the way that most Unix terminals work. The control keys map onto a limited set of characters, so Ctrl-#, Ctrl-Space, and Ctrl-` all map to the same thing and work the same way. This occurs in terminal emulators and the VT running on real Linux systems as well.
It is possible that other terminal emulators have an option for this, but the Windows Terminal attempts to emulate the xterm-256color terminal type, which implements the behavior you're noticing. Even if other terminal emulators do support it, that doesn't mean that programs running in them do; they might receive such a sequence and not know what to do with it, especially if TERM is set to a terminal type that doesn't support the distinction.
According to the Windows Terminal issue tracker, they are aware of this and there is a possibility they may pass these keys in the future using some xterm-specific sequences, but currently this doesn't work. I'm not sure that even if they did implement it that it would work as you expect in Vim, although it's possible it might.
You can either remap Ctrl-# if you aren't using the existing functionality or just use another key.

Autohotkey is a good company for vim in Windows. It can map ctrl-space to any other keys and send them to vim by running scripts.
https://www.autohotkey.com/docs/Hotkeys.htm#Intro
AHKscript like(not tested)
^Space::
send {Ctrl}g
return
Then in vimrc
nnoremap <c-g> ...

Related

Vimwiki C-Enter or S-Enter does not work in Gnome Terminal

I am trying out VimWiki. So far so good, but on Ubuntu 18.04, the Shift-Enter and Ctrl-Enter do not work [1]. Search on the net says Gnome Terminal interprets these key combos as the regular Enter key. So I believe I have to remap these keys to something else or find another terminal program. I have tried Terminator, but it works the same as Gnome Terminal.
[1] https://github.com/vimwiki/vimwiki
You can change the key mappings, or you can run Vim as a graphical application (gvim). You may have to install the relevant distribution package (such as vim-gtk3), it is sometimes split from the pure terminal application.
I suspect the author of this extension is using Vim as a GUI application because I don't think there are many terminals which preserve these key combinations.

What is the difference between gVim and gVim easy?

The question is self explanatory, but I haven't found a single resource that explains what the difference is after an hour of searching. After poking around a little bit in both, it appears that gVim and gVim easy are identical.
Gvim easy is started and locked in insert-mode (every character you type is printed like a simple notepad).
Standard gvim starts in normal mode and you have to toggle between normal/insert like all other vim.
From help:
Easy mode. Implied for |evim| and |eview|. Starts with
'insertmode' set and behaves like a click-and-type editor.
This sources the script $VIMRUNTIME/evim.vim. Mappings are
set up to work like most click-and-type editors, see
|evim-keys|. The GUI is started when available.
{not in Vi}
gVim-Easy, which is installed with gVim, has all the functionality of
normal gVim but lacks modes. This is especially useful for begginers
and people who do not want to, or do not have the time to, learn how
to use gVim. Users can benefit from gVim's superior syntax
highlighting and auto-indentation while not having to have to learn
the, often deemed complex, command set of gVim in order to edit a
simple document. It is recommended that readers of this tutorial at
least try to learn how to use gVim in normal mode, the learning curve
is steep, but, the benefits in speed and usability this confers is
worth the investment.
Read here
gVim Easy: gvim.exe -y (pass a parameter y)
gVim: gvim.exe
It seems that Insert and Replace are available modes, and command mode is missing. And at first glance it appears to have lost the ability to save a document using keystrokes - the File menu shows only ":w" for Save and without command mode, the command simply isn't there. What isn't shown however is Alt-F followed by S - this works, although also missing is the status line confirmation of the file being written.

Tmux vs. iTerm2 split panes

Why should I use tmux when iterm2 has split panes?
I have never used tmux, and want to know if there are advantages to using that in my workflow instead of the split pane features iterm2 has.
I really like the dimming of inactive windows that iTerm2 split panes offers. Does tmux do something similar?
What are the advantages/disadvantages of each?
There is another advantage of tmux: what happens if you accidentally close iterm2? If you do it really by accident, you want to reopen everything again. With tmux it is normally as simple as reattaching session without losing anything. Most terminal emulators send SIGHUP to all children which terminates them by default and thus you lose unsaved data (at least, shell and vim command history and other data stored in viminfo) and running processes and thus reopening means rerunning everything.
iTerm2 can use tmux for it's split panes. Personally, I'm used to tmux by itself at this point, so I've not leveraged this ability extensively - but if you are used to iTerm2 split panes, you can get the benefits of tmux (mostly screen-like session saving) with the iTerm aesthetics.
https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration
My approach (not based on any particular insight) is to use iTerm tabs and panes to separate servers, and screen / tmux on the server to persist sessions.
I don't often have anything of importance running locally, but often do remotely.
Never used iterm2, however I have played with tmux a little and there are several articles about using tmux and vim together. These articles show how you can control a tmux session via the tslime plugin, and others, from Vim. What's nice about it is that you can run a command in Vim to compile your files, run unit tests, etc. without every leaving Vim, but you see the command run in the other tmux pane.
Apologies for not being a complete answer, but hopefully it helps point you in the right direction.
LINK: https://joshuadavey.com/2012/01/10/faster-tdd-feedback-with-tmux-tslime-vim-and-turbux/

MacVim: Any idea why I can't override the Command button?

I am trying to use the command button in MacVim instead of Ctrl and other buttons.
I tried something like :imap <D-space> <Esc> to override the normal Command-space functionality while in MacVim but it still performs the spotlight.
Any ideas?
In these cases its usually the window manager intercepting the key-stroke before the application ever sees it. There may be an option to turn off certain global key-bindings when a specified app is active but I've been unable to find it on 10.5 - linux window managers have this functionality, as does windows, so I'd expect its hiding somewhere in the OS WM..
The Spotlight shortcut takes precedence over your own shortcut.
To be able to use it in MacVim you must change Spotlight's shortcut in its preferences.
However, the Command key won't work in Terminal.app and won't be sent to remote servers connected by SSH. If you use Vim on a server you won't be able to use it and you will be forced to either create and learn lots of machine-specific mappings or simply use the defaults.
Another possible issue, one I encountered at the beginning, is that shortcuts with multiple modifier keys (like <D-M-something> or <C-S-something>) don't work in MacVim.
Because of that and the number of native shortcuts using these keys you won't have many possibilities.
When I decided to learn Vim (with MacVim), I tried a lot of things to make it (and Vim) more "Mac-like" or "TextMate-like" to no avail.
Instead i suggest you to do things the Vim way. It may seem weird but it's worth it.
In your case, the "Vim way" would be to use mapleader, it's a regular key on your keyboard that is used for custom mappings. The default key is \, if you want to change it (to , for the example, that's my settings but YMMV), add this line to your ~/.vimrc:
let mapleader=","
After that you can create mappings like this:
inoremap <leader><Space> <ESC>

Is there a way to “hide” Vim’s interface to see the underlying shell?

Something as light as buffer switching. So I can quickly jump there and back to check, for example, the output of the last !-invoked command.
I know there is the :sh command, but then you have to exit it to get back to Vim, so it is a bit heavy for the purpose.
I am also aware of http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window but I am not a huge fan of splits.
Try Ctrl-Z, also accessible from the built in command :suspend. Does that do what you want?
If you do not mind not having scrolling, use
:!
(That is, run the ! Ex command without arguments.)
Otherwise, if you are running the terminal version of Vim,
use :suspend or Ctrl+Z (the latter
keyboard shortcut works in Normal and Visual modes).

Resources