golangの日記

Go言語を中心にプログラミングについてのブログ

テキストエディタ GNU nano チートシート

default-gray.png


テキストエディタ GNU nano のショートカットキーと設定方法などの使い方。「vim 使うから nano なんてどうでもいいよ」って人が多いのかもしれないけどlinux 使ってるとデフォルトのエディタがこれになってることがあるのでまとめたやつ。





目次





ショートカットキー



ヘルプの ^ / M / Sh の意味

^ Ctrl キー
M Alt キーまたは Esc キー(メタキー)
Esc の場合は同時押しする必要はない。
Sh Shift キー


ヘルプ(- help)

^G (F1) ヘルプ表示
M-X 下に常時表示されてるヘルプの表示/非表示


ファイル操作(- file)

^S 上書き保存
^O (F3) 名前を付けて保存

^X (F2) ファイルを閉じる/終了
^R (Ins) 現在開いているファイルに追記で他のファイルを読み込む。
M-F または起動時に-F/--multibuffer オプションを指定している場合は、
追記ではなく別のバッファにファイルを開く。(M-<, M->)でファイルを切り替える

M-◀ (M-<) 前のファイル(起動時に複数ファイルを開いている場合。または ^R で別のファイルを開いている場合)
M-▶ (M->) 次のファイル(起動時に複数ファイルを開いている場合。または ^R で別のファイルを開いている場合)


マウス(- mouse)

M-M マウスの有効化/無効化


インフォメーション関連(- information)

^C (F11) 現在のカーソル位置を 行数、列番号、相対的な文字数 で表示
M-C 現在のカーソル位置を常に表示/非表示 (set constantshow)
M-D 全体の 単語数、行数、文字数 の表示
M-N 行数番号の表示/非表示


移動(- move)

文字の移動に関する操作はだいたい terminal と同じ

^B (◀) 行頭に向かって一文字移動
^F (▶) 行末に向かって一文字移動
^A (Home) 行頭に移動
^E (End) 行末に移動
^◀ (M-Space) 行頭に向かって一単語移動
^▶ (^Space) 行末に向かって一単語移動

M-\ (^Home) 一番上に移動
M-/ (^End) 一番下に移動

M-G (^\_) 入力した 行番号,列番号 へ移動

M-] 対応するカッコへ移動

^Y (PageUp) 1ページ分スクロールアップ
^V (PageDown) 1ページ分スクロールダウン

^▲ (M-7) 次の文字ブロックへ移動(空白を飛ばす)
^▼ (M-8) 前の文字ブロックへ移動(空白を飛ばす)

M-( (M-9) 前の段落の先頭へ移動
M-) (M-0) 次の段落の最後へ移動

M-▲ (M--) 現在のカーソルを中心に上にスクロール
M-▼ (M-+) 現在のカーソルを中心に下にスクロール


削除 (- delete)

^H (BS) 行頭に向かって一文字削除
^D (Del) 行末に向かって一文字削除(Delete)
Sh-^Del 行頭に向かって一単語削除
^Del 行末に向かって一単語削除


コピー/切り取り/貼り付け (- copy - cut - paste)

M-6 一行または選択範囲のコピー

^K 一行または選択範囲の切り取り/削除
M-K を有効にするとカーソル位置から行末までの切り取りになる。

M-K 有効にすると ^K を一行切り取りから行末切り取りにする。
(set cutfromcursor)

M-Del 現在の行または選択範囲の削除

M-T カーソルからファイルの最後まで切り取り

^U (F10) 貼り付け(F10)(ペースト)


行の連結 (- join - justify)

^J (F4) 行の結合(空白行までを現在の行末に結合する)
M-J ファイル全体を段落ごとに行を結合する


アンドゥ/リドゥ (- undo - redo)

M-E アンドゥ
M-U リドゥ


改行/行の追加 (- new line)

^M (Enter) 行の追加


インデント (- indent)

^I (Tab) タブの挿入
M-} (Tab) インデント
M-{ (Sh-Tab) アンインデント
M-I オートインデントの有効化/無効化


検索 (- search - find)

^W (F6) 後方検索
^Q 前方検索

検索候補へ移動
M-W 次の検索候補へ移動
M-Q 前の検索候補へ移動


置換 (- replace)

^\ (M-R) 文字の置換


文字の選択 (- select)

M-A (^6) 文字選択の有効/無効

Tab 選択した領域のインデント
Sh-Tab 選択した領域をアンインデント


補完 (- complete)

^] 補完


コメントアウト/アンコメント (- comment - uncomment)

M-3 現在の行のコメント/アンコメント(選択状態であれば全体をコメント/アンコメントする)


マクロ (- macro)

M-: マクロの記録を開始/終了する
M-; 最後に記録したマクロの実行


その他 (- others)

M-P 空白の可視化表示/非表示
M-O タブを空白で置き換える。有効化/無効化

M-S 長い行のソフトラップを有効化/無効化 (set softwrap)
M-L 長い行のハードラップを有効化/無効化 (set breaklonglines)

M-Y シンタックスハイライトの有効化/無効化
各言語の設定ファイルは /usr/share/nano/ 以下にある

M-H スマート Home キーの有効化/無効化 (set smarthome)
有効化した場合は行頭の空白以外の一文字目にカーソルを移動する。
カーソルが一文字目にある場合は行の先頭(空白でも)に移動する。

^T (F12) スペルチェック

M-B リンターが利用可能な場合に実行する
/usr/share/nano/python.nanorc では linter pyflakes となっている

M-F フォーマッターを実行する
/usr/share/nano/go.nanorc では formatter gofmt -w となっている

^L 再読込

^Z 一時停止(M-Z でサスペンションが有効化されているときのみ)
jobs で停止しているコマンドを確認。fg で復帰。
M-Z 一時停止(^Z)の有効化/無効化

M-V キーストロークを文字化する(例えば M-V 状態で Enter を押すと ^M と入力される)



設定ファイル(- config - setting)



nano に関するディレクトリ(ubuntu)

/usr/share/doc/nano
/usr/share/nano
/usr/share/doc-base/nano

設定ファイルのパス

/etc/nanorc
~/.nanorc



各種設定


単語移動(Ctrl+Right)を、次の単語の先頭ではなく現在の単語の終わりにする。

set afterends


ソフトラップが有効の場合に、単語を途中で分割しないように空白/タブで折り返す。

set atblanks


オートインデント(行を追加したときに自動で字下げする)

set autoindent


バックアップファイルを有効化する

set backup


バックアップファイルを作成するディレクトリを指定する

set backupdir "/path/to/dir"


折返しをハードラップする。

set breaklonglines


検索するときにデフォルトで大文字/小文字を区別する

set casesensitive


現在のカーソル位置を常に表示する(M-C)

set constantshow


K を一行切り取りではなくカーソル位置から行末までにする(M-K)

set cutfromcursor


タイトルバー下を一行分空ける

set emptyline


画面半分スクロールする。通常は一行ずつスクロール

set jumpyscrolling


行番号を表示する

set linenumbers


マウスの有効化。シングルクリックでのカーソル移動やダブルクリックで範囲選択の開始/終了する。

set mouse


R で複数ファイルを開くようにする(^R のデフォルトは追記)

set multibuffer


下に常時表示されてるヘルプの非表示

set nohelp


ファイルの最後に空白行を追加しない(デフォルトでは空行が追加される)

set nonewlines


カーソル位置を記憶する。次回ファイルを開いたときに、そのカーソル位置になる。

set positionlog


キーが押されたら即ステータスバーを消す

set quickblank


検索にデフォルトで正規表現を使う

set regexp


スマート Home キーの有効化。A を押すと行頭の空白以外の一文字目にカーソルを移動する。 カーソルが一文字目にある場合は行の先頭(空白でも)に移動する。

set smarthome


長い行をソフトラップする。

set softwrap


スペルチェッカーを設定する

set speller "aspell -x -c"


サスペンド(^Z)の許可。(M-Z)

set suspend


タブサイズを設定する。

set tabsize 8


タブを空白で置き換える。

set tabstospaces


行を連結させたとき(^J)または、行の折返しにハードラップを設定している場合に行末の空白を削除する

set trimblanks


選択範囲を Backspace/Delete キーで削除可能にする

set zap


インターフェースの色に関するやつ

## Paint the interface elements of nano.  These are examples;
## by default there are no colors, except for errorcolor.
# set titlecolor brightwhite,blue
# set statuscolor brightwhite,green
# set errorcolor brightwhite,red
# set selectedcolor brightwhite,magenta
# set stripecolor ,yellow
# set numbercolor cyan
# set keycolor cyan
# set functioncolor green
## In root's .nanorc you might want to use:
# set titlecolor brightwhite,magenta
# set statuscolor brightwhite,magenta
# set errorcolor brightwhite,red
# set selectedcolor brightwhite,cyan
# set stripecolor ,yellow
# set numbercolor magenta
# set keycolor brightmagenta
# set functioncolor magenta


設定ファイルを指定して有効にする(/usr/share/nano/ 以下の *.nanorc を含める)

include "/usr/share/nano/*.nanorc"


ショートカットキーの bind/unbind

#bind ^Q exit all
#bind ^S savefile main
#bind ^W writeout main
#bind ^O insert main
#bind ^H help all
#bind ^H exit help
#bind ^F whereis all
#bind ^G findnext all
#bind ^B wherewas all
#bind ^D findprevious all
#bind ^R replace main
#bind M-X flipnewbuffer all
#bind ^X cut all
#bind ^C copy main
#bind ^V paste all
#bind ^P curpos main
#bind ^A mark main
#unbind ^K main
#unbind ^U all
#unbind ^N main
#unbind ^Y all
#unbind M-J main
#unbind M-T main
#bind ^T gotoline main
#bind ^T gotodir browser
#bind ^Y speller main
#bind M-U undo main
#bind M-R redo main
#bind ^U undo main
#bind ^E redo main
#set multibuffer


その他、調べてないやつ

## Use bold text instead of reverse video text.
# set boldtext

## The characters treated as closing brackets when justifying paragraphs.
## This may not include any blank characters.  Only closing punctuation,
## optionally followed by these closing brackets, can end sentences.
# set brackets ""')>]}"

## Set the target width for automatic hard-wrapping and for justifying
## paragraphs.  If the specified value is 0 or less, the wrapping point
## will be the terminal's width minus this number.
# set fill -8

## Remember the used search/replace strings for the next session.
set historylog

## Enable vim-style lock-files.  This is just to let a vim user know you
## are editing a file [s]he is trying to edit and vice versa.  There are
## no plans to implement vim-style undo state in these files.
set locking

## The opening and closing brackets that can be found by bracket
## searches.  They cannot contain blank characters.  The former set must
## come before the latter set, and both must be in the same order.
# set matchbrackets "(<[{)>]}"

## Don't convert files from DOS/Mac format.
# set noconvert

## Set operating directory.  nano will not read or write files outside
## this directory and its subdirectories.  Also, the current directory
## is changed to here, so any files are inserted from this dir.  A blank
## string means the operating-directory feature is turned off.
# set operatingdir ""

## Preserve the XON and XOFF keys (^Q and ^S).
# set preserve

## The characters treated as closing punctuation when justifying
## paragraphs.  They cannot contain blank characters.  Only closing
## punctuation, optionally followed by closing brackets, can end
## sentences.
# set punct "!.?"

## The regular expression that matches quoting characters in email
## or line-comment introducers in source code.  The default is:
# set quotestr "^([     ]*([!#%:;>|}]|//))+"

## Try to work around a mismatching terminfo terminal description.
# set rawsequences

## Fix Backspace/Delete confusion problem.
# set rebinddelete

## Put the cursor on the highlighted item in the file browser, and show
## the cursor in the help viewer; useful for people who use a braille
## display and people with poor vision.
# set showcursor

## Save automatically on exit; don't prompt.
# set tempfile

## Disallow file modification.  Why would you want this in an rcfile? ;)
# set view

## The two single-column characters used to display the first characters
## of tabs and spaces.  187 in ISO 8859-1 (0000BB in Unicode) and 183 in
## ISO-8859-1 (0000B7 in Unicode) seem to be good values for these.
## The default when in a UTF-8 locale:
# set whitespace "»·"
## The default otherwise:
# set whitespace ">."

## Detect word boundaries differently by treating punctuation
## characters as parts of words.
# set wordbounds

## The characters (besides alphanumeric ones) that should be considered
## as parts of words.  This option does not have a default value.  When
## set, it overrides option 'set wordbounds'.
# set wordchars "<_>."

## If <Tab> should always produce four spaces when editing a Python file,
## independent of the settings of 'tabsize' and 'tabstospaces':
# extendsyntax python tabgives "    "

## If <Tab> should always produce an actual TAB when editing a Makefile:
# extendsyntax makefile tabgives "  "

## Key bindings.
## See nanorc(5) (section REBINDING KEYS) for more details on this.

## The <Ctrl+Delete> keystroke deletes the word to the right of the cursor.
## On some terminals the <Ctrl+Backspace> keystroke produces ^H, which is
## the ASCII character for backspace, so it is bound by default to the
## backspace function.  The <Backspace> key itself produces a different
## keycode, which is hard-bound to the backspace function.  So, if you
## normally use <Backspace> for backspacing and not ^H, you can make
## <Ctrl+Backspace> delete the word to the left of the cursor with:
# bind ^H chopwordleft main