Open sessions, restore graphical tabs (gvim, windows) - session

I use gvim and work in tabs. For example, I have 3 tabs open when I :mksession. When I later source it, the files will "open" in buffers, as they are visible in the buffers menu, but it doesn't recreate the tabs.
Looking at the example session.vim, it runs badd for every file, but I can't see anything that creates new tabs. I tried putting au BufAdd * tabnew in my vimrc, but it didn't work as expected.
My .vimrc
Example session.vim
sessionoptions="blank,buffers,curdir,folds,help,resize,tabpages,winsize"

Sometimes the exact right combination of Google search terms will get it for you...
:au BufAdd,BufNewFile * nested tab sball
http://vim.wikia.com/wiki/Open_every_buffer_in_its_own_tabpage
edit: This au command causes Netrw to open a new tab for each directory you browse. A workaround is to run :tab sball after opening a session.

[ When you open session ]
And make your session save command that :mks! next time when You can open session with following.
save session:
1) :mks!
Next open session:
2) vim -S Session.vim
It's so uesful. Enjoy your code in vim.
Thanks.

Related

iterm2 issue : create new tab with same path of previous current tab BUT 2 tabs are clones and not indepedent

I have switched from default terminal on MacOS Mojave to iterm2. I have an issue about the opening of a new tab from the current tab.
Indeed, I would like to be in the same path than the previous current tab.
For this, I did the classical procedure, i.e to go to iterm2 preferences and Profile and choose Reuse previous session's directory for new tab :
Then, the issue is that once tab opened, all the other tabs are affected and change from their old path to the path of the new tab: I don't understand what happens and which option to use to prevent this behavior.
Every tab is the same than the others: if I do a cd ~/foo/, then the other tabs will go into foodirectory.
Result worse: if I edit with vim a file in one tab, if I do a cd ~/foo/ in another tab, then the tab associated to the edited file disappears is clearing this edition and shows the same windows than the tab where I did cd ~/foo/: very strange.
I want to keep all the current path for all others tabs except for the new one which must be the same than the previous one from which I do a CMD+T.
I saw on different forums this issue sometimes occurs.
Update 1
From what I have seen, it seems that I have to find a way to create a new session when I do the shortcut CMD+T to get another tab independent from the current one (from which I do CMD+T).
But unfortunately, I didn't find how to create a new session in iTerm2 (inside the iTerm2 - Preferences - profile, I could execute a script that creates this new session). From the moment, you can see the command (/bin/bash that I launch when I open a new tab:
I tried also to build the binary iTerm2 from the sources but issue remains.
Update 2
I tried to use a little apple script to force a new session to be created from current window:
tell application "iTerm2"
tell current window
create tab with profile "Terminology2"
end tell
end tell
(where Terminology2 is a duplicate of profile Terminology (default profile).
But always the same issue, the 2 tabs are not independent: each command in one of 2 is executed on the another one.
Update 3
I keep on trying a solution: for this I removed the macport package and hidden files and directory ~/.iTerm2/.
So I downloaded the iTerm2 zip archive from iTerm2 official website.
Here's a screen capture of my profile :
Is shortcut key necessary in this profile to open new tabs : the issue seems to come from this option since it may not concern the shortcut for a new tab ? CMD+T is already a shortcut for opening an independent tab, isn't it ?
Update 4
Solution finally found. Coming from classic MacOS terminal, I was used to do a shortcut CMD+Shift+-> or CMD+Shift+<- to change of tab.
But by chance, I tried simply the shortcut CMD+-> or CMD+<- and so was able to switch between 2 tabs independent.
So this was an error of beginner into iTerm2's world since I was used to apply old classical shortcut of default terminal.
If someone else makes the same mistake, they will know that it is just a configuration issue of shortcut.
The OP already answered the question in Update 4, but in case anyone jumps right to the answers, the solution was to update the Key Mappings and create two new entries - CMD+SHIFT+LEFT & CMD+SHIFT+RIGHT - with assigned actions of Previous Tab and Next Tab, respectively.
These entries can be created in Preferences -> ${Your Profile} -> Keys, and then clicking on the + icon near the Presets... button.
Do you see the all-pane input icon in the upper right?
Command-Shift-I to toggle it. (that is a capital i)
Sounds like you have Broadcasting enabled. To check:
Toolbar > Shell > Broadcast Input > Send input to current Session Only

Reuse window / tab when file is already open

I want to set a global shortcut that will open a certain file. When there already is a gvim window that has that file open, I want it to focus on that window, and select the tab with that file. If there isn't, I want it to be opened in a new gvim window, regardless of whether there already are other gvim windows.
I can do part of this with --remote and --servername, but I can't find a way to detect whether there already is a remote server running with the name I use, so I can't quite get everything to work together to come to what I described above.
OK, turns out most can be done using the default behavior of --remote-silent. The whole setup is a matter of making an AutoHotkey script like this:
#!^+1::
Run "c:\Program Files (x86)\vim\vim74\gvim.exe" --servername org --remote-silent %DROPBOX%\org\TODO.org
WinActivate, TODO.org
Return
AHK is needed for the global hotkey as well as activating the window; vim (using --servername and --remote-silent) will start a new session called 'org' if there isn't one yet, and start it otherwise. It even gets the tab activation right when there already is a server called 'org' but if that server has another tab active.

How to load bashrc in all open tabs

Sometimes I change my prompt on .bashrc and I want to source the file so I can get the new version. But usually I've many open tabs simultaneously. Is there any way/command to source the .bashrc file in all open tabs?
I saw that Terminator allows to send the command to multiple tabs, but I do not use it...
Answer available at Super User
thanks to Anthony Geoghegan

Rename tab in MobaXterm for session duration

How can we rename tabs in MobaXTerm for the entire session duration? At the moment, I can right-click and rename the tabs, but as soon as I press enter to get command prompt, MobaXTerm resets tab name to its original default. I have tried changing PS1 env variable with no effect. Please help.
I haven't tried this myself but when you create a profile for a new ssh session, there is a tab "Bookmark settings" and within this tab there is a check box named "Lock terminal title." According to the manual:
Lock terminal title
Terminal title will be set to the session name
If you check this option, any attempt by the shell to set tab title will fail.
Uncheck this option if you want to allow the shell to change tab title.
Looks like you need to open every new tab as a New Session (Click on the "Session" button) and then follow what ks2000 suggested (It works for me).
There is limitation in number of sessions created for non-purchased mobaxterm. When you go for edit the session, red coloured message this message will be displayed. Delete unwanted sessions, unlock terminal title, then it will work. Otherwise purchase mobaxterm.
A bit late, but I came across this and wanted to update it.
I found the answer here:
https://stackoverflow.com/questions/29963545/rename-tab-in-mobaxterm-for-session-duration
I wrote a bash function to quickly handle this for me.
set_title() {
PROMPT_COMMAND="echo -ne \"\033]0;$1\a\""
}
set_title "webserver"
If none of the above works, just go to the sessions tab and click on the session you want to rename (just like when you want to rename a file). You should see the following:
After that, enter the preferred name and hit enter. The following window will occur:
Click yes and voilĂ !
THIS IS NOT FOR THE SESSION DURATION BUT PERMANENT

GVim: Open in a new tab

I am using gVim on Windows and facing the annoying thing of having a new gVim window opened whenever I open a new file. Is it possible to make it open a new tab in the same window?
Thanks,
Rafid
Also (more tedious but generally useful for other things) you can drag&drop files from Windows Explorer into gVim when the command line is active. If you type :e and then drop a file, the command line will be filled out with the full path to the file. You can do the same with :sp and :tabe; just remember to put the space after the command!

Resources