I have mapped Ctrl-s key to save a file in .vimrc. This was working fine till I just installed tmux. (Note that it was working fine because I had "stty -ixon" set in my .bashrc file).
How can I get the mapping work again when opening vim from tmux window?
What I tried so far without success:
Added stty -ixon in .bashrc
Added stty stop undef in .bashrc
Added both 1 and 2 in .bashrc
Added unbind-key C-s in .tmux.conf
Thanks #jeremysprofile for the suggestion. Here is the solution that fixed my issue for future references:
tmux was working fine outside of vim for C-s. So, instead of opening vim straight by 'tmux new-window -n editor vim', I did 'tmux new-window -n editor bash' and then 'tmux send-keys -t my_sess:editor "vim" C-m'.
The reason above works is because now vim is opened under bash(which invokes the .bashrc prior to calling vim).
Related
If I highlighted a filename in the copy mode, how could I open that file with vim by a hotkey?
I'm imagining something like:
bind-key -T copy-mode-vi 'C-o' send-keys -X copy-pipe-and-cancel "vim $(tmux paste-buffer)"
but that doesn't work, plus piping is redundant in this case.
I know there is tmux-open which should do similar thing, but it doesn't work for me somehow.
Environment: OSX 10.13.5, iTerm2 3.1.7, Tmux stable 2.7 built by homebrew
I normally have these settings in my vimrc
set hidden
set path+=**
Then you can just press gf when you cursor is over a word. If you want to open it on a new window, press Ctrl-w gf. If you just use gf you can go back by pressing Ctrl-6.
Since backspace in vim was giving me ^? instead of working as a backspace, I put the following in .cshrc to make it work:
stty erase ^?
Now the problem is that when I open a gnome-terminal from my linux machine, the backspace still does not work in vim. However if I run tcsh on my shell, and reopen vim, backspace does work. If I open a gnome-terminal tab in the already open terminal, or open a new terminal window from the already open terminal on which tcsh was run, I don't see the issue. Could anyone tell me what might be going on?
A little bit of context: I'm using vimx (that is X display campatible version of terminal vim for RedHat which gives me the ability to work with + and * X clipboard registers in vim). I do ssh to my server (with X forwarding using -Y option) and run vim (ie. vimx) in tmux. If I detach tmux session and attach to it again in the same ssh session, every thing works fine. However, if I logout of ssh session and log in back and then attach to my tmux session (which is running vim), then vim key binding and key mappings (like ctrl+n for new tab) and vim commands (like ":buffers" for displaying vim buffers or ":reg" for displaying registers) won't work any more until I close vim and reopen it again. I suspect that is a X11 display problem in vim and tmux, however I am not able to find what's going wrong in vim or tmux.
The summary of the problem and how to reproduce it:
1) do ssh to the server: ssh -Y user#server
2) open a new tmux session: tmux -2
3) open vimx: vimx myfile.cc
4) detach from tmux: ctrl+b d
5) logout ssh session: type exit in terminal or press ctrl+d
6) reconnect to the server: ssh -Y user#server
7) reattach to the tmux session: tmux -2 attach
in step 7, I will get reattached to the vimx session however, none of my vim key mappings or commands for vim work now. (They do get fixed if I close and reopen vim but in that case what good tmux is for working with vim remotely?! :) )
Rather than restarting vim, just use the :source command to reload your vimrc.
:so ~/.vimrc
That's easier than a restart and will work even in the middle of editing a file.
In the tmux shell, after exiting vim, the vim screen is not cleared. I'm using zsh. It works fine without using tmux.
The same problem is also happen with screen.
I'm using vim 7.3.672, tmux 1.7, all with default configuration.
Put this line in your .screenrc:
altscreen on
Then screen will clear the VIM content when VIM exits.
With tmux, it should work out of the box.
PS. this is my .tmux.conf, in case you find anything interesting in it.
Put the following line in your .zshrc, and restart terminal.
export TERM=xterm
It works for me.
I am transitioning from using Gvim to console Vim.
I open a file in Vim, and then suspend Vim, run a few commands on the command-line and then want to return to Vim.
Ctrl+Z (in normal mode) suspends Vim and drops back to the console
fg can be used to return focus to Vim
jobs lists background jobs and can be used to get the job number to
bring a given job to the foreground (e.g., fg %2 to bring job 2 to the
foreground).
However, when Vim is in the background and I issue vim file, the file opens in a new instance of Vim.
I'm used to using the --remote option with Gvim to open a file in an existing Gvim instance.
Question:
How can I open another file in a background Vim from the command-line?
Is this a reasonable workflow for moving between console and Vim?
Update:
I just read this answer by #jamessan which provides a few ideas. He shows the following code snippet:
vim --servername foo somefile.txt
:shell
<do stuff in your shell>
vim --servername foo --remote otherfile.txt
fg
However, I'd have to think about how to make it easier to use perhaps with some aliases.
Would this be a good approach?
How could it be made efficient to use?
This is also what I need. I found this thread, though no satisfying approach, happy to see people having same requirement like me.
My approach is
add below to .bashrc
v() {
vim_id=`jobs|sed -n "/vim/s/\[\([0-9]\)\]+.*/\1/p"`
if [ -n "$vim_id" ]; then
echo "tabedit $#" > ~/.vim_swap/e.vim && fg $vim_id
else
vim $#
fi
}
add below to .vimrc
nnoremap <silent> <space>e :source $HOME/.vim_swap/e.vim<Bar>:call writefile([], $HOME."/.vim_swap/e.vim")<CR>
Then v foo.c to open first file, editing..., ctrl-z to suspend vim, do shell stuff, v bar.h to bring vim foreground.
And in VIM, press <Space>e to tabedit bar.h.
So the idea is to generate vim command from shell command, save them to a temp .vim file. In VIM, map key to source the .vim file and clear it.
Instead of running vim again, you need to bring your current vim process to the foreground (with fg) and open the file in vim.
I have not used it much, but you may find the "vim server" feature (see --remote*, --servername, etc. options) lets you open the file from your shell into an existing, backgrounded vim. However, ctrl-z suspends the process instead of allowing it to continue to run in the background, and you will need to put that vim into the background so it can respond as a "vim server". Use the shell's bg command to do that.
I would just call vim from fg and open new file inside vim since its just seems to be faster (although it may be just faster to me). To work with multiple files inside vim you need to use command edit (in vim): :e [filepath/]filename and you walk true buffers (all files will be as vim buffers) with ^I (ctrl+I) and ^O (ctrl+o)
It works on both GTK and shell versions. There is no such a huge difference on workflow. I prefer shell version since i do most of commands there (compiling launching etc.).
If you use tmux, and if you always have your vim instance running as the first job in background, you can setup alias like below in csh.
alias v 'tmux send-keys fg Space +1 Enter :e Space `realpath \!:1` Enter'
then you can call it like this
v myfile.txt
If your vim instance is not the first background job, enrich the alias with jobs output.
In Bash, this can be done with a function.
function v() {
local job=$(jobs | perl -ne 'print $1 if /\[(\d+)\].*vim/')
if [[ -n $job ]]; then
tmux send-keys fg Space $job Enter
for f in $*; do
tmux send-keys :e Space `realpath $f` Enter
done
else
vim $*
fi
}