Skip to content

Instantly share code, notes, and snippets.

@yskszk63
Created November 15, 2020 12:11
Show Gist options
  • Save yskszk63/6534808a92ae5dcda1ac1158588c52e0 to your computer and use it in GitHub Desktop.
Save yskszk63/6534808a92ae5dcda1ac1158588c52e0 to your computer and use it in GitHub Desktop.

Vim :s

自分向けのメモ

テキストを削除

%s/GATT Characteristic and Object Type//g
%s/GATT Service//g

パターンで改行

%s/0x2A../\r\0\t/g
%s/0x18../\r\0\t/g
0x2A00foo bar hoge0x2A01zzz...
---

0x2A00	foo bar hoge
0x2A01	zzz
...

タブを挟んでスワップ + コメント

%s/^\(.*\)\t\(.*\)$/\/\/\/ \2\r\2\t\1/g
0x2A00	foo bar hoge
0x2A01	zzz
---
/// foo bar hoge
foo bar hoge	0x2A00
/// zzz
zzz	0x2A01
...

コメント行を除いたスペースをアンダースコアに変換

%s/^\([^\/]*\) /\1_/g
/// foo bar hoge
foo bar hoge	0x2A00
/// zzz
zzz	0x2A01
---
/// foo bar hoge
foo bar_hoge	0x2A00
/// zzz
zzz	0x2A01

コメント行を除いたタブ文字までを大文字に変換

%s/^\([^\/]\).*\(\t\)\@=/\U&/g
/// foo bar hoge
foo_bar_hoge	0x2A00
/// zzz
zzz	0x2A01
---
/// foo bar hoge
FOO_BAR_HOGE	0x2A00
/// zzz
ZZZ	0x2A01

コメント行を除いた先頭にテキスト追加

%s/^\([^\/]\)\@=/pub const /g
/// foo bar hoge
FOO_BAR_HOGE	0x2A00
/// zzz
ZZZ	0x2A01
---
/// foo bar hoge
pub const FOO_BAR_HOGE	0x2A00
/// zzz
pub const ZZZ	0x2A01

タブ文字をテキストに変換

%s/\t/: Uuid = Uuid::new_uuid16(/g
/// foo bar hoge
pub const FOO_BAR_HOGE	0x2A00
/// zzz
pub const ZZZ	0x2A01
---
/// foo bar hoge
pub const FOO_BAR_HOGE: Uuid = Uuid::new_uuid(0x2A00
/// zzz
pub const ZZZ: Uuid = Uuid::new_uuid(0x2A01

コメント行を除いた行末にテキストを追加

%s/^[^\/].*/\0);/g
/// foo bar hoge
pub const FOO_BAR_HOGE: Uuid = Uuid::new_uuid(0x2A00
/// zzz
pub const ZZZ: Uuid = Uuid::new_uuid(0x2A01
---
/// foo bar hoge
pub const FOO_BAR_HOGE: Uuid = Uuid::new_uuid(0x2A00);
/// zzz
pub const ZZZ: Uuid = Uuid::new_uuid(0x2A01);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment