21 天学会 Emacs 之第 14 天

优酷视频地址:

百度网盘地址:

http://pan.baidu.com/s/1slMRuot

视频 Show notes:

Spacemacs Rocks Season 2 (Day 14)

Topic: File and Buffer operations

Talk the difference between the configs of mine and spacemacs

File related operations

  1. SPC p f (find a file in current project, it looks like the Ctrl-p plugin in Vim)

I also do some hacks to enhance the SPC p f

(defun zilongshanren/open-file-with-projectile-or-counsel-git ()
  (interactive)
  (if (zilongshanren/vcs-project-root)
      (counsel-git)
    (if (projectile-project-p)
        (projectile-find-file)
      (ido-find-file))))

If it is in a Git repository, I use counsel-git to find file. Why not projectile? Becuase I think ivy-mode is much faster. If it is in a proctile project, say it has a .projectile file in your project’s root. Otherwise, you ido-find-file

  1. SPC f f to find a file start from the current directory

  2. SPC f L find the file across the whole Mac system

  3. SPC f l find file literally(I also enhance this func with ffap)

  4. SPC f h find file in hex mode(I also enhance this func with ffap)

  5. SPC f o open with external program

  6. SPC f E sudo edit

  7. SPC f D delete current file and buffer

  8. SPC f j open the current file’s dired mode

  9. SPC f r find the recent file with ivy

  10. SPC f R rename the current file

  11. SPC f v add local variables

  12. SPC f y yank current buffer’s full path

  13. SPC f a d find the current visited directory with fasd.

  14. SPC f C d/u convert file encoding between unix and dos

  15. SPC f e d find the .spacemacs/.spacemacs.d/init.el file

  16. SPC f e i find the .emacs/.emacs.d/init.el init file

  17. SPC f e l helm locate library file

  18. SPC f c copy file

  19. SPC f b show bookmarks

  20. SPC f s/S save buffers

buffer related operations

  1. SPC b . buffer micro state (hydra)
  2. SPC b b switch buffers, i rebind it to ivy-switch-buffer, because I could see recent use file in buffer
  3. SPC b d kill a buffer
  4. SPC b f find buffer file in finder
  5. SPC b B/i I bind it to ibuffer
  6. SPC b h go to home
  7. SPC b k kill matching buffers
  8. SPC b N new empty buffer
  9. SPC b m kill others
  10. SPC b R safe revert buffer
  11. SPC b s switch to scratch buffer
  12. SPC b w toggle buffer read-only
  13. SPC b Y copy the whole buffer to clipboard, the content could be used in other programs
  14. SPC b P paste to the whole buffer
  15. SPC <tab> switch between the current buffer and the last opened buffer

Sometimes I also use the Dired mode to do all the files operations

I think I have talked about it in the previous videos.

Happy hacking!

2 个赞

关于buffer操作有个问题就是,我想split/vsplit打开buffer的话怎么处理, b b 都是替换当前的。 这个算是vim遗留下来的一个习惯。

补充一下,就是类似Ctrlp,可以自由选择 当前buffer替换,vsplit,split,tab。其实我最需要的还是vsplit,因为有时候就想vsplit两个buffer做对比,或者其他用途。

有一个函数叫 view-buffer-other-window 应该可以,但貌似没法选择用什么方向分割窗口

这个是知道,但是spacemacs的所有buffer操作都没有提供选项使用split。目前是小白,还不是很清楚怎么去写代码去处理使他支持在buffer list时能用 <C-v>之类的快捷键来执行view-buffer-other-window

(defun liu233w/view-buffer-vsplit ()
  (interactive)
  (let ((window (split-window-right)))
    (select-window window))
  (ido-switch-buffer))

看看这个行吗。这个是纵向分割的,和view-buffer-other-window的横向分割正好一对


这个可以在helm切换buffer的界面按F3或者C-c o来在下方开新的window来打开buffer

另外,在helm里面可以用C-z来打开按键说明的,helm下的快捷键都在这里了

好的。 非常感谢!! :thumbsup:

@xuchunyang 给出的解答 https://github.com/emacs-helm/helm/issues/1100 更好用,简单的还有只添加(setq split-width-threshold 0)就能右边分屏,依这个链接 https://www.emacswiki.org/emacs/HorizontalSplitting 可以写个切换分屏方向的函数

1 个赞