哈希火箭的中心键和值

时间:2014-08-25 22:59:04

标签: regex vim vim-tabular

使用vim-tabular我试图将其格式化如下:

foo = {
    "iSortCol_0" => "1",
    "sSortDir_0" => "desc",
  "iSortingCols" => "1",
   "bSortable_0" => "false",
   "bSortable_1" => "true",
   "bSortable_2" => "false",
   "bSortable_3" => "true",
   "bSortable_4" => "false",
   "bSortable_5" => "true",
   "bSortable_6" => "true",
   "bSortable_7" => "true",
   "bSortable_8" => "true"
}

我有随机格式化的红宝石哈希中的项目列表,例如如下:

foo = {
      "iSortCol_0" => "1",
"sSortDir_0" => "desc",
    "iSortingCols" =>"1",
     "bSortable_0" =>   "false",
     "bSortable_1" => "true",
     "bSortable_2"=> "false",
     "bSortable_3"  => "true",
     "bSortable_4"   => "false",
     "bSortable_5" => "true",
     "bSortable_6" =>    "true",
     "bSortable_7" =>"true",
     "bSortable_8" => "true"
}

我可以使用Tab /=>来完成它,但它并不能完全产生预期的结果:

foo = {
      "iSortCol_0" => "1",
"sSortDir_0"       => "desc",
    "iSortingCols" => "1",
     "bSortable_0" => "false",
     "bSortable_1" => "true",
     "bSortable_2" => "false",
     "bSortable_3" => "true",
     "bSortable_4" => "false",
     "bSortable_5" => "true",
     "bSortable_6" => "true",
     "bSortable_7" => "true",
     "bSortable_8" => "true"
}

如何指定对齐符号的一侧?我想我需要使用\zs\ze,但我很难将其用于此目的。

1 个答案:

答案 0 :(得分:1)

您需要为每个部分指定对齐方式:

Tabularize/=>/r1l1l0
右侧为{p> r,左侧为l,中心为c。每个部分后面都有空格数。因此,您在=>上拆分意味着=>之前有一个部分,=>本身以及=>之后的部分文字。

由于我不喜欢正确对齐,您可能希望通过=i}缩进代码,然后执行:Tabularize/=>/