LoginSignup
7
5

More than 5 years have passed since last update.

Atomで行移動(moveLineUp/moveLineDown)時のオートインデントをオフにする方法

Last updated at Posted at 2015-12-24

前置き

【超おすすめ!!】Atomのパッケージ、テーマ、キーバインディング、設定を紹介してみる(※随時更新):カスタム設定:行移動時のオートインデントをオフにする
↑の記事にも追記したのですが、探してる人向けに別記事化しましたー。

行移動時のオートインデントをオフにする方法

v1.3.0 (2015-12-10)の更新で下記の行移動時に自動でインデントする機能が追加されたのですが、これが不具合を起こしていて、一行だけの移動なら良い感じに動いてくれるのですが、複数行を移動させる時にファイルタイプにも依りますが、結構な確率でコードの構造を壊してしまいます…その問題の取り敢えずの解決法を考えたので、かなり微妙なやり方ですが紹介してみたいと思います。

v1.2.4...v1.3.0
...
atom/atom#9104 - autoindent lines with moveLineUp/moveLineDown on November 3rd 2015
...

引用元:https://atom.io/releases

手順は簡単で、まずはinit.coffeeに下記のコードを追加します。

init.coffee
atom.commands.add 'atom-text-editor', 'my:move-line-up', ->
  editor = atom.workspace.getActiveTextEditor()
  if atom.config.get('editor.autoIndent')
    atom.config.set('editor.autoIndent', false)
    editor.moveLineUp()
    atom.config.set('editor.autoIndent', true)
  else
    editor.moveLineUp()

atom.commands.add 'atom-text-editor', 'my:move-line-down', ->
  editor = atom.workspace.getActiveTextEditor()
  if atom.config.get('editor.autoIndent')
    atom.config.set('editor.autoIndent', false)
    editor.moveLineDown()
    atom.config.set('editor.autoIndent', true)
  else
    editor.moveLineDown()

次にkeymap.csonに下記の設定を追加して終了です。

「.pratform-linux」部分は各種OSの物に変更してくださーい。
keymap.cson
'.platform-linux atom-workspace atom-text-editor:not([mini])':
  'ctrl-shift-up': 'my:move-line-up'
  'ctrl-shift-down': 'my:move-line-down'

これで以前の行移動の動作と同じ様な動きになっているかと思います。

最後に

atom/atom#9104 - autoindent lines with moveLineUp/moveLineDownのページを見て貰えれば分かるかと思うのですが、GitHubの中の人が、この問題に対応出来るまで一旦この機能を削除した方が良いかも的な事を言っているので、この設定は次の更新で不必要になるかもしれません…
(´・ω・`)

その時はまたここでもお知らせしますねー。
(`・ω・´)b

7
5
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
7
5