How can I insert one or more pre made text strings, stored in one storage file, into any text file where I need these strings? The text strings are stored as one string per line in the storage file.

When in a file where I need to insert my strings, I would like to call a function that opens a Helm-list of all the strings available in the storage file. Further, I must be able to chose more than one string (by the space bar), and insert the chosen strings either vertically (one string per line), or horizontally, where the strings are separated with space.

Thanks in advance for all suggestions, either to available methods for doing this, or new code!


The following use helm to take strings from /etc/shells and insert into the current buffer. To pick multiple strings at a time, use C-SPC (helm-toggle-visible-mark). To insert marked strings vertically, just use RET. To insert horizontally, open the action menu with TAB (helm-select-action) and choose the second item.

(defun foo ()
  (helm :sources
        (helm-build-in-file-source "Strings"
          '(("Insert vertically" .
             (lambda (_candidate)
               (insert (mapconcat #'identity (helm-marked-candidates) "\n"))))
            ("Insert horizontally" .
             (lambda (_candidate)
               (insert (mapconcat #'identity (helm-marked-candidates) " "))))))))
  • Thanks, your code functions perfect, for inserting list of strings both vertically and horizontally. BTW, I am able to invoce the action meny when I have bound the function helm-select-action to the TAB key, but not when I try to invoke the same function by means of M-x helm-select-action`. What is the reason for this?
    – myotis
    Sep 11 '17 at 20:58
  • @myotis you can't use minibuffer while in minibuffer, e.g., in the middle of C-x C-f, you can't use M-x.
    – xuchunyang
    Sep 12 '17 at 8:51

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.