2

Sometimes when I use paste in emacs the indentation gets messed up.

In vim I would use :set paste before pasting. I'm in evil mode but it says: State paste cannot be set as initial Evil state.

Is there something else I can do?

Example pasting this:

events { worker_connections 4096; ## Default: 1024 }

http {
  include    conf/mime.types;
  include    /etc/nginx/proxy.conf;
  include    /etc/nginx/fastcgi.conf;
  index    index.html index.htm index.php;

  default_type application/octet-stream;
  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '

Ends up like this:

http {                                                                          
  include    conf/mime.types;                                                   
    include    /etc/nginx/proxy.conf;                                           
      include    /etc/nginx/fastcgi.conf;                                       
        index    index.html index.htm index.php;                                

  default_type application/octet-stream;                                        
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '     
    '"$request" $body_bytes_sent "$http_referer" ' 
7
  • You'll have a better chance of an answer if you could explain what the vim command does.
    – Dan
    Aug 23 '17 at 21:38
  • It sets a Vim option that ensures no auto-indenting happens for pasted code.
    – wasamasa
    Aug 23 '17 at 22:26
  • What mode are you using? I have evil, and I've tried pasting C (with c-basic-offset set to something different), javascript, and the stuff you have above in conf-mode and it's pasting exactly what I copy with no reindentation. Aug 24 '17 at 1:49
  • @JeffSpaulding Is there a way to check the mode with a command? I'm using evil but I'm not sure what mode the file automatically opens up in. Aug 24 '17 at 1:53
  • 1
    M-: major-mode
    – wasamasa
    Aug 24 '17 at 5:11
1

First of all, even with Evil Emacs ain't Vim. Things like :set option won't work, simply because Evil concentrates on implementing text editing capabilities, not complete Vim emulation including Vim's options. I strongly recommend to learn about Emacs settings, minor modes and whatever else you encounter on your way. This includes habits like switching from using Vim in the terminal to using Emacs in graphical mode or keeping an Emacs instance open as opposed to keep opening and closing Vim instances.

The closest thing to :set paste would be M-x electric-indent-mode (and ensuring it has been disabled by checking the echo area) except it doesn't change anything about paste behavior in graphical or textual mode for me. Please provide a minimal reproduction example starting from make emacs as described in Evil's CONTRIBUTING.md (unless it's not Evil-specific, then emacs -Q is sufficient as starting point).

3
  • I have an emacs daemon running that I can open and close in terminal but it always actually open. And yes learning emacs is what I'm doing, if it wasn't I wouldn't be here I'd be back on vim. Aug 24 '17 at 0:05
  • 2
    I'm trying M-x electric-indent-mode but it is the same. I feel like this would be a common question for anyone using terminal. I'll update my answer with the info later if no one replies. Aug 24 '17 at 0:10
  • Does it work as expected in the GUI? If yes, you've found a compelling reason to switch.
    – wasamasa
    Aug 24 '17 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.