Can tmux save commands to a file, like .bash_history? - linux

Does tmux support saving to a file the commands typed in "C-b :" mode ? I'd rather look through the ones I already typed than have to look each command up in the man page.

There is history-file option which does what you are looking for.
history-file path
If not empty, a file to which tmux will write command prompt history on exit and load it from on start.
Add this to your .tmux.conf
set -g history-file ~/.tmux_history
Note it was added in 2.1 version. if you have older version of tmux read
https://unix.stackexchange.com/questions/26548/write-all-tmux-scrollback-to-a-file

Related

How to issue Vim commands in command mode (`Enter` not working)

I installed neovim with pkg install neovim. I then downloaded the latest version of Nvim-R with curl -L "https://www.vim.org/scripts/download_script.php?src_id=26482" > NvimR.vmb. Finally, I opened the file with nvim NvimR.vmb.
Now I'm in the editor and I launch the command mode by pressing the : key on my keyboard. I then proceed to type packadd vimball into the command console. Finally I try to issue the packadd vimball command by hitting Enter on my keyboard and nothing happens. I look up in the editor panel and notice each time I hit Enter the cursor is just being moved around in the editor.
I don't want the cursor to move around in the editor. I want to issue my :packadd vimball command. How do I do this?
Everything I see in that gif is precisely what I would expect to see given what you typed.
You run :packadd vimballEnter—this does vim’s native packadd command (assuming nvim has that), and then returns you to the editing portion of the screen.
Subsequent Enter presses are equivalent to j—move down a line.
All of that said, I dont know of any packages named vimball, but I don’t really work with that format. Perhaps you’ve misunderstood a plugin’s usage or vimball usage? Ask about that stuff on vi.stackexchange.com: we probably have better vi/m experts there.

p4 change not working with gvim

I use perforce as source code repository. p4 change command is used to create a changelist of opened files. If I set setenv EDITOR gvim and then run this command then gvim opens and I add some description and then save and quit. I get below error. Same error does not come if EDITOR is not set, I mean in that case vim opens. Any idea to fix this issue?
sachina#inn-sachina-vm[285] p4 change
Error in change specification.
Error detected at line 29.
Change description missing. You must enter one.
Hit return to continue...
Applications that invoke EDITOR assume that the command blocks until editing is done and the editor was closed. While true for vim, the GUI version gvim launches in the background; i.e. the command returns immediately.
You can avoid this via the :help -f command-line option:
setenv EDITOR 'gvim -f'

Stuck in overwrite mode in tmux

Scenario: I open a new tmux session, and run emacs .tmux.conf.
The second line of .tmux.conf reads: set-option -g prefix C-a. I type 'asd', and the second line now reads: asdset-option -g prefix C-a. All good.
I ssh to another server, do some stuff, and then close the connection. I now re-run emacs .tmux.conf, and type 'asd'. The second line now reads asd-option -g prefix C-a, but if I save and run emacs .tmux.conf again, I'll see asdset-option -g prefix C-a.
This issue affects all lines except the first, even when I'm typing commands in the prompt.
Sourcing .bashrc, resetting the pane with respawn-pane, does not fix this. If I create a new pane or window, the issue is fixed in the new pane or window until I run ssh again.
What's happening? It's clearly a display issue, since inspection of the actual file reveals that i'm not actually overwriting.
To fix the problems of this kind, type in your shell:
$ stty sane
This is generally an universal one-time fix for terminal left off in a weird state.
To get rid of the problem completely, check your $TERM environment variable.
Inside tmux it should be TERM=screen (some suffix may present).
tmux does this automatically but your TERM environment variable can be altered by shell startup/login scripts.
So, in your tmux window type:
$ export TERM=screen
$ emacs <...>
If it helps, revise your shell rc files.

Vim Ex mode loads when opening terminal

I know little about Vim in terminal(Mac) and the other day I was working copy and pasting text and i think I accidently did it when in terminal. Now whenever I open terminal it instantly loads on Vim Ex mode. I know how to quit Ex mode once in terminal but is there any way i can get rid of Vim loading when I open Terminal?
Thanks
Edit: To explain further to what i mean when I open terminal.app from Utilities I get the following
and the only way I get back to the command prompt is by typing quit every time I open terminal and i cant understand why the Vim process is running in the first place.
I was just outside the terminal in a document copy and pasting text then accidentally did a command v to paste within terminal which resulted in this happening.
It appears that you've accidentally updated one of your shell startup scripts so it launches vim.
If your default shell is csh or tcsh, take a look at .cshrc, .tcshrc, and .login in your home directory, and look for a command like vi -e or vim -e.
If your default shell is bash, check .bashrc and .bash_profile.
It may be easier to figure out which file you messed up by checking which file in your home directory was modified most recently:
% ls -altr $HOME | tail
-a lists all files, including files whose names start with ..
-l gives you a long listing, showing timestamps.
-t sorts by modification time.
-r reverses the order, so newer files are shown last

adding a shell script to a configuration file

I'm pretty new to shell scripting and linux in general. Basically, I need to change the configuration file for logging out so that when a user logs out, a certain shell script is run.
Now, I've located the logout configuration file and opened it with vi using this command
$ vi ~/.bash_logout
At this point, I'm experiencing some very weird behavior. When I try to type a character, the cursor jumps around seemingly erratically. What could this be due to? I'm running the latest version of ubuntu.
And once I get that figured out, what's the command to run a .sh file from within this configuration file?
If you're having trouble with vi, try using nano instead. nano .bash_logout
If you do need to use vi for some reason, "i" will put the editor into insert mode, and ESC will take it out of insert mode when you're done. ":wq" will write and quit the editor.
To run a command, just put it in the .bash_logout file as you would type it on the commandline.
Some other useful commands:
a insert after selected character
o insert at next line
O insert at previous line
r replace a single character
R replace mode
:q! quit without saving
:w save
:wq save and quit
To get familiar with Vi and its brother Vim ("VI improved") I recommend the book "A Byte of Vim", you can read it online or download for free at http://www.swaroopch.com/notes/Vim
You can permanently change your editor option. To find out what your current one is, type this:
export | grep -i edit
To change it on Ubuntu:
sudo update-alternatives –config editor
On any other BASH prompt, just do this:
export EDITOR="nano"
Replace 'nano' with 'vi', 'emacs', or any other preferred editor. You can also add this to your .bashrc by typing the following:
echo 'EDITOR="nano"' >> ~/.bashrc

Resources