I'm switching from vim and so far everything is going smoothly. One thing I'm sorely missing is ctrlp's functionality for opening the selected file in a horizontal split with C-x or vertical split with C-v. What's more, I was able to select multiple files with C-z and then use one of the aforementioned bindings to open them all in horizontal or vertical splits. It really defined my flow.

So to make it clearer, I would trigger ctrlp with ,f, type a short pattern, highlight the appropriate file, then press C-x to open it in a new horizontal split window.

I've scoured helm's documentation for something relevant to this but the only thing I found was some hint that it may be possible to select multiple files and do something with them, but I'm not sure if one of those actions could be opening the file(s) in a split. I imagine it would be something relevant to helm-find-files and the other similar commands, since those deal with files and not just general narrowing like helm-M-x.

Usually I just need to open a single file in a horizontal split, so if the "mark multiple for opening in their own splits" functionality is missing I won't mind too much.

However, it seems like I'm expected to first create the split, switch to the new window, then run helm so that the opened file populates that window. This is much slower for me in an environment that already feels slower to operate to me compared to vim, though I've been making progress on other fronts.

Is there any way at all that this may be possible? In the worst case, would it be possible to hack this on using the 'advice' functionality that I've heard about? I'd prefer not to hack on helm's source itself if possible, since I don't want to deal with the maintenance burden of doing that. If helm isn't capable of doing this, is there another package that offers similar narrowing functionality for finding files and buffers that does support this?

  • 5
    Have you checked out the menu opening when hitting TAB in helm-find-files? It offers a few actions including C-c o for opening the file in a new window and C-c C-o for finding it in another frame. – wasamasa Jul 18 '15 at 21:11
  • @wasamasa: Wow I looked at that that many times and I never tried it because I thought it simply opened it in another existing window -_- This is exactly what I wanted. I'll just rebind that because it's a pretty weird bind. The thing I'm missing now is to open multiple files that way. I saw that I can mark multiple candidates with C-SPC but doing C-c o still only works on the currently selected candidate. – Jorge Israel Peña Jul 18 '15 at 21:16
  • @JorgeIsraelPeña I have filled an github issue according to your request, if you like, you can describe what you want exactly there. – xuchunyang Oct 11 '15 at 15:22
  • Thanks @xuchunyang! As I mentioned in the issue, you had already helped me with this. If you would like, you can provide the solution here and I will accept it as the answer. Otherwise I can do that too, so that I can close this question :) – Jorge Israel Peña Oct 11 '15 at 20:01

@xuchunyang helped me out on the github issue I filed. Here is the solution for posterity:

(defun helm-buffer-switch-to-new-window (_candidate)
  "Display buffers in new windows."
  ;; Select the bottom right window
  (require 'winner)
  (select-window (car (last (winner-sorted-window-list))))
  ;; Display buffers in new windows
  (dolist (buf (helm-marked-candidates))
    (select-window (split-window-right))
    (switch-to-buffer buf))
  ;; Adjust size of windows

(add-to-list 'helm-type-buffer-actions
             '("Display buffer(s) in new window(s) `M-o'" .
               helm-buffer-switch-new-window) 'append)

(defun helm-buffer-switch-new-window ()
    (helm-quit-and-execute-action 'helm-buffer-switch-to-new-window)))

(define-key helm-buffer-map (kbd "M-o") #'helm-buffer-switch-new-window)

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.