【VScode】Sort linesでテキストの並び替えをする
概要
Windowsでテキストファイルをメモ帳(notepad)で開き、中のテキストデータをソートしようと思ったのですが、メモ帳の機能ではソートできないことに気づきました。
そこでVScodeの「sort lines」というプラグインを使用して並び替えをしてみたので紹介していきたいと思います。
Step 1 : Sort linesのインストール
まず初めに今回使用するプラグインである「Sort lines」をVScodeをインストールしていきたいと思います。
VScodeを開き、拡張プラグインの検索ボックスに「sort」と入力すると「Sort lines」が見つかりますので、[Install]ボタンを選択します。

プラグイン自体が軽いこともあり、インストールは一瞬で終わりました。
完了すると以下のような機能一覧の表示が現れます。

Step 2 :試しにソートする
Sort linesの機能を試すために適当なテキストファイルを作成してました。

このファイルをVScodeで開きます。

ソートしたい範囲を選択し、右クリックを押すと[Sort lines(ascending, case sensitive)]メニューが追加されていることが確認できました。F9がascendign(昇順)のショートカットキーになっているようです。
これをクリックしてみます。

昇順ソートされていることが確認できました。

非常にお手軽にできました。
Step 3:その他の機能をみる
Ctrl + Shift + Pでコマンドパレットを表示し、「sort」と入力し、Sort linesの機能を表示してみます。

昇順ソート insentive
Sort lines (ascending, case insensitive)を選択すると、アルファベットの大文字と小文字の区別なく昇順ソートしてくれました。

降順ソート
Sort lines (descending, case sensitive)を選択するとアルファベット大文字、小文字を区別した状態での降順ソートになります。

文字長さ昇順ソート
Sort lines (line length ascending)を選択すると文字の長さが短い順にソートされます。

文字長さ降順ソート
Sort lines (line length ascending) を選択すると文字の長さが長い順にソートされます。

自然ソート
Sort lines (natural)を選択すると基本的に昇順ソートと同じような感じですが、<3l>と<10ad>という文字列でそれぞれ最初の数字列を見て数字の小さい順に並べてくれました。通常の昇順ソートだと<10ad>が先にきます。

重複削除
Sort lines (remove duplicate lines)を選択すると重複している行が削除されます。(ソートはされません)
元データ

remove duplicate lines実行後

シャッフル
Sort lines (shuffle)を選択するとランダムにシャッフル(並び替え)が行われます。
シャッフルするたびに変わります。(左:1回目、右:2回目)

まとめ
Sort linesはシンプルで軽量ですがソートのオプションや重複削除やシャッフルなど便利な機能が備わっていて便利でした。コマンドパレットからショートカットキーを割り当てておくとさらに使い勝手がいい気がしました。