如何使用vim模式删除visual studio代码上的空行

时间:2017-11-22 12:36:51

标签: vim visual-studio-code

我一直试图从一个巨大的文件中删除许多空行。对于//main.py #mysql database class db = MySQLDBClass() #mqtt client class where subscription,connection to broker,some callbacks mqttclient = MyMQTTClient() mqttclient.on_message = db.onMessage mqttclient.loop_forever() //MySQLDBClass.py def __init__(self): self.insertcounter = 0 self.insertStatement = '' self.bulkpayload = '' self.maxInsert = 1000 def onMessage(self, client, userdata, msg): if msg.topic.startswith("topic1/"): self.bulkpayload += "(" + msg.payload.decode("utf-8") + "," + datetime + ")," elif msg.topic.startswith("topic2/"): self.insertStatement += "INSERT INTO mydatabase.table1 VALUES (" + msg.payload.decode("utf-8") + "," + datetime + ");" elif msg.topic.startswith("topic3/") self.insertStatement += "INSERT INTO mydatabase.table2 VALUES (" +msg.payload.decode("utf-8") + "," + datetime + ");" elif msg.topic.startswith("messages"): self.insertStatement += "INSERT INTO mydatabase.table3 VALUES ('" + msg.topic + "'," + msg.payload.decode("utf-8") + "," + datetime + ");" else: return # do not store in DB self.insertcounter += 1 if ( self.insertcounter > self.maxInsert ): if ( self.bulkpayload != '' ): self.insertStatement += "INSERT INTO mydatabase.table4 VALUES" + self.bulkpayload + ";" self.bulkpayload = '' cursor.execute(self.insertStatement) cursor.commit() print (cursor.rowcount) #prints always count as one , expecting bulk count self.insertcounter = 0 self.insertStatement = '' vim本身的其他编辑,我可以这样做:

vim

但是,如果我使用:%s/\n\n/\n/g \r它都不起作用。似乎编辑器中缺少某些\t功能。是否有任何配置可以使这项工作或其他方式做到这一点?

1 个答案:

答案 0 :(得分:2)

要在VScode中使用高级Vim功能,您可以利用其Neovim集成。

首先,您必须安装Neovim。有关说明,请查看:https://github.com/neovim/neovim/wiki/Installing-Neovim

然后,在您的用户配置中调整以下设置:

// Use neovim on backend. (only works for Ex commands right now). You should restart VScode after enable/disabling this for the changes to take effect. NOTE: Neovim must be installed (v0.2.0) and neovimPath must be set the executable in order for this setting to work. Otherwise, vscodevim will crash.
  "vim.enableNeovim": true,

// Path to run neovim executable. For example, /usr/bin/nvim, or  C:\Program Files\Neovim\bin\nvim.exe
  "vim.neovimPath": "nvim",

重启VScode。现在您可以使用Vim Ex命令,因为命令被发送到在后台运行的无头Neovim实例。您甚至可以在一定程度上使用已安装的Vim插件功能。