Spacemacs 安装和简要配置

Spacemacs 安装和简要配置

SPACEMACS 和 EMACS

SPACEMACS 只是 EMACS 的配置。好处在于安装之后,几乎不需要另外设置配置。SPACEMACS 配置了很多快捷键,用leader键(空格键)触发。由于 EVIL 插件,EMACS 可以使用很多 VIM 的快捷键。VIM 的基本快捷键在网络上很多,用几次就差不多了。EMACS 不好的地方就是太多 C/ALT+key 的组合,手指很疼。用 VIM 快捷键会缓解很多,也很方便。e.g. 删除引号中的一段, di" or ci”。另外,对初学者(包括我),别折腾太多功能。譬如,用 EMACS 听歌,浏览网页,ORG 模式,等等,这些用手机挺好的。仅仅用 EMACS 编辑代码就可以了。

安装

在 mac 或 linux 系统中:

brew install emacs
// or 
sudo apt install emacs

rm -rf ~/.emacs.d .emacs
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
emacs

在启动 emacs 中会提示选择编辑模式,我选择了 emacs。但是我在配置文件中改成 hybrid 模式。这个模式要用 i, 进入编辑模式,可以利用 emacs 的组合键。可以用 ESC 退出编辑模式,用 VIM 的快捷键。

基本配置

打开~/.spacemacs。

nvim ~/.spacemacs

编辑模式

  dotspacemacs-editing-style 'hybrid
  不太喜欢这个 line-number 显示,由于我把有的字体加粗后,linenumber 有些变形
   ;; dotspacemacs-line-numbers '(:visual t
   ;;                             :relative t
   ;;                             :disabled-for-modes dired-mode pdf-view-mode
   ;;                                     )
  dotspacemacs-smartparens-strict-mode t

添加 需要安装的 layer

   dotspacemacs-configuration-layers
   '(
     javascript
     python
     (c-c++
      :variables
       c-c++-backend 'lsp-clangd
      c-c++-enable-clang-format-on-save t
      )
     shaders
     common-lisp
     osx
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
     ;; <M-m f e R> (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     helm
     (auto-completion :variables
                      spacemacs-default-company-backends '(company-files company-capf company-tabnine company-lsp)
                      auto-completion-tab-key-behavior 'cycle)
     better-defaults
     emacs-lisp
     git
     markdown
     ;; org
     (shell :variables
             shell-default-height 30
             shell-default-position 'bottom)
     ;;spell-checking
     syntax-checking
     version-control
	 (ranger :variables
             ranger-show-preview t
             ranger-show-hidden t
             ranger-cleanup-eagerly t
             ranger-cleanup-on-disable t
             ranger-ignored-extensions '("mkv" "flv" "iso" "mp4"))
     )

添加需要安装的 additional packages

   dotspacemacs-additional-packages '(
                                      highlight-indent-guides
                                      slime
                                      helm-slime
                                      helm-git
                                      company-tabnine
                                      lsp-mode
                                      lsp-ui
                                      ;;company-lsp
                                      python-mode
                                      comment-dwim-2
                                      electric-operator
                                      yasnippet-snippets
                                      cmake-mode
                                      ;;multiple-cursors
									  iedit ; C-; activate/cancel,  10C-; 10 matches
									  key-chord
									  all-the-icons
									  treemacs
									  treemacs-evil
									  treemacs-projectile
									  treemacs-icon-dired
									  treemacs-magit
									  try
                                      )

其它设置

(defun dotspacemacs/user-init ()
  "Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
 This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."
  (setq-default dotspacemacs-colorize-cursor-according-to-state nil)
  (setq configuration-layer--elpa-archives
        '(("melpa-cn" . "http://elpa.emacs-china.org/melpa/")
          ("org-cn"   . "http://elpa.emacs-china.org/org/")
          ("gnu-cn"   . "http://elpa.emacs-china.org/gnu/")))
  (setq-default display-line-numbers-width 2)
  )

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  (setq-default tab-width 4)
  (setq-default indent-tabs-mode nil)
  (setq c-default-style "bsd"
        c-basic-offset 4)
  (global-hl-line-mode t)
  ;;下划线,可以快速找到正在编辑的行
  (set-face-attribute hl-line-face nil :underline "magenta")
  (set-face-background 'highlight nil)
  (global-set-key (kbd "M-;") 'comment-dwim-2) ;;注释用的
  (setq spacemacs-show-trailing-whitespace nil)
  (setq inferior-lisp-program "/usr/local/bin/sbcl")
  ;; (use-package company
  ;;   :ensure t
  ;;   :config
  ;;   (setq company-idle-delay 0)
  ;;   (setq company-minimum-prefix-length 3)
  ;;   (global-company-mode t))
  ;; (use-package company-tabnine
  ;;   :ensure t
  ;;   :config
  ;;   (add-to-list 'company-backends #'company-tabnine))
  ;; (use-package company-lsp
  ;;   :ensure t
  ;;   :config
  ;;   (add-to-list 'company-backends #'company-lsp))
  (use-package electric-operator
    :ensure t
    :config
    (electric-operator-add-rules-for-mode 'c-mode
                                          (cons "*" nil))
    )


  ;; (add-hook 'python-mode-hook (lambda () (set (make-local-variable 'company-backends) '(#'company-tabnine))))
  (electric-indent-mode t)
  ;; (add-hook 'c++-mode-hook (lambda ()
  ;;                            (electric-indent-local-mode -1)))


  ;;(electric-pair-mode 1), because of smartparens
  ;;(global-set-key (kbd "RET") 'newline-and-indent)
  ;; add space around to opera
  (add-hook 'python-mode-hook #'electric-operator-mode)
  (setq company-show-numbers t)
  (add-hook 'after-init-hook 'global-company-mode)
  (blink-cursor-mode t)
  (set-cursor-color "yellow")
  (setq-default line-space 0.3)
   (add-hook 'prog-mode-hook 'which-function-mode)
   ;; display-line-numbers 并非必需的。我把配置文件中的 dosspace-line-numbers 注释掉了
   (use-package display-line-numbers
     :init
     (setq display-line-numbers-width 2)
     (setq display-line-numbers-grow-only t)
     (setq display-line-numbers-type 'relative)
     (set-face-background 'line-number "#313335")
     (set-face-foreground 'line-number-current-line "#FF0000")
     (add-hook 'prog-mode-hook #'display-line-numbers-mode)
     (add-hook 'text-mode-hook #'display-line-numbers-mode)
     (add-hook 'web-mode-hook #'display-line-numbers-mode))

  ;;(load-file "~/.emacs.d/keybinding.el")
  ;;(load-file "~/.emacs.d/pretty-symbols.el")
  ;;这个看个人喜好,可以注释掉
(custom-set-faces
  '(font-lock-function-name-face ((t (:height 1.2))) t)
  '(font-lock-constant-face ((t (:height 1.1 :Width 1.1))) t)
  '(font-lock-keyword-face ((t (:height 1.1))) t)
  '(font-lock-builtin-face ((t (:height 1.1))) t)
  '(font-lock-type-face ((t (:height 1.2))) t)
  '(font-lock-string-face ((t (:Width 1.1 :height 1.1))) t))
)

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值