1

I'm using spacemacs and while when I create a new buffer with a given name and try to save it into a real file I find that :w won't work but :sav will. What is the difference between those two commands ?

1
  • Just an additional comment that I like the provided spacemacs bindings "space f s" and "space f c" for saving the file and copying to a file, respectively.
    – SpaceNuB1
    Nov 1, 2016 at 15:54

2 Answers 2

3

:w and :sav are Evil ex-commands, provided by Evil. The "bindings" of ex-commands are stored in the variable evil-ex-commands, which is an alist. To examine the variable, run the command C-h v evil-ex-commands (in Spacemacs you can use SPC h d v evil-ex-commands instead). The output would be something like this:

evil-ex-commands is a variable defined in ‘evil-vars.el’.
Its value is shown below.

This variable may be risky if used as a file-local variable.

Documentation:
Association list of command bindings and functions.

Value: (("edit" . evil-edit)
        ("e" . "edit")
        ("write" . evil-write)
        ("w" . "write")
        ("wall" . evil-write-all)
        ("wa" . "wall")
        ("saveas" . evil-save)
        ("sav" . "saveas")
        ("read" . evil-read)
        ("r" . "read")
--- I trimmed the rest (the list continues) ---

When invoking :<key>, Evil looks for <key> in evil-ex-commands and invokes the corresponding command. As you can see, ":w" is a shortcut for ":write", and ":write" invokes the function evil-write. Similarly, ":sav" is a shortcut for ":saveas", which invokes evil-save.

To find the differences between evil-write and evil-save, you can read their documentation by calling C-h f or SPC h d f (as db48x wrote). It seems that ":w" saves to current file, while ":sav" lets you save to a new file.

2

I don't use spacemacs, but emacs in general is self-documenting; you can always query the help system for information about keybindings, functions, variables, etc. The normal emacs keyboard shortcut for getting help with a key binding is C-h k. From a quick glance at the spacemacs manual (http://spacemacs.org/doc/DOCUMENTATION.html#orgheadline91), it looks like you should use SPC h d k, or possibly SPC h d f (I'm not sure if the ex-commands like :w are classified as keyboard shortcuts or functions; probably the former but it might be the latter.)

You should be able to figure out the differnce by comparing the documentation for the two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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