如何使用Vim插入此文本块?

时间:2015-12-20 11:41:54

标签: vim

我是Vim初学者,我想知道有经验的Vim用户如何输入这个Haskell代码块(来自http://learnyouahaskell.com/syntax-in-functions):

sayMe :: (Integral a) => a -> String  
sayMe 1 = "One!"  
sayMe 2 = "Two!"  
sayMe 3 = "Three!"  
sayMe 4 = "Four!"  
sayMe 5 = "Five!"  
sayMe x = "Not between 1 and 5" 

我想可以使用某种列操作(可视模式?)来编写“sayMe”和“=”。

提前致谢!

1 个答案:

答案 0 :(得分:3)

我从这开始:

sayMe 1 = ""

现在处于正常模式时qwYp^Aq4@w(注意^A是单个字符,control-A)。结果将是:

sayMe 1 = ""
sayMe 2 = ""
sayMe 3 = ""
sayMe 4 = ""
sayMe 5 = ""
sayMe 6 = ""

然后我有一张有用的地图(在我看来):

nnoremap Q $i

这会在最后一个字符之前进入插入模式。所以我去插入 引用内容(后续行,在向下移动后将已经在 最后一个字符,所以一个简单的i就足够了。而且,在最后,我改变了 输入报价内容后,6x只需F6rx个简单。

sayMe 1 = "One!"
sayMe 2 = "Two!"
sayMe 3 = "Three!"
sayMe 4 = "Four!"
sayMe 5 = "Five!"
sayMe x = "Not between 1 and 5"

然后ggO多次转到顶部^E以插入底线 内容,直到冒号。那部分只是常规打字。

sayMe :: (Integral a) => a -> String
sayMe 1 = "One!"
sayMe 2 = "Two!"
sayMe 3 = "Three!"
sayMe 4 = "Four!"
sayMe 5 = "Five!"
sayMe x = "Not between 1 and 5"

我希望这会有所帮助。只是一个想法。您可以通过:s//\=来获得更高级的体验 自动插入数字,但我认为这对我来说会更快(对我来说) 它只有几行。