How to scroll up terminal till your previous command? - macos

Is there a way to scroll up the terminal right till your previous command, no more no less?
Ubuntu or mac.
The goal is to quickly find the beginning of the previous command output without spending time on scrolling and searching for it.

If you are running a gnome-terminal (default GUI terminal on ubuntu) you can hit shift+ctrl+f, type your search terms, and hit enter. Still graphical, but no mouse required.
Or
Finding text in scrollback is a weakness of most terminal emulators; the only ones I know of that provide it are OS X Terminal and Terminator. That said, you could run GNU screen in any terminal and search its scrollback buffer in copy mode.

Related

I noticed that my terminals get a bit kooky after they forcibly disconnect from SSH

The terminal begins to behave a little bit strangely after an SSH session inside has been terminated (due to sleeping the computer or killing it via <Enter>+~+.).
It causes a beep to be emitted whenever focus enters and leaves the particular terminal. Also when in my zsh shell, a blank new line appears to be fed into the terminal.
I've tested this in:
tmux in alacritty
raw alacritty
iTerm2
This is not a hugely annoying behavior, although the bell is definitely annoying for sure.
Today I was able to finally find a way to reproduce the behavior. Clearly this is somehow related to a terminal mode that SSH puts the terminal into and which it fails to clean up when it dies. But it is also related to the focus reporting.
I have tried stty sane but it does not work. Not even starting and quitting vim works. That usually is able to reset various other terminal state weirdnesses, such as being stuck in mouse mode where clicking the mouse on the terminal (and especially scrolling your mouse) produces lots of bells.
Inspired by the answer https://superuser.com/a/1017817/98199, I found that issuing the command echo '\x1b[?1004l' does effectively turn off the focus reporting, and restores normal behavior.
Since vim definitely is capable of recognizing focus events I do not know why starting and stopping vim does not do the trick for this. I suppose I will make this command into an alias and just run it when I need to.

why command is canceled when I move terminal window on ubuntu?

everyone!
I installed ubuntu on vmware for working laravel framework.
I have problem with terminal.
when I move terminal window using mouse, running command is canceled.
Please see this...
hkg328#hkg328-virtual-machine:~$ ^C
hkg328#hkg328-virtual-machine:~$ ^C
hkg328#hkg328-virtual-machine:~$ ^C
hkg328#hkg328-virtual-machine:~$ ^C
whenever I move terminal window using mouse, following line appears in terminal.
hkg328#hkg328-virtual-machine:~$ ^C
What is the reason?
What should I do for solving this problem?
(When I move terminal using shift key+mouse drag It is ok.
But I don't want to use shift key.)
Thank you.
The likely problem is that your terminal has the xterm mouse-protocol enabled (usually from running some text-editor). Occasionally that does not clean up after itself (a problem with vim's plugins), and you'll even see this enabled on the shell command-line.
When you click in the text-area without shifting, that sends escape characters (and control characters) when xterm mouse-protocol is enabled. For xterm, at least, clicking/dragging the window border (including title area) shouldn't pass those escape/control characters to the application.
The use of the shift-key is built into the mouse protocol; if it's enabled you'll get that behavior -- always.

Vim stops scrolling randomly in terminal?

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

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