Vim stops scrolling randomly in terminal? - macos

Usually I can scroll in vim when I open a file in the mac terminal.
However, recently, all of a sudden sometimes I am not able to.
When I go to scroll, instead the entire terminal scrolls so I see what I had previously typed in the shell.
How can I fix this?
This is new, I've been using vim for months and it has only started to happen now.

You probably messed with the mouse setting.
:help mouse-using

Related

How to stop opening VSCode every time I open a new iTerm or Terminal window/tab

For some reason today whenever I open a new window in iTerm or Terminal it opens VSCode for a sec before closing it. Whenever this happens the terminal disappears from my screen and it's really annoying. It is running commands as soon as it opens the new window. The top of iTerm2 displays
login
then
bash
then finally
Electron before it kicks me out and opens VSCode. I installed luaenv and rbenv today and I tried to comment out the paths in /.zshrc. but it didn't help at all. Do you know what is causing this issue? Any help would be much appreciated!
I just figured it out. In my ~/.p10k.zsh literally the first line was 'code', which of course is the command to open VSCode. I just commented it out and now it's totally fine. It still displays login and then bash but it doesn't display Electron anymore and doesn't open VSCode every single time anymore.

Strange tmux status-bar rendering issues iterm2

I'm running into this strange issue with my tmux in iterm where it appears to be rendering on the wrong line, but this causes strange rendering issues to happen
Here is the basic behavior:
You'll notice the menubar is offset by one line. This is fine, for the most part, except when I start entering tmux commands I get behavior like this:
I've also noticed that sometimes the menu bar will entirely disappear and I won't be able to show which sessions i have open. I've also noticed that sometimes if I select the text in my terminal with my mouse, it will select text one-line up from what I expected to select.
I've tried a bunch of things to debug this, including:
re-install tmux
clear tmux-resurrect history
restart my computer
reinstall iterm
resizing the iterm window (both manually, and using cmd+ and cmd, which I have a theory was what triggered this behavior)
I've also noticed that if I run tmux in the default terminal macOS application it behaves normally with no issues.
Does anyone have any ideas of things I could try?
I have unchecked all of these options, and the strange behavior disappears.

mouse capturing differences between Terminal.app with MouseTerm SIMBL plugin and iTerm2

iTerm2:
Mouse reporting works out of the box, works in Vim, works fully in Tmux, mouse wheel reporting works in Vim and for navigating Tmux history, but mouse wheel reporting does not work in manpages, does not work in git log, does not work in less
Terminal.app:
Mouse reporting does not work out of the box, but once installed mouse wheel reporting works everywhere including less and manpages and git log, etc. However mouse click+drag fails in Tmux, but still works in Vim.
So I'd rather use just one of these terminal apps, and I am particularly digging the immense feature set of iTerm2 (e.g. mouse-over to select which term to input to beats the hell out of anything Tmux can offer since it is zero keys to switch contexts) so I'd prefer if I can get mouse wheel reporting working fully in those programs.
I am having a hard time trying to debug the terminal codes being sent because the only way I can intercept them is through Vim, (as ctrl+V followed by scroll in my terminal will just have it scroll the terminal buffer) but Vim seems to be doing everything correctly.
Update: According to mouseterm project, it seems to be using a feature called "Simulated mouse wheel scrolling" to scroll programs like less... maybe I can configure iTerm to do the same. Somehow. I do believe PuTTY also accomplishes this, and I'd like to have at least the functionality I can get on Windows on the Mac... Nope, I'm just spoiled by the neatness of MouseTerm.
Although less (which is also used in git log) does not use mouse reporting itself,
iTerm2 can be configured to send up/down-arrow escape codes for scrolling
(from mouse wheel or trackpad two-finger swipe)
and less understands those.
See my answer
to a related question about how to set this up for iTerm2.
less does not actually recognize any terminal mouse events. (As such, tools that use it, like man and git log will not recognize mouse events either.) Something else you've done must be making it appear to support mouse events.
If you want the mouse wheel to work in your pager, you'll need to find a pager other than less which supports it. You might be able to put something together using view (vim in read-only mode), but applications like man which output content with control codes will be an issue there.

How to mouse-wheel scroll downwards with tmux

I've got tmux to scroll up, with the mouse wheel, using mouse-mode on in tmux.conf (here's my entire conf).
But I've always had a problem scrolling back down again. Once the cursor hits the bottom of the screen, it immediately scrolls back to the bottom of the whole buffer, where the prompt is. It's not possible to scroll down a few lines in the same way I can scroll up a few lines. In other words, the whole middle section is only visible on the way up.
I just upgraded from tmux 1.6 to the new tmux 1.8 (compiled from source rather than Homebrew, in case that matters), and it's working again now.
What would happen if you turned mousemode off and used the keyboard? Try that.
Have you used burningTyger's settings for your conf?
Try deleting the buffer command, maybe then it won't autoscroll to the prompt line. If you can disable any automatic behavior you might be able to do what you need.
I don't know the OSX terms, but hopefully these concepts might be helpful.

Scrolling inside Vim in Mac's Terminal

I've been googling around trying to figure out if it's possible to use my mouse wheel to scroll while inside Vim in Mac's Terminal, with no luck. It seems as if only X11 or iTerm support this.
Before I give up, I thought I'd try the geniuses here to see if anyone knows a way to do this. So, does anyone know if I can set that up?
Or should I seriously consider using a different terminal application?
And if you're using iTerm, add this to your vimrc
:set mouse=a
http://bitheap.org/mouseterm/
Use MouseTerm (and do make sure to install SIMBL first!) and scrolling will work like a charm, even remote, using Mac Terminal.
You need to fully quit the Terminal application (Command+Q) and then launch it again after installing MouseTerm.
This is an old question, but a top hit on google, so I feel compelled to provide an updated answer.
Running OSX El Capitan 10.11, vim mouse and trackpad scrolling just worked(TM) for me in Terminal.app by default. However occasionally the mouse/trackpad input stopped manipulating the vim buffer, and started scrolling the terminal buffer. The answer was Command+R or Menu View --> Allow Mouse Reporting. Turning that on allowed the mouse/trackpad scroll operations to move the cursor in vim.
Termanal Menu > View > Allow Mouse Reporting
Terminal Menu > Preferences >
Keyboard > Scroll alternate screen
If the mouse functionalities still do not work properly take a look at my answer in this post How to let vim behave on Mac OS X as on Ubuntu?, just add to your .vimrc
set ttymouse=xterm2
You can read this article, but I'm pretty sure since the default terminal in Mac OS X has a built-in scrollbar, the mousewheel commands automatically go to it. You could definitely use gVim as suggested in the previous answer. I find that I don't generally want to use the mouse in Vim though as it takes my hands off the keyboard.
I just use 50j to go down and 50k to go up. Not exactly scrolling, but it works pretty well.
Make sure the terminal is xterm & not ansi in Terminal Menu > Preferences > Profiles > Advanced. I accidentally broke scrolling by changing the term type in a naive effort to get coloring to work over ssh.
Use gVim, which gives you a text editing environment in a window you can scroll. Terminal is not involved when using gVim.
I'm using xterm in X11 (XQuartz 2.3.4) and vim works very fine with mouse and also suport 256 colors.
Here is the ~/.Xresources I use to make my xterm nicer in X11:
XTerm*faceName: Lucida Sans Typewriter Regular
XTerm*faceSize: 9
XTerm*utf8: 1
xterm*saveLines: 1000
xterm*jumpScroll: true
!xterm*awaitInput: true
!xterm*multiScroll: true
XTerm*scrollBar: false
xterm*scrollbar*thickness: 16
xterm*rightScrollBar: true
XTerm*foreground: white
XTerm*background: grey10
!XTerm*background: black
XTerm*cursorColor: yellow
xterm*visualBell: false
xterm*loginShell: true
Little tips, to remove the bell sound in X11's xterm type this command:
xset b 0
I would recommend using iTerm - it has so many advantages over Terminal eg Mouse support, 256 colors, sensible copy and paste (auto-copy, word/url selection with double click, middle click paste)...
When using iTerm create a .vimrc file (if not already there) in your home folder and add the line:
:set mouse=a
Scrolling down in vim to view a file works after this.

Resources