Spacemacs 设置标签宽度
Spacemacs set tab width
我刚从 VIM 迁移到 Spacemacs,想将制表符宽度从默认值 (\t?) 更改为仅 2 个空格。我发现像
这样的命令
(setq-default indent-tabs-mode nil)
和
(setq tab-width 4) ; or any other preferred value
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
我的问题是我不知道它们是否正确,我应该将它们插入 .spacemacs 文件中的什么位置,以及它们的含义。
我找到这篇文章:
http://blog.binchen.org/posts/easy-indentation-setup-in-emacs-for-web-development.html
我将这部分代码添加到任何函数之外的 .spacemacs 文件中(但在 (defun dotspacemacs/user-init () ... )
之前):
(defun my-setup-indent (n)
;; java/c/c++
(setq c-basic-offset n)
;; web development
(setq coffee-tab-width n) ; coffeescript
(setq javascript-indent-level n) ; javascript-mode
(setq js-indent-level n) ; js-mode
(setq js2-basic-offset n) ; js2-mode, in latest js2-mode, it's alias of js-indent-level
(setq web-mode-markup-indent-offset n) ; web-mode, html tag in html file
(setq web-mode-css-indent-offset n) ; web-mode, css in html file
(setq web-mode-code-indent-offset n) ; web-mode, js code in html file
(setq css-indent-offset n) ; css-mode
)
并添加了行
(my-setup-indent 2) ; indent 2 spaces width
像这样进入(defun dotspacemacs/user-init () ... )
:
(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."
(my-setup-indent 2) ; indent 2 spaces width
)
您也可以通过在 spacemacs 中调用命令 customize-variable
来自定义 standard-indent
变量,将其设置为 2。这会将自定义保存到您的 .spacemacs
文件中。
编辑:
至运行 'customize-variable' 使用热键 M-x(在大多数系统上为 alt-x),然后在提示中键入 customize-variable。
您可以使用搜索来搜索'standard-indent'
我刚从 VIM 迁移到 Spacemacs,想将制表符宽度从默认值 (\t?) 更改为仅 2 个空格。我发现像
这样的命令(setq-default indent-tabs-mode nil)
和
(setq tab-width 4) ; or any other preferred value
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
我的问题是我不知道它们是否正确,我应该将它们插入 .spacemacs 文件中的什么位置,以及它们的含义。
我找到这篇文章: http://blog.binchen.org/posts/easy-indentation-setup-in-emacs-for-web-development.html
我将这部分代码添加到任何函数之外的 .spacemacs 文件中(但在 (defun dotspacemacs/user-init () ... )
之前):
(defun my-setup-indent (n)
;; java/c/c++
(setq c-basic-offset n)
;; web development
(setq coffee-tab-width n) ; coffeescript
(setq javascript-indent-level n) ; javascript-mode
(setq js-indent-level n) ; js-mode
(setq js2-basic-offset n) ; js2-mode, in latest js2-mode, it's alias of js-indent-level
(setq web-mode-markup-indent-offset n) ; web-mode, html tag in html file
(setq web-mode-css-indent-offset n) ; web-mode, css in html file
(setq web-mode-code-indent-offset n) ; web-mode, js code in html file
(setq css-indent-offset n) ; css-mode
)
并添加了行
(my-setup-indent 2) ; indent 2 spaces width
像这样进入(defun dotspacemacs/user-init () ... )
:
(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."
(my-setup-indent 2) ; indent 2 spaces width
)
您也可以通过在 spacemacs 中调用命令 customize-variable
来自定义 standard-indent
变量,将其设置为 2。这会将自定义保存到您的 .spacemacs
文件中。
编辑:
至运行 'customize-variable' 使用热键 M-x(在大多数系统上为 alt-x),然后在提示中键入 customize-variable。
您可以使用搜索来搜索'standard-indent'