LoginSignup
59
54

More than 5 years have passed since last update.

Spacemacsに乗り換えてみた(1)導入編

Last updated at Posted at 2018-07-19

はじめに

  • Emacs Preludehttp://batsov.com/prelude/ )からSpacemacsに乗り換えてみた
  • なにか設定したら、メモを随時追記していく
  • 最初は、そこら中に書いてあるけど、インストールから

動機

  • Emacs : Vim= 95 : 5くらい、普段はEmacsを使ってるんだけれど、たまに vimも使うときがあるのでキーバインドを覚えたい
  • でもやっぱりEmacsから離れたくない・・・というより離れられない
  • evilというパッケージがあるのは知っているけど、自分で設定するのは面倒だ
  • Emacs + vim = Spacemacs !! (どんぴしゃ!)

Spacemacsのインストール

  • すでにemacsの設定(~/.emacs.d/)があったので、バックアップをとっておいた
  • Spacemacsの公式サイトにあるINSTALLボタンをクリックし、そこに書いてあるコマンドを入力した
$ mv ~/.emacs.d ~/.emacs.d.bk
$ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Spacemacsの初期設定ウィザード

  • Emacsを起動するとSpacemacsのロゴが表示され、ウィンドウ下部のミニバッファに初期設定ウィザードが表示された
  • 矢印キーとEnterキーで選択して進める
  • 下記の3つの内容を設定した

編集スタイルの選択

What is your preferred editing style ?
-> Among the stars aboard the Evil flagship (vim
   On the planet Emacs in the Holy control tower (emacs)
  • vimスタイルかemacsスタイルかを選択する
  • Spacemacsを使うなら、ここではvimスタイルを選択するのがよいと思う
  • と書いておきながら、あとでhybridに変更した

ディストリビューション(?)の選択

What distribution of spacemacs would you like to start with ?
-> The standard distribution, recommended (spacemacs)
   A minimalist distribution that you can build on (spacemacs-base)
  • フルパッケージ(spacemacs)か、ミニマムパッケージ(spacemacs-base)かを選択する
  • フルパッケージを選択した

補完ツールの選択

What type of completion framework do you want ?
-> A heavy one but full-featured (helm)
   A lighter on but still very powerful (ivy)
   None (not recommended)
  • helmivyかを選択する
  • ivyを選択した
  • どちらを選ぶかは好みの問題
    • 僕はhelmの使い方が結局よく分からずidoを使っていた、そっちに似ているivyにした

インストール完了

  • 必要なパッケージのインストールがすべて終って完了!
  • Quick Help画面が表示されるので、とりあえず書いてあるとおりにキーを押して遊んでみた

Screenshot 2018-07-19 15.15.33.png

Quick Helpに書いてあること

  • 英語が読めれば不毛な作業をここに記しておく
  • SPC h SPCの動作は説明を読んでもよく分からず、実際に押してみてもよく分からず、なので、動作が理解できたときに修正する
キー 動作
TAB or J 次のボタンに移動
Shift + TAB or K 前のボタンに移動
w warning一覧にジャンプ
r recent file一覧にジャンプ
p project一覧にジャンプ
b bookmark一覧にジャンプ
c org-agenda一覧にジャンプ
d org-todo一覧にジャンプ
o リンクやボタンにジャンプ
m トップのメニューにジャンプ
SPC Spacemacsコマンドを起動
SPC f e d ~/.spacemacsを開く
SPC h SPC (よく分からない)
SPC s j ドキュメントを読んでいるときに、見出しを移動

キーバインド

終了・再起動(SPC q

キー コマンド 動作
SPC q r restart-emacs-resume-layouts 再起動
SPC q q prompt-kill-emacs 終了
SPC q d restart-emacs-debug-init デバッグモードで再起動

Spacemacsに関するドキュメント

キー コマンド 動作
SPC h r ivy-spacemacs-help-docs Spacemacs Documentation
SPC h l ivy-spacemacs-help-layers Spacemacs Layer Lists
SPC h f ivy-spacemacs-help-faq Spacemacs FAQ

ヘルプ操作(SPC h

キー コマンド 動作
SPC ? counsel-descbinds キーバインドを調べる
SPC h d +help-describe 調べる系
SPC h d b describe-bindings キーバインドを調べる(SPC ?と一緒)
SPC h d f describe-function 関数を調べる
SPC h d m describe-mode 現在のバッファで有効になっているモードと使えるキーバインドを調べる
SPC h d p describe-package パッケージを調べる
SPC h d s describe-system-info システム情報をクリップボードにコピー(*Messageバッファで内容を確認できる)
SPC h d v describe-variable 変数を調べる

ウィンドウ操作(SPC w

キー コマンド 動作
SPC w TAB alternate-window 別のウィンドウを移動
SPC w 2,3 layout-double-columns 縦に{2,3}分割
SPC w f follow-mode follow-modeの切り替え
SPC w b switch-to-minibuffer-window ミニバッファに移動
SPC w d delete-window ウィンドウを消去
SPC w h,j,k,l evil-window-{left,down,up,right} 上下左右に移動
SPC w W ace-window 移動するウィンドウを選択
SPC w D ace-delete-window 消去するウィンドウを選択
SPC w M ace-swap-window スワップするウィンドウを選択

バッファ操作(SPC b

キー コマンド 動作
SPC b . buffer-transient-state バッファ移動ステート
SPC b b ivy-switch-buffer バッファを選択
SPC b s switch-to-scratch-buffer *scratch*バッファ
SPC b d kill-this-buffer バッファを削除
SPC b h home Spacemacsのホーム画面

ファイル操作(SPC f

キー コマンド 動作
SPC f f counsel-find-file ファイルを開く
SPC f r counsel-recentf 最近使ったファイルを開く
SPC f j dired-jump ディレクトリを開く
SPC f J open-junk-file 仮ファイルを開く
  • デフォルトのjunkファイルの保存先は~/.emacs.d/.cache/junk/
  • Google Driveで同期できるように、シンボリックリンクにして使うことにした
junkへのシンボリックリンクを作成
$ cd .emacs.d/.cache/
$ rm -r junk
$ ln -s ~/Google\ Drive/junk/ .

Spacemacsの設定(SPC f e

キー コマンド 動作
SPC f e +emacs(spacemacs) Spacemacsレイヤーの操作
SPC f e d find-dotfile ~/.spacemacsを開く
SPC f e i find-user-init-file ~/.emacs.d/init.elを開く
SPC f e R dotspacemacs/sync-configuration-layers 設定ファイルを再読込み

Git操作(SPC g

キー コマンド 動作
SPC g s magit-status Magitを起動

設定ファイルdotspacemacsの編集

  • インストールが完了すると~/.spacemacsという設定ファイルができていた
  • Spacemacsの設定は、このファイルに記述する
  • Spacemacs内からはSPC f e dで開くことができる

編集スタイルの変更

;; One of `vim', `emacs' or `hybrid'.
;; `hybrid' is like `vim' except that `insert state' is replaced by the
;; `hybrid state' with `emacs' key bindings. The value can also be a list
;; with `:variables' keyword (similar to layers). Check the editing styles
;; section of the documentation for details on available variables.
;; (default 'vim)
dotspacemacs-editing-style '(hybrid :variables
                                    hybrid-mode-default-state 'hybrid)
  • さっそく編集スタイルをvimhybridに変更した
    • 105行目のdotspacemacs-editing-stylevimhybrid に修正
    • hybrid-mode-default-state'normalから'hybridに変更
    • 詳しくはドキュメント参照 → 8.1 Editing Styles
  • hybridに設定すると、バッファが編集モードのときにEmacsのキーバインドでカーソル移動ができるようになるので、Emacs出身の人はやっておくとよいと思う
  • Emacsな人はhybrid-mode-default-stateemacsにするとよい」と、ドキュメントに書いてあるが、そうするとESCを押してもnormalモードに移行できなかったので、ここもhybridにしたほうが、Spacemacsを使う恩恵が受けられるのでよいと思う

フォントの変更

dotspacemacs-default-fontを変更
(defun dotspacemacs/init ()
  (setq-default
   ...
   ;; dotspacemacs-default-font '("Source Code Pro"
   ;;                             :size 13
   ;;                             :weight normal
   ;;                             :width normal
   ;;                             :powerline-scale 1.1)
   dotspacemacs-default-font '("Source Han Code JP"
                               :size 13
                               :weight light
                               :width normal
                               :powerline-scale 1.1)
  ))

Batteries Included

  • EmacsBatteries Includedである
  • (ちゃんとした)パッケージの場合、Emacs内蔵のマニュアルから参照することができる
  • ウェブ記事でいろいろ探すのもよいが、マニュアルをちゃんと読めば分かることも多い

全体の操作

コマンド 内容
M-x info マニュアル起動
q 終了
H コマンド一覧
mノード ノード(目次)に移動
T 現在のパッケージの目次一覧を表示する
M-n 現在のノードを別バッファにクローンする
  • ドキュメントを読んでいると、あっちみてこっちみてすることが多いので、そんなときにM-nは便利

ノード間の移動

コマンド 内容
d ルート・ノードに移動
g 指定したノードに移動
], n 次のノードに移動
[, p 前のノードに移動
^ 上のノードに移動
< 最初のノードに移動
> 最後のノードに移動
f 参考文献のノードに移動
  • p(前のノードに移動)は、Spacemacsだと使えないみたい

ノード内の移動

コマンド 内容
C-n, j 次の行
C-p, k 前の行
TAB 次のリンクに移動
C-M-i 前のリンクに移動;Shift + TABと同じ
b ノードの先頭に移動
RET リンク先に移動
SPC 1ページ進む(Spacemacsだと使えない)
DEL 1ページ戻る
L 履歴一覧を表示する
l 履歴を戻る(Spacemacsだと使えない)
r 履歴を進む
  • SPCはプリフィックスに取られているので使えない。不便。Shift + DELに割り当てようかな
  • lvimlに取られているので使えない。代わりにLから探せばよいので問題はない
  • C-M-iShift + TABのほうが簡単

目次

  1. Spacemacsに乗り換えてみた(1)導入編
  2. Spacemacsに乗り換えてみた(2)キーバインド編
  3. Spacemacsに乗り換えてみた(3)レイヤー編
  4. Spacemacsに乗り換えてみた(4)ウェブ制作編
  5. Spacemacsに乗り換えてみた(5)メーラ編
  6. Spacemacsに乗り換えてみた(6)LaTeX編(予定)
59
54
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
59
54