How to map CTRL+Tab in vim Mac OSX Terminal - terminal

I'm trying to make Firefox keybindings work for tabs in vim (ssh'd into a server through OSX Terminal), however I'm running into issues.
Its basically the same as this Stack Overflow question except for Terminal in Mac not xterm:
Mapping <C-Tab> in my vimrc fails in Ubuntu
From my research, it seems some terminals don't differentiate between <C+Tab> and <Tab>, so I'm wondering if there's some way to hack around this in the Terminal app so vim can understand it. (Maybe escape sequences or something...)
Any ideas?

Long story short: Ctrl-Tab doesn't exist, because Tab is really already a Control key, Ctrl-i.
Short story longer: There is a way to do it, but it requires a sufficiently large amount of hackery at both the terminal and the vim level that you may or may not consider it worth it. I'm working on a much better more generic solution to it but currently I'm not quite sure the world seems to want it.
http://www.leonerd.org.uk/hacks/fixterms/ if you are interested.

In Terminal.app's preferences, you can set some keybindings to send specific character sequences. In your case, you could set <C-Tab to send gt or whatever Vim shortcut you want.
Anyway, you'd better learn the right shortcuts.

Related

vim in Macbook Pro command line doesn't work appropriately

I just switched from a Windows laptop to a Macbook Pro. I have installed vim and macvim using homebrew. Everything works fine with macvim, but in the command line, the vim exhibits weird behaviors.
First, the cursor in the Insert mode (which I suppose should be simply a line) is the same as the Normal mode (which is a rectangle), making it impossible to tell the current mode from the cursor shape. I don't know whether this is normal with vim in the command line because I didn't pay attention before. But this is certainly different from the behavior of macvim and it helps to distinguish the shapes of the cursor in different modes.
Second, the backspace does not work appropriately. It often cannot delete letters in the Insert mode.
I am totally new to OS X, so I would greatly appreciate it if someone can give some hints on how to solve these issues.
Thanks!
Indeed, nothing in your question relates in any way to Mac OS X.
I also like my cursor to change shape when in insert mode, and I use these lines to make it happen in iTerm2:
let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"
This is a hack, and YMMV depending on which terminal emulator you're using. I suggest googling to find the best solution for your case.
The weird backspace behavior you're experiencing is caused by one of the notorious Vim defaults. Simply set
set backspace=eol,start,indent
to make it work as expected.
I suggest starting with or at least skim through Tim Pope's vim-sensible and save yourself some headaches.
When run in a terminal emulator, Vim has no control over the shape of the cursor. Some hacks exist but they only "work" by chance so I would suggest you get used to it and read :help 'showmode'.
Your backspace issue with a simple option. See :help 'backspace'.

Emacs Terminal.app Meta Key - German MacBook Keyboard

Good evening,
I have a problem using Emacs in Terminal.app the last 9 hours but wasn't able to solve it on my own.
The workarounds I have found on Stackoverflow etc. didn't persuade me.
I didn't want to use the Option 'Wahltaste als Metataste verwenden' (alt/option as meta), because I have to type for example {}[] with my alt-key. Keybinding of these Charakters in Emacs is no solution for me, because outside of Emacs in nano I want to use []{}..., too.
I also didn't want to use iTerm2.app, I think it should be possible in Terminal too.
Because sometimes I use Emacs over SSH, it is not possible to choose an GUI-based Emacs either.
A possibilty I would accept is to use the left alt/option key for meta and the right one for typing []{}... Or the Fn-Key for meta...
But I wasn't able to do it the last 9 hours...
I already ported 'emulate-mac-keybord-mode.el' from Aquamacs, but I didn't get it work as expected.
Does anybody have an idea?
Thanks in advance,
Zappel
If you insist on a TTY Emacs within Terminal.app, you may probably have some success with kernel level remappings of modifier keys, using KeyRemap4MacBook. I do not know, because I never used it for such things, and since the key codes, Terminal.app sends to the TTY process when a modifier is pressed, are ultimately hard-coded in Terminal.app, this is neither easy nor particularly pretty.
iTerm2 probably provides means to customize modifiers individually, and is generally a superior terminal emulator (with the notable exception of color management), but frankly, do yourself a favor, and use a GUI Emacs.
A GUI Emacs provides a much nicer expierence on OS X. You are not only able to map each modifier key individually with mac-option-modifier and friends, you also more modifiers available, namely Super and Hyper.
For instance, the following setting uses the Command keys as Meta, the function key has Hyper, and keeps the Option keys for OS X, so that you can still use the alternate layout level:
(setq mac-option-modifier 'none
mac-command-modifier 'meta
mac-function-modifier 'hyper)
To edit files on remote systems, you'd just use Tramp then.

Run terminal inside vim on a macbook?

I searched some old answers on stackoverflow, some of them seem relevant, but none of the solutions work on my macbook (with mountain lion). e.g. The shortcuts mentioned in answers here do not work on my computer: How do I run a terminal inside of Vim?
So I'm wondering if it's because vim on mac/unix is different from a normal linux one. I don't think so, but I'm not sure.
Since I can split the screen with :sp, I'm wondering if it's possible to use one split as terminal and another as the regular vim editor, just like emacs. If so, what's the correct way to do it? (Maybe particularly for mac) If not, it's sad.
Why don't you do things the other way around?
You can use a terminal multiplexer such as Tmux and split a terminal window into two panes using C-b %.
Inside the second pane you can run macvim inside a terminal with $ mvim -v
You can navigate between the two panes with C-b o, (And do much more, but I'll leave it up to you to discover!)
Doing things this way around is much more sane in my opinion, you get the full power of both the terminal and vim without having to hack around with Vim too much (Plus Tmux is very handy for many other uses).
I hope doing things this way around is appealing enough for you!
Having a terminal inside of vim would go against the author's philosophy and design so no: that feature will probably never appear nativelyly in vim.
There are a couple of plugins that more or less work like conqueterm, try them if you really want that feature. Or simply use a separate terminal window like everybody.
You should definitely look at programs like tmux or screen.
But an even simpler solution is to use C-z (which halt vim) to access the terminal and fg to bring back vim into the foreground.

Vim under mac does not behave as expected

I recently got a mac. I was previously working on a laptop with ubuntu and I was using vim.
I now will discuss about vim in console (iTerm2 or the default terminal) and macvim.
The problem is that some binding don't work under mac. For example I had CTRL left/right for navigating between splits, CTRL up/down to move lines or blocks of code up and down, etc. They don't work anymore.
I had a bunch of plugins (nerdtree, powerline, etc.) that now look weird. Powerline doesn't display special characters in macvim and in terminal they are question marks.
In console, nerdtree looks weird and it doesn't display the special triangle character. If I hit return to open a file selected from nerdtree, it doesn't do anything. In macvim, it works ok.
Is there any guide on how to use vim on mac? Or what is the recommended way?
Nerdtree : let g:NERDTreeDirArrows=0
Powerline : Take a look at the part of strange characters in the document https://github.com/Lokaltog/vim-powerline
Navigating within splits with Ctrl + arrows work on mine. Can you post your vimrc, or try running vim without any configuration.
Ctrl+arrows to move lines and block doesn't work on mine.
Did you check which key was sent by your terminal to vim ?
Did you tried to set it manually ?
I had similar problems with emacs, including one keybinding I'm still not able to reproduce :(
I have the exact same config on my Mac and a Windows box at work, my Ubuntu box at home and a couple of VPSes. It works exactly the same on every platform in GVim/MacVim or in plain Vim.
Unfortunately I don't use either NERDTree nor Powerline but Vdt's answer seems to have all the info needed.
Some of the behaviors you describe are custom mappings. You should show us your ~/.vimrc (the old one on linux and the new one on the Mac, if there are differences) so that we can help you make it more portable.
Also, "looks weird" means nothing: please add a screenshot or two.

How to map Shift-Tab in vim? (Cygwin, Windows cmd.exe)

I see a few entries here about making Shift-Tab work in vim, but none of them addresses the failure when it's in Cygwin, running at a Windows command prompt. In that environment, Shift-Tab works for me exactly like an unshifted tab, and my attempts at remapping have failed:
:imap <S-Tab> ^D [ this is a real Ctrl-D, entered with Ctrl-V before it ]
:imap [ typed Ctrl-V, Shift-Tab here; got a Tab character inserted ]
So it seems that the Shift modifier is being ignored. Any thoughts about how to proceed? Thanks.
That won't work in the Cygwin console because it sends the same keycode for both Tab and Shift+Tab: ^I.
You might want to install Cygwin's mintty terminal emulator, which sends the standard keycode for Shift+Tab: \e[Z.
Instead of messing with the Cygwin version, I suggest you remove it and install the native version instead. With that, you can map Shift-Tab without issues, even when starting Vim from a bash shell.
I don't have windows right here now, but look whether your vimrc contains
behave mswin
source ...\mswin.vim
In that case,
:e +g/mswin/norm!\ 0i" $MYVIMRC
should automatically comment these out. Relaunch vim, and inspect whether there are existing mappings:
:verbose map <S-Tab>
will show you any existing mappings, and where it was last defined, so you can find the script/plugin that is causing this (:he :verbose-cmd)
HTH
Update to the comment:
Well - blimey, turns out that Shift-Tab is magically impossible with Win32 Consoles. Never noticed.
Perhaps it is because I
use mintty these days, to provide a much better experience (Unix like copy pasting, real alternative terminals, more performance, and re-attaching screen sessions, e.g.)
might have tweaked the CompletionChar setting although this seems like a loose fodder even to me
Could you try with mintty? I'd think I'd have noticed such a hairy incompatibility over the years. But, you never know :)

Resources