1. 程式人生 > >sublime text 3 下的nodejs環境配置以及新增nodejs的操作按鈕實現殺死node程序(加快捷鍵)

sublime text 3 下的nodejs環境配置以及新增nodejs的操作按鈕實現殺死node程序(加快捷鍵)

首先感謝http://blog.csdn.net/ender__/article/details/53289066作者提供的幫助,前期的配置和他的配置相同可憐

首先謝謝我參考的環境配置同學的資料

https://my.oschina.NET/ximidao/blog/413101

在該操作基礎上

安裝nodejs的外掛後,環境配置成功後的兩個檔案內容

Nodejs.sublime-build

  1. {  
  2.   "cmd": ["node", "$file"],  
  3.   //"cmd": ["node","--debug", "–use-strict", "–harmony","-p", "$file"],  
  4.   "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",  
  5.   "selector": "source.js",  
  6.   "shell":true,  
  7.   "encoding": "utf8",  
  8.   "windows":  
  9.     {  
  10.         //"cmd": ["call","killnodejs.bat $file"]  
  11.         //"cmd": ["taskkill /F /IM node.exe &  node $file"]  
  12.         "cmd": ["node", "$file"]  
  13.     },  
  14.   "linux":  
  15.     {  
  16.         "cmd": ["killall node; node $file"]  
  17.     },  
  18.     "osx":  
  19.     {  
  20.         "cmd": ["killall node; node $file"]  
  21.     }  

然後是Nodejs.sublime-settings

  1. {  
  2.   // save before running commands  
  3.   "save_first": true,  
  4.   // if present, use this command instead of plain "node"  
  5.   // e.g. "/usr/bin/node" or "C:\bin\node.exe"  
  6.   "node_command": "C:\\Program Files\\nodejs\\node.exe",  
  7.   // Same for NPM command  
  8.   "npm_command": "C:\\Program Files\\nodejs\\npm.cmd",  
  9.   // as 'NODE_PATH' environment variable for node runtime  
  10.   //"node_path": false,  
  11.   "expert_mode": true,  
  12.   "ouput_to_new_tab": false  
  13. }  
其中的路徑為我本地的nodejs環境安裝路徑 現在開始新增kill node程序的選單配置 在檔案Main.sublime-menu內容 { "id": "nodejsrun", "caption": "Run", "command": "node_run" },內容後新增一行以下內容
  { "id": "nodejsstop", "caption": "Stop", "command": "node_stop" }, 在Context.sublime-menu檔案 { "id": "nodejsrun", "caption": "Run", "command": "node_run" },後新增一行以下內容
   { "id": "nodejsstop", "caption": "Stop", "command": "node_stop" }, 在檔案Default.sublime-commands內容為 {
  "caption": "Nodejs::Run::Current File",
  "command": "node_run"
}, 的後面新增
{
  "caption": "Nodejs::Stop::Current File",
  "command": "node_stop"
}, 在Nodejs.py檔案 內容為
  1. # Command to Run node
  2. class NodeRunCommand(NodeTextCommand):  
  3.   def run(self, edit):  
  4.     command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
  5.     os.system(command)  
  6.     command = ['node'self.view.file_name()]  
  7.     self.run_command(command, self.command_done)  
  8.   def command_done(self, result):  
  9.     s = sublime.load_settings("Nodejs.sublime-settings")  
  10.     if s.get('output_to_new_tab'):  
  11.       self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")  
  12.     else:  
  13.       self.panel(result)  
的後面新增
  1. # Command to Stop node
  2. class NodeStopCommand(NodeTextCommand):  
  3.   def run(self, edit):  
  4.     command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
  5.     os.system(command)  
  6.     command = 'taskkill /F /IM node.exe'#the command when os is win,then run cmd command
  7.     result = os.system(command)  
  8.     s = sublime.load_settings("Nodejs.sublime-settings")  
  9.     if s.get('output_to_new_tab'):  
  10.       self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")  
  11.     else:  
  12.       self.panel(result)  
因為我是在Win10上安裝的軟體,所以開啟Default (Windows).sublime-keymap在其中新增: {"keys": ["alt+c"], "command": "node_stop"}
實現了關閉由sublime開啟的nodejs程序。