Run terminal inside vim on a macbook? - macos

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.

Related

Why does emacs intermittantly not use the alternate screen?

I use emacs with the -nw flag so that it runs in the terminal. I don't run it inside screen or tmux or anything like that, just a plain terminal. Often when I exit emacs I return to a view of my terminal that shows the emacs command I typed but no longer shows the file I was editing or the emacs menu bar or anything like that. From this question I take it that this behavior is because emacs uses a so called "alternate screen" in my terminal. This is the behavior I want.
Maybe 30% of the time when I exit emacs the file I was editing and the menu bar and such are still on the screen. Why does this happen and how can I prevent it?
Based on this answer I tried the hacky solution of aliasing emacs to "tput smcup; emacs -nw". That seemed to reduce the frequency of the problem down to maybe 5 or 10%, but it didn't fix it and I'm sure it's not the "right" thing to do anyway. Any help would be appreciated.
IIUC this has been resolved for Emacs 29. Refer to the NEWS.

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

Opening files into an existing vim session (Cygwin/mintty)

I am looking for ideas to open files into an existing vim session.
I am working on Windows + Cygwin + Mintty. I usually have 3 to 4 opened terminals (2-3 vim sessions + 1 shell, build environment). I don't use tmux/screen because it's easier to use the native Windows's window manager to switch in between my terminal windows. Because I have 2 wide-screen monitors I can use the 2 half of both screens for my terminals which gives me an awesome working environment. With the help of an AHK script, I can use shortcuts to switch/rotate or even to reposition my terminals in the desired position.
I rather prefer vim over gvim for many reasons. I can achieve almost all the gvim features (scroll, mouse selection, copy, paste, etc. I am one of those who think that using the respectable y/P commands is a bit crippling when you need to use plenty of other softwares that use /. I always get confused to use different shortcuts for each software I am using.
Now the core issue. I would like to open a file from the Windows explorer into an existing vim session. I found a horrible solution using a Perl script with the Win32::API in order to look for an existing mintty terminal with Vim in the title. Then I activate the window and send <esc>:e path/file<cr> to it.
It works pretty well but I am looking for a better solution like gvim --remote that works with my console vim. Unfortunately I don't have such options with my vim even though if I built it with the -with-x configure option.
So, I am looking for some suggestions to achieve a more honorable solution (socket/adding the feature directly to vim/using a smarter ahk script/etc.)
gvim --remote should work with console vim if you start vim with vim --servername GVIM. Alternatively, choose another servername and use vim --servername foo --remote.

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.

Configure gnome-terminal so that right click extends selection rather than displays menu

I've been using Linux for a long time, but have only recently 'upgraded' to a full GUI desktop since using it command-line-only for the last three or four years. I used to use 'aterm' before then (with fluxbox, and other old-school things) but I see now that gnome-terminal is pretty usable in Ubuntu's Gnome.
However, there's one thing that really gets me - when you select something and then right click, it doesn't extend the selection, instead it brings up a pop-up menu.
I've been using terminals and emacs for years and right-click has always extended a selection - so there must be some way to configure gnome-terminal to do this. This is a habit I'm not going to be able to grow out of because I use it all the time in emacs.
Does anyone have the magic recipe to restore the behaviour I'm after please?
Alternatively, what's a good and modern alternative to gnome-terminal?
I'm using Ubuntu 10.04.
Try program called terminator.
sudo apt-get install terminator
As #bruce-van-der-kooij rightly pointed out, the answer is to Shift+LeftMouseClick, which extends the selection.

Resources