Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot edit shell commands in normal mode. Prompt not read-only (Evil) #8642

Closed
cweill opened this issue Apr 5, 2017 · 25 comments
Closed

Cannot edit shell commands in normal mode. Prompt not read-only (Evil) #8642

cweill opened this issue Apr 5, 2017 · 25 comments
Labels
- Bug tracker - Evil stale marked as a stale issue/pr (usually by a bot) Terminals

Comments

@cweill
Copy link
Contributor

cweill commented Apr 5, 2017

Description :octocat:

Shell prompt in term, ansi-term, multi-tem not protected from normal/command mode in Evil. Cannot edit shell commands in normal mode. This is not an issue when the shell is eshell, where the expected behavior works.

Reproduction guide 🪲

  • Set shell to one of multi-term, term, ansi-term
  • Start Emacs
  • SPC ' to open shell
  • ESC to enter command mode

Observed behaviour: 👀 💔

  • Type cc will delete prompt
  • Cannot edit inserted test in prompt. Hitting enter will run the uneditted text

Expected behaviour: ❤️ 😄

  • Prompt should not be deleted. Behavior should be the same as in eshell.
  • Editing test in command/normal mode should edit underlying command.

System Info 💻

  • OS: darwin
  • Emacs: 25.1.1
  • Spacemacs: 0.200.8
  • Spacemacs branch: develop (rev. f79a169)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(helm auto-completion better-defaults emacs-lisp git markdown org osx evil-commentary
      (shell :variables shell-default-shell 'term shell-default-height 30 shell-default-position 'bottom)
      spell-checking syntax-checking version-control)
  • System configuration features: JPEG RSVG IMAGEMAGICK NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
@gtmshrm
Copy link

gtmshrm commented Aug 20, 2017

@cweill did you find any solution this problem? this is the only problems that's keeping me away from using ansi-term as my full time terminal

@mpereira
Copy link

@gtmshrm I tried too and couldn't get it working. If anyone else did please let us know!

@gtmshrm
Copy link

gtmshrm commented Sep 13, 2017

@mpereira You need to follow these 2 steps in order to make it work properly:

  1. (If not done already) Use vi-mode for editing inside terminal by changing inputrc (and zshrc if you use zsh). This is necessary to make vim bindings work even when the evil-mode is disabled inside ansi-term.

  2. Disable evil-mode inside ansi-term. For this, Add:
    (evil-set-initial-state 'term-mode 'emacs) in user-config (this will always open ansi-term with evil-mode disabled)

Note: If you need evil-mode to do some complex stuff inside ansi-term, you can enable evil-mode inside ansi-term by pressing C-z. Press the same key to disable evil-mode.

Let me know if this works.

@mpereira
Copy link

@gtmshrm that was one of the things I tried but with the fish shell. I don't remember exactly the specific issues but it didn't work very well. Ideally we could have the full evil functionality available when editing commands, since these shell vi-modes are very limited. Maybe I'll try getting it working again this weekend.

Thanks for your reply!

@gtmshrm
Copy link

gtmshrm commented Sep 15, 2017

@mpereira Please let me know if you fix this issue without disabling evil mode. Sometimes, I hate switching back and forth between evil mode and holy mode.

@daviddaiweizhang
Copy link

daviddaiweizhang commented Jan 19, 2018

I am encountering the same problem and would greatly appreciate it if this bug can be fixed. Being able to use terminal inside spacemacs will be a big boost to my workflow. I have tried using eshell instead, but it's not working as smoothly as bash inside ansi-term.

@gtmshrm
Copy link

gtmshrm commented Jan 19, 2018

@zhangdaiwei Enable vi-mode in your regular shell and in emacs, open ansi-term and then disable evil mode by pressing C-z and the bindings should work fine. I have mentioned about a permanent solution above.

@daviddaiweizhang
Copy link

@gtmshrm I tried your solution and terminal worked fine. However, the space bar no longer works for sending key combinations as commands. I could use M-m but that's less convenient. The space bar is what I like the most about spacemacs.

@gtmshrm
Copy link

gtmshrm commented Jan 20, 2018

@zhangdaiwei There is a simple solution of this situation which I use. First remove (evil-set-initial-state 'term-mode 'emacs) from your config just in case you added it to your config because adding this to your config (or pressing C-z) disables evil mode for ansi-term. If the evil mode is disabled, then the spacemacs bindings won't work. Whenever I work with terminals, I don't disable the evil mode for the reason you have mentioned. When I need to edit a command with vim bindings, I temporarily disable evil mode by pressing C-z, edit the command and then I enable it by pressing C-z again after the editing is done.

@daviddaiweizhang
Copy link

@gtmshrm Yes, I was aware of that solution. However, when I use shell I need to edit commands frequently, so typing C-z that much does slow me down. It would be great if I can make emacs detect when I need to turn off evil mode and does that automatically.

@mpereira
Copy link

mpereira commented Jan 20, 2018

FWIW my solution was to switch to eshell.

@daviddaiweizhang
Copy link

@mpereira I tried that, too. However, most of my work need to be done on remote servers, and eshell is not as convenient as ansi-term for this task. When I cd to the remote server, eshell is confused about $PATH, even if I specify $PATH in eshell's init files. It is not sure whether I am referring something on local or remote. This is a problem when I need to execute a software installed on the remote server. If I use ssh, then eshell creates an ansi-term, and the original problem appears.

@kylegentle
Copy link

kylegentle commented Feb 7, 2019

Edit: This allows normal mode navigation in ansi-term with Evil-mode, but doesn't allow normal mode editing of text in the input line; the issue remains.

For anyone still coming across this issue, the fix from #10779 worked for me in ansi-term. Simply set term-char-mode-point-at-process-mark nil in dotspacemacs/user-config.

@mpereira
Copy link

mpereira commented Feb 8, 2019

@kylegentle are you able to edit text in the input line after moving in normal mode?

@kylegentle
Copy link

@mpereira, thanks for double checking--it looks like I was experiencing a separate issue. I'm not able to edit text in the input line while in normal mode. Sorry about the confusion!

@mpereira
Copy link

mpereira commented Feb 8, 2019

@kylegentle no worries! I was genuinely curious if you got that working. That issue was the main reason I found eshell to be more ergonomic.

@kylegentle
Copy link

@mpereira I did a little more investigating! Although it hasn't made it to master yet, #10844 is working with ansi-term in my setup and allows normal mode editing on the input line.

@mpereira
Copy link

mpereira commented Feb 8, 2019

@kylegentle interesting. I'll try that out later tonight, thanks for sharing!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 28, 2020
@fgionghi
Copy link

Someone solve this problem?

@duianto duianto removed the stale marked as a stale issue/pr (usually by a bot) label Mar 18, 2020
@duianto
Copy link
Collaborator

duianto commented Mar 18, 2020

It's still an issue on the latest develop branch.

This error message appears:

funcall-interactively: Buffer is read-only: #<buffer term-1>

Not only in evil normal state when one tries to change a word: cw
But also in evil insert state, when one tries to delete the next character: delete
or the standard key bindings for removing the previous or next word by holding down Ctrl while pressing: backspace or delete

delete works in evil emacs state (C-z)
(but C-backspace and C-delete shows the same read-only message, so they are not evil related)

PopOS 19.10
#### System Info :computer:
- OS: gnu/linux
- Emacs: 26.3.50
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. b7fd2fab6)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
((auto-completion :variables auto-completion-use-company-box t)
 command-log emacs-lisp git helm markdown multiple-cursors
 (org :variables org-agenda-files
      '("~/org/notes.org"))
 python
 (shell :variables shell-default-shell 'term shell-default-height 30 shell-default-position 'bottom)
 spell-checking syntax-checking treemacs version-control)
```
- System configuration features: XPM JPEG TIFF GIF PNG SOUND DBUS GSETTINGS GLIB NOTIFY LIBSELINUX GNUTLS FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS

@rubynho
Copy link

rubynho commented Apr 20, 2020

Do we have at least a work around to get editing commands working in evil mode? I'm trying using line mode when I need to edit a command but when I come back to char mode it's not actually edited.

@duianto
Copy link
Collaborator

duianto commented May 24, 2020

No one might have implemented evil support in term (yet).

The evil-collection lists it as a TODO item:
https://github.com/emacs-evil/evil-collection/blob/1fd291f082175a61e79b17c5ef2e2699d789a0ba/modes/term/evil-collection-term.el#L61

;; TODO: Add support for normal-state editing.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Oct 17, 2021
@Bost
Copy link
Contributor

Bost commented Aug 31, 2023

@mpereira You need to follow these 2 steps in order to make it work properly:

1. (If not done already) Use vi-mode for editing inside terminal by changing inputrc (and zshrc if you use zsh). This is necessary to make vim bindings work even when the evil-mode is disabled inside ansi-term.

2. Disable evil-mode inside ansi-term. For this, Add:
   `(evil-set-initial-state 'term-mode 'emacs)` in user-config (this will always open ansi-term with evil-mode disabled)

Note: If you need evil-mode to do some complex stuff inside ansi-term, you can enable evil-mode inside ansi-term by pressing C-z. Press the same key to disable evil-mode.

Let me know if this works.

As of now (August 2023) this works for me:

(with-eval-after-load 'multi-term
  (mapcar
   (lambda (map)
     (evil-collection-define-key 'insert map (kbd "S-<up>")   #'previous-line)
     (evil-collection-define-key 'insert map (kbd "S-<down>") #'next-line)
     (evil-collection-define-key 'insert map (kbd "C-<up>")   #'previous-line)
     (evil-collection-define-key 'insert map (kbd "C-<down>") #'next-line)
     (evil-collection-define-key 'insert map (kbd "<delete>") #'term-send-del)
     (evil-collection-define-key 'insert map (kbd "<prior>")  #'evil-scroll-page-up)
     (evil-collection-define-key 'insert map (kbd "<next>")   #'evil-scroll-page-down))
   '(term-raw-map))) ;; term-mode-map is apparently not needed

The (evil-set-initial-state 'term-mode 'emacs) is not need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - Evil stale marked as a stale issue/pr (usually by a bot) Terminals
Projects
None yet
Development

No branches or pull requests

10 participants