iTerm2 – scroll less output with mouse - macos

I just switched from OSX Terminal to iTerm2, and I seem to have lost one piece of functionality.
In Terminal, I could scroll through output of the less command with my mouse, because I had installed MouseTerm.
However, when I try scrolling less output in iTerm2, the window's scrollbar moves instead.
Strangely, scrolling works as expected with vim.
How can I scroll less output with my mouse in iTerm2?

Now it is implemented in iTerm2 and can be activated by
Settings -> Advanced -> Scroll wheel sends arrow keys when in alternate screen mode and change it to Yes
(defaults write com.googlecode.iterm2 AlternateMouseScroll -bool true still works but it just changes the same setting)

The iTerm2 issue is now marked as "fixed" -
but the fix is to add a hidden option, so it is not immediately obvious
how to enable the new AlternateMouseScroll option.
As Filippo Valsorda (author of the patch) writes,
once you install a nightly build (still not present in 1.0.0.20140629) of iTerm2,
just run this command:
$ defaults write com.googlecode.iterm2 AlternateMouseScroll -bool true
restart iTerm2, and all your windows will report scroll events as up/down arrow-key escapes
when the terminal is in the "alternate screen" (direct addressing) mode
used by programs like less, vim, emacs, etcetera.
For applications like vim and emacs that provide additional mouse support,
you will still want to enable mouse reporting mode,
as this automatic mode switch only enables scrolling.

Finally did it, I've been spending a lot of time on this looking here and there with no luck, the simplest steps are:
Install the 2.9 beta version
Done

Not the OP's question, but for anyone here trying to get this to work in tmux, with credit to choco via this github comment here's a snippet to add to your tmux.conf to get it to handle alternate screens (e.g. less, vim) correctly:
# Check if copy-mode or any mouse flags, then send mouse events
# or check if we're in alternate screen end send navigation keys (up, down)
bind -n WheelUpPane if-shell -Ft='#{?pane_in_mode,1,#{mouse_any_flag}}' \
'send -Mt=' 'if-shell -Ft= "#{alternate_on}" \
"send -t= Up" "copy-mode -et= ; send -Mt="'
bind -n WheelDownPane if-shell -Ft= '#{?pane_in_mode,1,#{mouse_any_flag}}' \
'send -Mt=' 'if-shell -Ft= "#{alternate_on}" \
"send -t= Down" "send -Mt="'
Note, this doesn't require the Iterm preference change mentioned in other answers, but it also isn't hurt by it.

This isn't implemented as of now.
There is an open issue in the iTerm 2 issue tracker about implementing it.

The latest version of less supports the --mouse and related flags so there's no need send arrow keys to alternate screens.

Related

Enable vi mouse wheel scrolling using bash on ubuntu on windows 10

I'm using bash on ubuntu on windows 10 and would like to enable scrolling using the mouse wheel in vi or vim. I've tried entering the following command in vim and added it to the .vimrc file and /usr/share/vim/vim74/debian.vim
set mouse=a
However I still can't scroll with the mouse.
I added this to my /etc/vim/vimrc.local, and it worked:
set mouse=a
map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>
Quick and simple answer:
If you use mintty/wsltty it works just fine!
You have done, properly, all you can in vim and the problem is with your terminal emulator.
Mouse wheel scrolling through the scrollback buffer of a terminal emulator is a function of the terminal emulator which is consuming the mouse events. You are wanting to send these events to the application (vim) hooked to the terminal.
Most terminal emulators have a way to enable the passthrough of mouse events when in "Application Key Mode" or "Alternate Screen". Most also support using a modifier key (like holding ALT) that will passthrough the mouse events as you wish.
Your version of Vim may not have been compiled with mouse support. See if you can get gvim. It contains a graphical version of Vim. Depending on your distribution it may also contain the terminal vim with almost all features enabled, including mouse support.
To check for mouse support in Vim, enter :version and check whether +mouse is in the list of features.

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.

Enabling mouse and paste support in command line vim

I've found these two articles
http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl
(see 31.13)
and
http://www.tummy.com/journals/entries/jafo_20060727_145450
But am unfamiliar with basic vim setup. Can anyone help me with a step by step instructions to making mouse usuage in command line mode automatically enabled? (and you will have good luck for a week if you can shed some light on enabling paste from OS to terminal window in VIM)
Note: Using latest mac os
To enable mouse support in all modes put this in ~/.vimrc:
set mouse=a
Note that Terminal.app has no mouse support, you'll need to use xterm in X11 to get mouse working.
I did find a 'plugin' for Terminal that claims to add mouse support, however it is in alpha and has no mention of 10.6. If it does work at all you'd probably need to run Terminal.app in 32 bit mode.
http://mac.softpedia.com/get/Utilities/MouseTerm.shtml
Try starting vim like this:
screen vim
That should enable copy/paste with the mouse.
You might also want to set-up an alias in ~/.bashrc for this.
Just use iTerm2 instead of the default Terminal.app. It has lots of other features, but mouse support alone makes it worth the switch.

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.

Unable to use Screen efficiently in Mac's Terminal

The post summarizes problems in using Screen in Mac's terminal when you have the following in your .zshrc
if [[ $STY = '' ]] then screen -xR; fi
Solution #1 is not working but Solution #2 works: Clipboard programs: pbcopy, pbpaste and xsel do not work at all
Bug in Vim when used in Mac: Unable to have no scattered windows in Screen by .Xresources.
Solved: Ctrl A stops working in terminal. This suggests me that Screen's keyboard bindings need to be changed slightly.
Solved: The scrolling with touchpad does not work. By editing your .screenrc the scrollback works normally (including touchpad)
Solved: Unable to have Dvorak keybindings for Screen for moving in Scrollback mod.
How can you use pbcopy/pbpaste/xsel inside Screen?
In screenrc:
# Make xterm scrolling work properly with screen.
termcapinfo xterm-256color|xterm-color|xterm|xterms|xs|rxvt ti#:te#
Works for Terminal.app too.
I usually solve the ctrl-a problem by setting my escape character to ctrl-z (which you generally don't need to use as often when you're running screen, since instead of backgrounding a process, you can just start up a new screen). In my .screenrc:
escape ^Zz
Scrolling using the touchpad just isn't going to work; screen is acting as a terminal emulator inside a terminal emulator, and it's just not possible for screen to switch the scrollback buffer in Terminal.app whenever you switch between screens. You're going to have to use screen's scrollback features. See this article for some tips on using screen's scrollback features.
The default OS X Terminal app is weak. Get iTerm instead:
iTerm
If I'm not mistaken, iTerm solves all of these out of the box (my install is a couple years old, so I can't test that theory now).
Problem #3 might be solvable if you enable the alternate screen buffer. Use altscreen on in .screenrc
Solution #1 which does not work
To be able to copy/paste in OSX put the following to your .screenrc
bind b eval "writebuf" "exec sh -c 'pbcopy < /tmp/screen-exchange'"
> Th[e] line - - sends that file to pbcopy - -.
The command is bound to C-a b (in my case, C-z b).
Solution #2 which works but is rather slow to type
Use Scrollback mode i.e. copy mode by
Coping
C-A [
Pasting
C-A ]
The solution is great, since it is the same in all terminal apps. It is similar to the clipboard as you use with your mouse.
Q5: Impossible: The scrolling with
touchpad does not work.
You can use ^A Esc to scroll up the screen. You cannot use Touchpad in Screen.
This solves the scrollback issue, although it is somewhat broken in that it isn't aware of screen's buffers.
env TERM=vt100 screen

Resources