vim in Macbook Pro command line doesn't work appropriately - macos

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'.

Related

Clear terminal without clearing first line of multi-line prompt

I'm trying to setup the terminal on my new Mac to match the behavior of my old Mac, however I have run into an issue with my multiline prompt that has me stumped. I remember having this issue when I setup my old Mac several years ago, however I don't remember how I solved it.
My prompt (without color) looks like this:
╭─username ~ 130 ↵
╰─
When I press ⌘commandK in iTerm2 on my old Mac it clears the terminal window so that both lines of the prompt are shown at the top.
When I press ⌘commandK in iTerm2 on my new Mac it clears the terminal window so that only the second line of the prompt is shown at the top.
I have tried checking everything I could think of, I have checked:
Every dot file/directory in my home directory (copied them to the new Mac).
iTerm2 settings.
System settings (primarily keyboard shortcuts).
Various websites with instructions about setting up multi-line prompts.
Interestingly I have discovered that if I type clear iTerm2 will clear the screen and leave the top line showing on both Macs. However it first clears the entire screen, including the prompt, before bringing the prompt back (looks bad imo). However since it works differently ⌘commandK does I don't think that's what my old Mac is doing.
It's possible that I installed some program/script that somehow does this, but if so I'm not finding it locally or referenced online.
Does anyone know how I can get ⌘commandK working to clear the screen while keeping the top line of my prompt? I still have the old Mac so I can check/compare anything on it to the new Mac if there are any guesses about what settings I changed.
Edit:
I was able to find something that worked, however if anyone has any other suggestions I'll be happy to try them and accept any that I can make work that are less hacky than this (e.g. don't require another 3rd party app).
Edit: This doesn't work while a command is running, nor does it clear the scrollable history. So it's better than nothing but still doesn't behave like I want it to.
After coming back to my question SO associated a new question with an answer I was able to make work, although it feels extra hacky and wasn't what I had working before.
I found this answer which suggests using ⌃controlL to clear the screen. That does exactly what I want it to do (leaves the top prompt visible and doesn't flash) but with the wrong keybinding. Fortunately I was able to use an app I already have installed (BTT) to make ⌘commandK map to ⌃controlL only in iTerm2.

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.

How to map CTRL+Tab in vim Mac OSX 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.

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