I am trying to implement a feature from the following article:
How to boost your vim productivity
in the fish shell. The Author in the Article uses the following code to map Ctrl+Z in zsh to the "fg" command.
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
The intention is to quickly switch between a vim instance in the foreground and the shell.
So Ctrl+Z backgrounds vim, and switches to the shell, then Ctrl+Z again should foreground vim again, so switching quickly is possible.
How would I replicate that in fish?
fish currently doesn't let you catch SIGTSTP, which is what Ctrl+Z sends. You can however bind another key. For example, you could write:
bind \ck 'fg %'
This makes control-K switch back to the last backgrounded process.
It looks like the zsh fancy-ctrl-z function has a separate mode where it clears the screen if there's input on the command line. I'm not sure what that's about, but that can be replicated in fish if you want, something like:
bind \ck 'if test -z (commandline) ; fg %; else ; clear; commandline ""; end'
Related
I'm creating a vim game where the purpose is to use vim motions to alter a buffer. It's a web game so I would have to emulate the inputs being sent from the client to the server, one challenge is going from insert mode to normal mode somehow. I'm running neovim behind an API, and this is how I'm able to run things from the app/frontend:
$ echo "foo" | nvim --headless --clean +"norm l" +"%print" +"echo getpos('.')" +q! -
I'm echoing "foo" into vim and using the norm command to alter it.
Inside the +"norm l" command I'm able to input vim motions, in this case moving the cursor right one character.
It works well, however, it can only handle things through normal mode. If I were to input ifoo<Esc>, which for me would translate to i, foo and then hitting the escape key, <Esc> is treated as an literal. Same thing with <C-c> and jj.
$ echo "foo" | nvim --headless --clean +"norm ifoo<Esc>" +"%print" +"echo getpos('.')" +q! -
foo<Esc>foo
[0, 1, 8, 0]
Is there a way to do this that I'm not seeing?
No matter I use term or ansi-term to start zsh in Emacs, I encounter this problem, whenever I input commands, the output will have some junk characters like:
[ruby-1.9.2] ~ pwd
2;pwd1;pwd/Users/tyraeltong
the 2;pwd1;pwd is screwing the output, don't know whether others are experiencing same problem? I found a similar thread here Getting Emacs ansi-term and Zsh to play nicely but by [[ $TERM == eterm-color ]] && export TERM=xterm I still see the junk characters.
Emacs doesn't play nice with ZLE, so I have this in my ~/.zshrc:
if [[ -n ${INSIDE_EMACS} ]]; then
# This shell runs inside an Emacs *shell*/*term* buffer.
prompt walters
unsetopt zle
fi
Found the solution in the related post mentioned earlier
In a nutshell, in emacs M-x package-install and install multi-term. M-x multi-term kicks off a shell, with all the bells & whistles oh-my-zsh has to offer
It could be an erronious PROMPT_COMMAND that has bash syntax. Try:
export PROMPT_COMMAND=""
and see if that helps.
When I use emacs from a terminal (xterm-color; a putty ssh session in this case) the font color used by emacs is different from the one I use in the shell. Which is fine. BUT, after I quit emacs (or suspend it for that matter) the colors are not restored.
Is there anything I can do to restore my term colors when returning to the shell after my emacs session?
I have aliased my ls command to add --color option, which if I run it restores my colors if the listing shows any files with "non-default" color, but that is a rather ugly way to get my colors back.
Use a wrapper script for emacs that runs "tput reset" after emacs exits:
#!/bin/sh
emacs &
pid=$!
wait $pid
trap "kill $pid 2>/dev/null; tput reset" TERM INT EXIT
How do I consistently control window focus after running emacsclient?
Currently, focus depends on if I already have an emacs server running. When emacsclient invokes an alternative editor, focus is shifted to the new emacs window. When emacsclient connects to an existing emacs server, focus is not shifted (ie. it stays on my putty client).
I would like to consistently focus on the emacs window, since I usually go to emacs after opening a file.
Any help would be greatly appreciated!
Notes
Version Info
emacs: 21.4.1
emacsclient: 21.4
client os: Windows XP Service Pack 3
x server: Exceed 11.0.0.0
Relevant section of my .bash_profile
# a wrapper is needed to sandwich multiple command line arguments in bash
# 2>/dev/null hides
# "emacsclient: can't find socket; have you started the server?"
emacs_wrapper () {
if [ 0 -eq $# ]
then
emacsclient -n -a emacs ~/notes.txt 2>/dev/null &
else
emacsclient -n -a emacs $* &
fi
}
alias x="emacs_wrapper"
Also, at the end of my .emacs I have
(server-start)
My current workaround is a simple autohotkey script, which focuses on my first Exceed window
^+x::
If WinExist("ahk_class EXCEEDW:MWCLIENT0")
WinActivate
return
As a side note, it seems my redirection to /dev/null confused the syntax-highlighter :(
How about:
emacsclient -e "(select-frame-set-input-focus (selected-frame))"
works for me on emacs 23.1
To unfocus (lower-frame) might be useful.
Would the "--create-frame" option to emacsclient work for you? You'd get a new frame for each file you opened this way, but at least it would be focused (I think).
For some unknown reason, the issue fixed itself. Opening files now consistently changes focus to the emacs frame with the corresponding file. I'm honestly unsure what changed the behavior, but I'm happy.
Thanks to everyone for their comments and suggestions!
Today's Daily Vim says this:
Assuming you're using the bash shell, the following can be helpful when composing long command lines.
Start typing on the command line and then type Ctrl-x Ctrl-e, it should drop you into your system's default editor (hopefully Vim) and allow you to edit the command line from there. Once finished, save the command line, and bash will run the command.
Is there any way to do this in tcsh?
A little explanation for the uninitiated.
bindkey -v
puts you in vi-mode (oh yeah!)
and hitting v from there would take you to $EDITOR -- and all is good with the world from there on.
Hmmm... IIRC, tcsh uses a command called bindkey. Try bindkey -v at the command line. Then hit escape followed by v. It's been a while since I used tcsh so the details are a bit fuzzy. When in doubt, Google it.