「Spacemacs」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(翻訳)
(翻訳)
84行目: 84行目:
 
* グレーは'''ビジュアルステート'''です。テキストの選択と操作に使います。
 
* グレーは'''ビジュアルステート'''です。テキストの選択と操作に使います。
   
  +
カーソルの色でも現在のステートは判別できます。
You can also check the cursor color for the current state.
 
   
{{Note|In order to use Spacemacs you will need to know at least '''normal''' and '''insert''' state.}}
+
{{Note|Spacemacs を使い込むには最低でも'''ノーマル''''''挿入'''ステートを知る必要があります。}}
   
 
===== ノーマルステート =====
 
===== ノーマルステート =====
  +
ノーマルステートではテキストの移動とコマンドの実行ができます。ノーマルステートで直接テキストを打ち込むことはできません。代わりに、素早く移動したり様々な校正を行うことができます。ノーマルステートはデフォルトのステートであり、'''オレンジ'''色をしています。
Normal state is used for text navigation and running commands. You can't directly enter text in this mode. Instead, you able to quickly navigate and make any sort of corrections there. Normal state is default state, and it has '''orange''' color.
 
   
  +
{{ic|ESC}} キーを押すか {{ic|fd}} キーシーケンスでいつでもノーマルステートに戻ることが可能です。
You can always return to normal state by pressing {{ic|ESC}} key or {{ic|fd}} key sequence if you accidentally leave it.
 
   
 
{{Note|
 
{{Note|
105行目: 105行目:
 
* {{ic|l}} - 1文字分だけ右にカーソルを移動
 
* {{ic|l}} - 1文字分だけ右にカーソルを移動
   
  +
単語あるいは文章単位の移動もひとつのキーで行うことができます:
It's also possible to navigate between the words or even sentences with single key:
 
* {{ic|w}} - move to next word (beginning)
+
* {{ic|w}} - 次の単語 (の先頭) に移動
* {{ic|b}} - move to previous word (beginning)
+
* {{ic|b}} - 前の単語 (の先頭) に移動
* {{ic|(}} - move to the beginning of current sentence
+
* {{ic|(}} - 現在の文の先頭に移動
* {{ic|)}} - move to the beginning of next sentence
+
* {{ic|)}} - 次の文の先頭に移動
* {{ic|^}} - move to beginning of line
+
* {{ic|^}} - 行の先頭に移動
* {{ic|$}} - move to the end of line
+
* {{ic|$}} - 行の末尾に移動
   
  +
ページをスクロールするには以下のコマンドを使います:
To scroll the pages, use the following commands:
 
* {{ic|Ctrl+f}} - move one page down
+
* {{ic|Ctrl+f}} - 1ページ分だけ下に移動
* {{ic|Ctrl+b}} - move one page up
+
* {{ic|Ctrl+b}} - 1ページ分だけ上に移動
* {{ic|gg}} - goto first line of the document
+
* {{ic|gg}} - 文章の一番最初の行に移動
* {{ic|G}} - goto last line of the document
+
* {{ic|G}} - 文章の一番最後の行に移動
   
  +
コマンドに数字を付けることで、複数回コマンドを繰り返すことができます:
You can also use numbers with commands, so they would repeat '''n''' times:
 
* {{ic|5j}} - move cursor five lines down
+
* {{ic|5j}} - カーソルを5行下に移動
* {{ic|7w}} - move cursor seven words forward
+
* {{ic|7w}} - カーソルを7単語分先に移動
* {{ic|3 Ctrl+f}} - move three pages down
+
* {{ic|3 Ctrl+f}} - 3ページ下に移動
* {{ic|20gg}} - move cursor to line with number 20
+
* {{ic|20gg}} - カーソルを20行目に移動
   
  +
{{Tip|Spacemacs では数字の引数がよく使われます。}}
{{Tip|Numeric arguments are widely used in Spacemacs world.}}
 
   
  +
上記で説明していないコマンドも多数存在します。基本的には Spacemacs では '''Vim''' のように自由自在に移動できます。
There are a lot of commands uncovered. Basicaly, you can navigate between everything in Spacemacs, thanks to '''Vim-like''' flow. Check the additional resources to get the details.
 
   
 
====== テキスト操作 ======
 
====== テキスト操作 ======
133行目: 133行目:
 
以下のコマンドでテキストを編集することができます:
 
以下のコマンドでテキストを編集することができます:
   
* {{ic|x}} - cut the symbol under cursor
+
* {{ic|x}} - カーソルの文字をカット
* {{ic|dw}} - cut the word under cursor
+
* {{ic|dw}} - カーソルの単語をカット
* {{ic|dd}} - cut the line under cursor
+
* {{ic|dd}} - カーソルの行をカット
* {{ic|yw}} - copy (yank) the word under cursor
+
* {{ic|yw}} - カーソルの単語をコピー (ヤンク)
* {{ic|yd}} - copy (yank) the line under cursor
+
* {{ic|yd}} - カーソルの行をコピー (ヤンク)
  +
* {{ic|p}} - コピー・カットしたテキストを貼り付け
* {{ic|p}} - paste copied/cut text
 
* {{ic|r''a''}} - replace the symbol under cursor to ''a''
+
* {{ic|r''a''}} - カーソルの文字を ''a'' に置換
   
  +
上記のコマンドで数字引数を使うこともできます。
You can also use numeric arguments there.
 
   
 
====== アンドゥ/リドゥ ======
 
====== アンドゥ/リドゥ ======
   
  +
変更の取り消し・やり直しは以下のコマンドで行なえます:
You can undo and redo changes with the following commands:
 
* {{ic|u}} - undo last change
+
* {{ic|u}} - 最後の変更を取り消し
* {{ic|Ctrl+r}} - redo last change
+
* {{ic|Ctrl+r}} - 最後の変更をやり直し
   
 
===== 挿入ステート =====
 
===== 挿入ステート =====
  +
挿入ステートはテキストを入力するときに使います。普通のエディタと同じような動きをします。ただし、テキストを編集能力は限られています。訂正を行うときは'''ノーマルステート'''に戻してください。挿入ステートの色は'''グリーン'''です。
Insert state is used for the text input. It's very closed to regular editor behavior. However, the ability to modify text is limited. You will need to switch back to the '''normal state''' in order to make corrections. The color of insert state is '''green'''.
 
   
 
====== 挿入ステートに移行 ======
 
====== 挿入ステートに移行 ======

2017年11月5日 (日) 18:40時点における版

SpacemacsEmacs をベースに Vim のキーバインドを組み合わせて作られた、拡張性・カスタマイズ性の高いテキストエディタです。プロジェクトの目標は Vim と Emacs エディタそれぞれから長所を抽出して統合することです。Spacemacs ディストリビューションはコミュニティ主導の Emacs 設定を元にしています。デフォルトの Emacs の挙動を拡張しており大量の追加機能が存在します。

インストール

Emacs のインストール

Spacemacs は Emacs 上で作られているため、先に Emacs のインストールが必要です。emacs パッケージをインストールしてください。

既存の Emacs 設定をバックアップ (任意)

既に Emacs を使っている場合、設定をバックアップしてください:

$ mv ~/.emacs.d ~/.emacs.d.bak && mv ~/.emacs ~/.emacs.bak

Spacemacs のインストール

Spacemacs をインストールするには GitHub から設定を複製して Emacs の設定を完全に置き換える必要があります:

$ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
ノート: 上記のコマンドはユーザーアカウントから実行してください。

Adobe Source Pro フォントのインストール (任意)

Spacemacs が使用するデフォルトフォントは Adobe の Source Code Pro です。Spacemacs を使用するときはフォントをインストールすることが推奨されています。adobe-source-code-pro-fonts パッケージをインストールしてください。

フォントが存在しない場合、他のフォントが使われます。

Spacemacs の初期設定

Spacemacs を起動してください:

$ emacs

最初にインストールする機能について質問されます。選択は必須です。選択によって Spacemacs の挙動やホットキーが変わります。Enter を押してデフォルトの値を使うことを推奨します。デフォルト設定は高度に最適化されており後で自由に変えることもできます。

ヒント: 大抵の場合、デフォルトパッケージが機能を多めに提供しますが、場合によっては他のパッケージを使用するほうが便利なときもあります (性能面や特殊な機能など)。

質問を終えると、Spacemacs は必要なパッケージをダウンロード・インストールします。数分はかかります。Spacemacs がフリーズしているかのように見えるかもしれませんが、問題はありません。

Spacemacs の実行

spacemacs を起動するには:

$ emacs

下のバーに '...' が表示されなくなったら Spacemacs を使用できます。

ノート: 起動に10秒以上かかる場合、下のトラブルシューティングを見てください。

デーモンモード

Spacemacs はデーモンモードで起動することもできます。デーモンモードはエディタを一度だけ初期化して、後から設定ファイルを再読込することなく接続して使うことが可能です。巨大な設定ファイルを使っている場合、初期化が一度だけですむので便利です。初期化してしまえばすぐに接続することができます。

デーモンモードで Spacemacs を起動するには:

$ emacs --daemon=instance1

emacsclient を使って instance1 に接続できます:

$ emacsclient -nc -s instance1
ヒント: 名前を異なるものにすることでデーモンを複数起動することもできます。

使用方法

最初 Spacemacs は多少使いづらいかもしれません (特に初心者にとっては)。しかしながら、努力は報われます。基本的な作業をこなすのに覚えておく必要があることはほんの少しです。

:q[Enter] と打ち込むことでいつでも spacemacs を終了できます。

ビルトインチュートリアル

Spacemacs で SPC h T と押すことでいつでも Spacemacs に組み込まれているチュートリアルを立ち上げることができます。

基本概念

準備

基本概念を説明するのにお試し用のテキストが必要です。最初に作成しましょう。現段階ではコマンドがよく分からなくても結構です。

  1. Spacemacs を実行
  2. SPC b N を押して新しい空のバッファを作成
  3. 9 SPC i l l を押してテキストを挿入

9行のテキストが生成されるはずです。作成したテキストを使って次のセクションで説明しているコマンドを試してみてください。

ノート: SPC キーシーケンスを使うときは、ひとつずつキーを押してください。つまり SPACE, b, N の順番でキーを押します。大文字は Shift キーを押しながら押してください。例えば NShift+n です。最終的なシーケンスは SPACE, b, Shift+n となります。
ヒント: SPC キーを押すとヘルプメニューが下部に表示されます。メニューからコマンドを確認することが可能です。

最初にステートについて説明します。

エディタステート

Spacemacs と普通のテキストエディタの大きな違いはステートです。ステートによってエディタの動作が変わります。例えば (普通のテキストエディタと同じように) 文章を入力できる挿入ステートやキーが全てコマンドとして認識されて文章は変更されないノーマルステートが存在します。どれかひとつのステートが有効になります。ステートの切り替えは Spacemacs を使うにあたって鍵となるスキルです。

エディタの現在のステートは左下に表示されます。色付きの矩形に "1" (デフォルト) と表示されているのがそうで、色によって現在のステートが分かります。様々なステートが存在しますが、通常使用するステートは限られます:

  • オレンジはノーマルステートです。コマンドの入力やテキストの移動で使います。
  • グリーンは挿入ステートです。テキストの入力に使います。
  • グレーはビジュアルステートです。テキストの選択と操作に使います。

カーソルの色でも現在のステートは判別できます。

ノート: Spacemacs を使い込むには最低でもノーマル挿入ステートを知る必要があります。
ノーマルステート

ノーマルステートではテキストの移動とコマンドの実行ができます。ノーマルステートで直接テキストを打ち込むことはできません。代わりに、素早く移動したり様々な校正を行うことができます。ノーマルステートはデフォルトのステートであり、オレンジ色をしています。

ESC キーを押すか fd キーシーケンスでいつでもノーマルステートに戻ることが可能です。

ノート:
  • 以下に記載しているコマンドは全てではありません。他にもたくさんコマンドが存在します。ドキュメントを確認して有用なコマンドを探してください。
  • 誰もが最初はコマンドを知りません。使っていくうちに慣れていきます。最初に何かするときに必要なコマンドは限られています。
移動

以下のキーを使うことで基本的な移動が可能です:

  • h - 1文字分だけ左にカーソルを移動
  • j - 1文字分だけ下にカーソルを移動
  • k - 1文字分だけ上にカーソルを移動
  • l - 1文字分だけ右にカーソルを移動

単語あるいは文章単位の移動もひとつのキーで行うことができます:

  • w - 次の単語 (の先頭) に移動
  • b - 前の単語 (の先頭) に移動
  • ( - 現在の文の先頭に移動
  • ) - 次の文の先頭に移動
  • ^ - 行の先頭に移動
  • $ - 行の末尾に移動

ページをスクロールするには以下のコマンドを使います:

  • Ctrl+f - 1ページ分だけ下に移動
  • Ctrl+b - 1ページ分だけ上に移動
  • gg - 文章の一番最初の行に移動
  • G - 文章の一番最後の行に移動

コマンドに数字を付けることで、複数回コマンドを繰り返すことができます:

  • 5j - カーソルを5行下に移動
  • 7w - カーソルを7単語分先に移動
  • 3 Ctrl+f - 3ページ下に移動
  • 20gg - カーソルを20行目に移動
ヒント: Spacemacs では数字の引数がよく使われます。

上記で説明していないコマンドも多数存在します。基本的には Spacemacs では Vim のように自由自在に移動できます。

テキスト操作

以下のコマンドでテキストを編集することができます:

  • x - カーソルの文字をカット
  • dw - カーソルの単語をカット
  • dd - カーソルの行をカット
  • yw - カーソルの単語をコピー (ヤンク)
  • yd - カーソルの行をコピー (ヤンク)
  • p - コピー・カットしたテキストを貼り付け
  • ra - カーソルの文字を a に置換

上記のコマンドで数字引数を使うこともできます。

アンドゥ/リドゥ

変更の取り消し・やり直しは以下のコマンドで行なえます:

  • u - 最後の変更を取り消し
  • Ctrl+r - 最後の変更をやり直し
挿入ステート

挿入ステートはテキストを入力するときに使います。普通のエディタと同じような動きをします。ただし、テキストを編集能力は限られています。訂正を行うときはノーマルステートに戻してください。挿入ステートの色はグリーンです。

挿入ステートに移行

To enter the insert state, press i from the normal state. Your cursor will changed to thin and green one. Now you can type something. When you ready, just leave the insert state by pressing ESC key or fd key sequence.

There are a lot of ways to enter insert mode. The difference, however, is only related to initial cursor position. It would be enough to know just i hotkey for the first time. But there are also the others, and they will be very useful when you master them:

  • i - enter insert mode before the cursor
  • a - enter insert mode after the cursor
  • I - enter insert mode at the beginning of the line
  • A - enter insert mode at the end of the line
  • o - enter insert mode at next line
  • O - enter insert mode at previous line
挿入ステートから離脱

To leave the insert state press ESC key or fd key sequence. You will return to normal state and cursor will change to orange.

ビジュアルステート

This state used for visual text selection. It allows to select text chunks and cut/copy them. The state color is grey.

To enter visual state press v hotkey from the normal mode. Then you can navigate around using normal mode hotkeys with only one difference: text selection. Cursor movements would select text, based on initial cursor position, and you can yank (copy) or delete it later. Remember, that you can use commands like ve or v( to quickly select words or sentences. Check the Normal state: Navigation section to get the idea.

You can also press V to quickly select the whole line.

ビジュアルブロックステート

Visual block state is more powerful version of visual state. It allows to select text in columns. It's similar to multi-cursor concept on regular editors and IDEs. This state can be entered by pressing Ctrl+v hotkey. Then you can navigate with h j k l keys to see the difference.

There a lot of stuff that can be done in visual block state. Refer to the additional resources for this information. This feature is called vim visual block mode in origin.

バッファ (タブ)

The text in Spacemacs located in the areas called buffers. They are very similar to regular editor tabs. You can switch between the buffers and create new ones. Buffers are also used by editor itself by storing some information you can inspect later.

操作

To show the list of the current buffers press SPC b b. You will see a new window at the bottom. This is a place you can inspect, filter, and navigate buffers. Some buffers already exist there, like *Messages* and *scratch*. They created by the editor and contain some useful information.

The first thing you can do with the bottom window is to type anything into pattern field. This will filter buffers. If there are no buffers left after the filtering, you can create new one instead, just pressing "Enter" after your input. New buffer will be created and opened.

You can also open any buffer by hand. Press Ctrl+j or Ctrl+k to navigate between the lines. Then press Ctrl+l or Enter to confirm your choice. Selected buffer will be opened.

ヒント: Remember h j k l keys? They are widely used for navigation. In some cases we need to use modifier keys like Ctrl. That allows to input and navigate at the same time.

You can also use some hotkeys from normal state to control buffers:

  • SPC b b - list buffers
  • SPC TAB - switch to last viewed buffer
  • SPC b n - switch to next buffer (one forward)
  • SPC b p - switch to previous buffer (one backward)
  • SPC f s - save the current buffer to file
  • SPC b d - close current buffer
ヒント: If you want to save a new buffer, you should choose a file for it. Refer to the next section for details.

ファイル

Spacemacs provides a two options for file navigation: inline navigation and build-in file manager. Inline navigation is used in Spacemacs confirmation dialogs and it's very similar to the shell one. Build-in file manager is more user-friendly and allows to check the file details. Learning the basics of each is the essential key of mastering Spacemacs.

There also advanced options available, like more powerful file manager and file tree. They are covered in Advanced section.

インライン (Helm)

Inline navigation available with SPC f f hotkey. It uses the window very similar to buffer-navigation one. You can filter and select files there. Just type anything to narrow results, or press Ctrl+j or Ctrl+k for moving the line down and up. Press Ctrl+l to open file or directory, and press Ctrl+h for going backward. Press TAB to autocomplete the input.

ファイルマネージャ (Dired)

If you need more visual method, run built-in file manager by pressing SPC a d Enter. You can navigate, using Ctrl+h j k l keys, and press Enter to enter directories and open files.

There are some hotkeys available (refer to dired documentation for more):

  • q - quit dired
  • R - rename file
  • C - copy file
  • + - create new directory
ヒント: If you need more powerful file manager, check Ranger in Advanced section. It provides more features and can be the best replacement for Dired when you master it.

上級概念

At this step you are able to open files, make changes and save them successfully. Half the way is done, and now you can choose what to master next. There are some sections you may be interested.

レイヤー

One of the strongest features of Spacemacs is layers. Layer is a set of packages and configuration options, that greatly extends editor functionality in some way. There are layers for different programming languages, for example, or layers, providing additional tools (like IRC messaging, or integrated web browser). The full list of layers can be found at Layers documentation page.

Some layers are already shipped with Spacemacs, the others can be added manually. To do this, open Spacemacs configuration file (SPC f e d), and find dotspacemacs-configuration-layers section there. Then simply add selected layer to the list and restart Spacemacs. It will download all the required files on the next start.

Spacemacs will also offer you to install a new layer when you open a file with already-known extension. For example, if you open .html file, installation of html layer will be offered.

You can customize layer behaviour by overriding some layer-specific variables in your Spacemacs configuration file. Check the appropriate layer documentation to get the details.

ファイル操作

ファイル操作に役立つツールが複数存在します。日常的な Spacemacs の使い勝手を大幅に向上させてくれます。

ファイルツリー (Neotree)

SPC f t を押すことでファイルツリーを起動できます。新しいウィンドウを開いて SPC 0 でアクセスできます。標準の h j k l による移動が可能です。R でルートフォルダを変更して s で隠しファイルを表示できます。新しいファイルは c で作成し、ファイル名の変更は r で行えます。詳しくは Neotree のドキュメントを参照してください。

ヒント: ルートフォルダを上層に変更したい場合、現在のルートパス (ウィンドウの最初の行) で R を押してください。インラインのファイルナビゲーションが開くので、H で上に移動してから . ディレクトリを選択してください。
ファイルマネージャ (Ranger)

フル機能のファイルマネージャが必要な場合、Ranger が最適でしょう。高速な h j k l による移動やインラインファイルプレビュー、ファイルの操作など便利な機能が多数存在します。また、デフォルトの Dired の挙動 (SPC a d) が改善されます。ranger レイヤーをインストールして SPC a r で起動してください。詳しくは Ranger のドキュメントを参照。カスタマイズオプションや便利なホットキーがあります。

ノート: Ranger を開けない場合、Neotree を閉じてみてください。

ウィンドウ

Spacemacs では画面を複数のウィンドウに分割することができます。ウィンドウにはそれぞれ番号が割り当てられ SPC n ホットキーでアクセスできます (n を番号に置き換えてください)。ウィンドウは独立して分割できるため、複雑なレイアウトを作成することができます。

ウィンドウを操作するホットキーは以下の通りです。他のホットキーはインラインヘルプ (SPC w) を確認してください。

  • SPC w 3 - 3番のウィンドウにフォーカス
  • SPC w s - ウィンドウを水平に分割
  • SPC w v - ウィンドウを垂直に分割
  • SPC w d - ウィンドウを削除
  • SPC w u - 最後のウィンドウアクションを取り消す
  • SPC w m - ウィンドウのフルスクリーンの切り替え
  • SPC w . - ウィンドウをトランジェントステートにする
ヒント: トランジェントステートではウィンドウの順番や割合などの設定を変えることができます。トランジェントステートにすると利用可能なオプションが表示されます。

トラブルシューティング

起動が遅い

起動時間が10秒を超える場合、おそらく exec-path-from-shell モジュールが原因です。Linux 環境では無効化しても問題ありません。以下の手順に従ってください:

  1. SPC f e d を押して Spacemacs の設定ファイルを開いてください。
  2. dotspacemacs-excluded-packages セクションを探してください。
  3. exec-path-from-shell モジュールを追加して、最後のエントリが dotspacemacs-excluded-packages '(exec-path-from-shell) となるようにしてください。
  4. SPC f s で変更を保存して Spacemacs を再起動してください。