How do I properly set the title in Terminal using zsh? - macos

I have been trying to set the title of my Terminal appropriately, but I haven't had any success. Currently, it looks like this, and if I were to change directory, to say the desktop, it would become this.
I would prefer if the title only had the current folder and process. I've tried various methods, such as here, but to no success.
I'm using the default Terminal app in Yosemite, and am running zsh.

If you don't want anything in the window title other than the current directory and process (which is there by default in Terminal.app), you can do the following at the end of your ~/.zshrc:
precmd () {print -Pn "\e]0;\a"}
Example:
I'm afraid you can't get rid of that terminal size though since it appears to be hard-coded into Terminal.app (maybe I'm wrong).
For more information, see How to change the title of an xterm: Examples for different shells.
By the way, I recommend iTerm2 instead of Terminal.app. The Swiss army knife of terminal emulators, infinitely better then Terminal.app, highly customizable.

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.

iTerm2 tab names change; what is this bash command?

I use iTerm2 as my terminal on OS X. When I SSH into a machine, I like to name my tabs by going into the session preferences (cmd + i). Whenever I run another bash command after setting this preference, the tab title goes back to the default that it was when I first SSHd in.
Browsing around for an answer, I found this answer by Chad that is working for me:
export PROMPT_COMMAND=''
echo -e "\033];MY_NEW_TITLE\007"
I don't really understand the PROMPT_COMMAND line, though I tried looking it up.
Can someone explain this in simple terms?
Same question for the 2nd line, as I don't even know how to begin researching that.
To keep the original tab:
Go to Iterm's Preferences > Profiles > Terminal
Uncheck "Terminal may set tab/window title"
Now you can name your tab, ssh into a server, exit and still keep the original tab name.
Credit to: https://groups.google.com/forum/#!topic/iterm2-discuss/czV-sv4ykzI
You can read iTerm2 escape code .
I didn't read the related iTerm2 code thoroughly, but it seems like an interface to manipulate iTerm2.
I guess iTerm2 does this magic by parse the output of screen if the contents fit special format(start by "\033]" and so on), iTerm2 will consider that's the information mean to sent to itself.
I used tabset node plugin. It works like a charm, and also color codes each tab, and has multiple options to color code, add a badge and even bring up a color picker to choose.

End of lines are grey with vim and zsh

I use vim and ZSH. When I open a document, the background seems to not be correct at the end of each lines as you can see here :
I tried with different colorscheme and it do the same thing. It works with bash.
What is the solution?
These visual problems usually occur when Vim cannot fully control the terminal: Basic stuff like screen updates work, but things that are handled differently in different terminals (like setting the background color) do not.
Check and compare the values for $TERM in bash and zsh; it's likely the latter one is wrong. You shouldn't hard-code them in a startup file like ~/.bashrc; instead, this variable should be set by your terminal emulator(s). This way, you can also work when you connect remotely via a different terminal emulator (e.g. PuTTY on Windows).

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.

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.

Resources