2021年11月6日 星期六

VIM Script 8.0.xx not execute channel command right away

 

I encountered this issue while developing my vim plugins. Although, 

Env/Platform: 

    VIM 8.0.1365

    MAC OS X Mojave

 

Problem: 

    When server send a channel command to VIM client, there is a notable gap between the command receiving time and execution starting time. In my case, the delay is about 4 seconds. With this delay, plugins for realtime application such as autocomplete, linting and highlighting will results  poor user experience. 

    To identify this problem, we can use channel log, for example, in command line type the following command:

    :call ch_logfile(''my_ch.log")

After channel command is done, we can check time-stamps in my_ch.log: 

    x.xxxxx On 0, RECV ["call", "MyFunc"]

    y.yyyyy Call MyFunc 

y.yyyy, x.xxxxx are time-stamps

 

Solution: 

    This issue seems a buffering issue because when VIM send message to server right after receiving  channel command, the channel command will be executed immediately. I guess the VIM is simply waiting  for some events before start to to command. To solve this, update VIM to 8.2.





2021年7月31日 星期六

node.js npm指令基本用法 -1

前言:

npm (Node Package Management) 是node.js 用來管理套件(Module)安裝與環境的工具,在node.js安裝完成後·後續項目的開發皆須使用此工具來安裝需要的套件


基本用法:

1. 安裝 指定的Module (本地)

> cd <NodeProjectDir>

> npm install <ModuleName> 

Ex: 

> npm install lodash


2. 安裝 指定的Module (全域)

> npm install -g <ModuleName>

Ex: 

> npm install -g loadsh

PS: 使用-g 選項,npm會將模組安裝至系統目錄,所有的使用者皆可以使用此模組。相反的沒有-g選項則npm會將模組安裝Project目錄下的node_module目錄中。一般建議儘可能將Module安裝至Project目錄,確保Project使用的模組的相依性有被儲存到package.jason,未來在新的環境需要重新安裝所有的模組時可以避免遺漏。

3. 移除 指定的Module 

> npm uninstall <ModuleName>

> npm uninstall -g <ModuleName> 

Ex: 

> npm uninstall lodash



解決Mackbook macOS home, end, pageup, pagedown 按鍵無法使用的問題

前言:

使用一般的PC鍵盤或是藍芽鍵盤連接Macbook時經常會遇到的問題是某些功能按鍵沒有如預期般的起作用,例如常用的home, end鍵與pageup, pagedown鍵等等。

問題發生的原因:

Macbook本身並沒有這些功能性按鍵,取而代之的類似的功能都是透過快速鍵來實現,例如:
1. HOME:⌘+ ← 
2. END     : ⌘+→
換句話說的一般PC鍵盤上的功能按鍵沒有功能是很正常的。

解決方法:

解決方式有兩種·
1. 學習使用mac的快速鍵 
完整的macOs快速鍵可以到蘋果電腦的支援網站查詢:

2. 使用修改KeyMapping 的方式將功能按鍵對應到期望的功能
有興趣的人可以參考下面的文章裡面有詳細的說明:

我把文章內介紹的方法整理在下方以便未來參考:
Step1. 新增~/Library/KeyBindings 目錄
Step2: 在~/Library/KeyBindings 內建立一個文字檔案‘DefaultKeyBinding.dict’,輸入下面的內容並且存檔:

{

    "\UF729"  = moveToBeginningOfLine:; // home

    "\UF72B"  = moveToEndOfLine:; // end

    "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home

    "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end

 

Step3. 重新啟動應用程式,順利的話home/end/pageup/pagedown就可以使用囉!