sublime使用總結


上周忙呀忙~    周一到五在忙項目,周六日搬家    在帝都平均一年就要換一次房子,從開始找房子到成功住進去前前后后大約花了半個多月的時間    什么時候就有自己的小窩了……

之前開發一直用的都是WebStorm,用了一段時間后發現很卡頓,內存占用很大,故而准備選擇輕量級的Sublime。

以下是使用過程中的一些總結,持續更新~

1、安裝Sublime Text3,傻瓜式安裝,這里就不多說了~

2、安裝Package Control(一個用來管理插件的插件)

  ctrl + `打開控制台;將以下代碼粘貼到控制台

import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

  等待安裝完成,ctrl + shift + p 打開命令板,輸入PC出現  選擇即可安裝sublime text 的各種插件

   -----------------------------------------------------------------------------------------------------------------------------

  出現問題:Package Control:There are no packages available for installation

  解決方法:① 網上查資料說是IPV6的問題, 打開win+R  cmd命令提示符中輸入ping sublime.wbond.net  得到IP,在C:\Windows\system32\drivers\etc\hosts文件,增加如下對應關系:{IPv4 address}sublime.wbond.Net

         ② 另一種說法是install package那個安裝代碼太舊,在官網上找到新的重新安裝

         ③上述兩種方法都沒能解決我的問題,故在官網重新下載了安裝文件(之前的是在網頁上搜出的百度軟件中心下載的漢化版),重新安裝,成功!

  -------------------------------------------------------------------------------------------------------------------------------

3、js校驗插件

  ① 確保安裝了nodeJs ;命令行進入npm目錄,輸入’npm install -g jshint’ 

  ② 插件安裝輸入JSHint Gutter

  ③ package settings > JSHint Gutter > Set Plugin Options > 設置NodeJS執行文件所在的路徑(node_path),並將lint_on_save(文件保存時檢查)選項打開

  ④ package settings > JSHint Gutter > set Linting Preferences  打開.jshintrc文件

  定制自己的校驗規則:

  參考:’http://jshint.com/docs/options/’ 

//
// 強制選項
//
    // When set to true, these options will make JSHint produce more warnings about your code.

    /**
     * 是否阻止位運算符的使用
     *
     * 有時候為了快速取整或判斷,會使用一些位運算符,所以此項設置為 false
     */
    "bitwise": false,
    /**
     * 是否要求變量都使用駝峰命名
     *
     * 默認開啟
     * 棄用,見jscs項目
     */
    "camelcase": false,
    /**
     * 是否要求 for/while/if 等循環和條件語句中總是使用花括號
     *
     *
     */
    "curly": false,
    /**
     * 是否強制使用嚴格等號
     *
     * 有時候需要判斷 null,所以默認不嚴格要求
     */
    "eqeqeq": false,
    /**
     * true: 默認要求所有函數運行在ES5
     * 棄用
     */
    "es3": true,
    "es5": true,
    "esnext": true,
    /**
     * 選擇ES版本,3,5,6
     */
    "esversion": 5,
    /**
     * for-in 語句是否要求過濾原型鏈上的對象
     *
     * 默認打開
     */
    "forin": true, /**
     * 是否阻止修改或拓展基本對象(Array、Date 等)的原型鏈
     *
     * 原型鏈污染比較危險,默認打開
     */
    "freeze": true,
    /**
     * 變量只能在函數域上定義,在代碼塊上定義的變量給出警告
     */
    "funcscope": true,
    /**
     * 當使用JS保留字時,顯示警告
     */
    "futurehostile": true,
    /**
    *這個選項可以用來指定一個沒有正式定義的全局變量的白名單。配置 globals在單個文件,看看內聯配置.
    */
    "globals": {
        "define": false,
        "module": true,
        "export": true,
        "console": false
    },
    /**
     * 是否要求自執行的方法使用括號括起  (function () { } ());
     * 默認打開
     * 棄用,見jscs項目
     */
    "immed": true,
    /**
     * 指定tab縮進寬度為 2 個空格
     *
     * 棄用,見jscs項目
     */
    "indent": 2,
    /**
     * 要求變量在使用前聲明,
     */
    "latedef": true,
    /**
     * 代碼塊嵌套深度
     */
    "maxdepth": 2,
    /**
     * 最大錯誤提示數量,默認50
     */
    "maxerr": 50,
/**
     * 單行最大長度
     *
     * 棄用,見jscs項目
     */
    "maxlen": 50,
    /**
     * 設置函數正式參數的最大數量
     *
     */
    "maxparams": 4,
    /**
     * 一個函數內聲明語句的最大數量
     *
     */
    "maxstatements": 4,
    /**
     * 要求構造函數大寫
     *
     * 棄用,見jscs項目
     */
    "newcap": true,
    /**
     * 不允許使用 arguments.callee 和 arguments.caller
     */
    "noarg": true,
    /**
     * 不允許使用逗號
     */
    "nocomma": true,
    /**
     * 不允許空的代碼快,默認關閉
     *
     * 棄用,見jscs項目
     */
    "noempty": false,
    /**
     * 不允許使用 "non-breaking whitespace"。
     *
     * 這些字符在非 UTF8 頁面會導致代碼失效
     */
    "nonbsp": true,
    /**
     * 阻止直接使用 new 調用構造函數的語句(不賦值對象)
     *
     * // OK
     * var a = new Animal();
     *
     * // Warn
     * new Animal();
     */
    "nonew": true,
/**
     * 阻止直接使用 typeof 操作符
     *
     * 慎用
     */
    "notypeof": true,
    /**
    * 字符串引號
    *
    * 默認要求使用單引號
    true-- 代碼字符串禁止單引號雙引號混用,
    "single"--只允許單引號
    "double"--只允許雙引號。
    * 棄用,見jscs項目
    */
    "quotmark": "single",
    /**
    * 隱藏式聲明
    *
    "inner" - check for variables defined in the same scope only
    "outer" - check for variables defined in outer scopes as well
    false - same as inner
    true - allow variable shadowing
    */
    "shadow": "inner",
    /**
     *  禁止在不必要的時候使用分組運算符
     */
    "singleGroups": true,
    /**
     * 是要求否以 strict 模式檢查
     *
     * 該選項要求文件有 "use strict;"不全局要求,需要的模塊自行開啟
     */
    "strict": false,
    /**
     * 提示未定義的變量
     *
     * 未定義的變量會容易造成全局變量,該項開啟
     */
    "undef": true,
    /**
     * 提示未使用的變量
     * vars - to only check for variables, not function parameters
     * strict - to check all variables and parameters.
     * 默認開啟
     */
    "unused": true,
    /**
     * 是否禁止使用var
     * Use `let` or `const` instead.
     */
    "varstmt": true,
//
//Relaxing options
//
    //When set to true, these options will make JSHint produce fewer warnings about your code.

    /**
     * 不顯示缺少分號警告
     */
    "asi": true,
    /**
     *  不顯示在 比較處使用了賦值 的警告信息。
     */
    "boss": true,
    /**
     * 不顯示代碼中使用的 debugger 語句默認給出的警告
     */
    "debug": true,
    /**
     * This option tells JSHint that your code uses ES3 array elision elements, or empty elements (for example, [1, , , 4, , , 7]).
     */
    "elision": true,
    /**
     * 不顯示關於 == null的警告
     * 當您想要檢查變量是否為空或未定義時,這種比較往往很有用。
     */
    "eqnull": true,
    /**
     * 不顯示關於 eval 的警告
     *
     */
    "evil": true,
    /**
     * 不顯示 在應該使用復制或函數調用的地方使用了表達式 的警告。
     */
    "expr": true,
    /**
     * 不顯示缺少分號的警告
     */
    "lastsemic": true,
 /**
     * 不顯示不安全的折行的警告
     *
     * 棄用,見jscs項目
     */
    "laxbreak": true,
    /**
     * 不顯示逗號放前面的警告,例如:
     *
     * 棄用,見jscs項目
     */
    "laxcomma": true,
    /**
     * 不顯示 在循環語句中定義函數 的警告
     */
    "loopfunc": true,
    /**
     * 不顯示 多行字符串 的警告
     */
    "multistr": true,
    /**
     * 不允許使用 ++ 和 -- 運算符
     *
     * 默認關閉
     */
    "plusplus": false,
    /**
     * 禁止關於__proto__屬性的警告
     */
    "proto": true,
    /**
     *  true: Prohibit use of empty blocks
     *  該選項控制形如 person['name'] vs. person.name的警告信息的顯示
     *  棄用,見jscs項目
     */
    "sub": true,
//
// Environments
//
    // These options let JSHint know about some pre-defined global variables.
    /**
     * 暴露瀏覽器屬性的全局變量,列如 window,document;
    注意:這個選項不暴露變量 alert或 console。
     */
    "browser": true,
    /**
     * 這個選項定義全局暴露的jQuery庫。
     */
    "jquery": true

  常見的提示錯誤:

“Missing semicolon.” : “缺少分號.”,  
“Use the function form of \”use strict\”.” : “使用標准化定義function.”,  
“Unexpected space after ‘-’.” : “在’-'后面不應出現空格.”,  
“Expected a JSON value.” : “請傳入一個json的值.”,  
“Mixed spaces and tabs.”: “空格和TAB重復.”,  
“Unsafe character.” : “不安全的字符.”,  
“Line too long.”: “本行中的字符超過設定的最大長度.”,  
“Trailing whitespace.”: “本行末尾有過多無用空格.”,  
“Script URL.” : “腳本URL.”,  
“Unexpected {a} in ‘{b}’.” : “在 ‘{b}’ 中不該出現 {a}.”,  
“Unexpected ‘{a}’.” : “不該在此出現’{a}’.”,  
“Strings must use doublequote.” : “字符串需要用雙引號”,  
“Unnecessary escapement.” : “不需要轉義”,  
“Control character in string: {a}.” : “在字符串中出現了Control的字符”,  
“Avoid \\’.” : “避免 \\”,  
“Avoid \\v.” : “避免 \\v”,  
“Avoid \\x-.” : “避免 \\x-”,  
“Bad escapement.” : “錯誤的轉義字符”,  
“Bad number ‘{a}’.” : “錯誤的數字 ‘{a}’”,  
“Missing space after ‘{a}’.” : “在’{a}’之后缺少空格”,  
“Don’t use extra leading zeros ‘{a}’.” : “不要再’{a}’的前面用多余的0″,  
“Avoid 0x-. ‘{a}’.” : “避免使用 0x-. ‘{a}’.”,  
“A trailing decimal point can be confused with a dot ‘{a}’.” : “在’{a}’中使用點尾隨小數點”,  
“Unexpected comment.” : “不該在此處出現注釋”,  
“Unescaped ‘{a}’.” : “沒有轉義 ‘{a}’”,  
“Unexpected control character in regular expression.” : “在正則表達式中出現了control字符”,  
“Unexpected escaped character ‘{a}’ in regular expression.” : “在正則表達式中出現了沒有轉義的字符 ‘{a}’”,  
“Expected ‘{a}’ and instead saw ‘{b}’.” : “應該用 ‘{a}’代替’{b}’”,  
“Spaces are hard to count. Use {{a}}.” : “空格難以統計,請使用 {{a}}”,  
“Insecure ‘{a}’.” : “不安全的 ‘{a}’”,  
“Empty class.” : “空的class”,  
“Expected a number and instead saw ‘{a}’.”:“應該用數字代替’{a}’”,  
“‘{a}’ should not be greater than ‘{b}’.”:“‘{a}’不應該比’{b}’大”,  
“‘hasOwnProperty’ is a really bad name.”: “‘hasOwnProperty’是關鍵字”,  
“‘{a}’ was used before it was defined.”:“‘{a}’未定義就已經使用了.”,  
“‘{a}’ is already defined.”:“‘{a}’被重復定義”,  
“A dot following a number can be confused with a decimal point.”:“數字后面的一個點會被誤認為是十進制的小數點”,  
“Confusing minusses” : “容易混淆的負數表達-”,  
“Confusing plusses.” : “容易混淆的正數表達+”,  
“Unmatched ‘{a}’.” : “無法匹配的’{a}’”,  
“Expected ‘{a}’ to match ‘{b}’ from line {c} and instead saw ‘{d}’.”:“在行{c}中需要用’{a}’和’{b}’匹配,用來代替’{d}’”,  
“Unexpected early end of program.”:“程序不可預期的提前終止”,  
“A leading decimal point can be confused with a dot: ‘.{a}’.”:“‘{a}’前的點容易混淆成小數點”,  
“Use the array literal notation [].”:“使用數組的符號 []“,  
“Expected an operator and instead saw ‘{a}’.”:“需要用一個符號來代替’{a}’”,  
“Unexpected space after ‘{a}’.”:“在’{a}’之后不能出現空格”,  
“Unexpected space before ‘{a}’.”:“在’{a}’之前不能出現空格”,  
“Bad line breaking before ‘{a}’.”:“在’{a}’之前錯誤的換行”,  
“Expected ‘{a}’ to have an indentation at {b} instead at {c}.”:“‘{a}’需要在{c}而不是{b}處縮進”,  
“Line breaking error ‘{a}’.”:“換行錯誤 ‘{a}’”,  
“Unexpected use of ‘{a}’.”:“此處不能用’{a}’”,  
“Bad operand.”:“錯誤的操作數”,  
“Use the isNaN function to compare with NaN.”:“使用isNaN來與NaN比較”,  
“Confusing use of ‘{a}’.”:“容易混淆的’{a}’的使用”,  
“Read only.”:“只讀的屬性”,  
“‘{a}’ is a function.”:“‘{a}’是一個函數”,  
‘Bad assignment.’:“錯誤的賦值”,  
“Do not assign to the exception parameter.”:“不要給額外的參數賦值”,  
“Expected an identifier in an assignment and instead saw a function invocation.”:“在賦值的語句中需要有一個標識符,而不是一個方法的調用”,  
“Expected an identifier and instead saw ‘{a}’ (a reserved word).”:“需要有一個標識符,而不是’{a}’(保留字符)”,  
“Missing name in function declaration.”:“在方法聲明中缺少名稱”,  
“Expected an identifier and instead saw ‘{a}’.”:“需要有一個標識符,而不是’{a}’”,  
“Inner functions should be listed at the top of the outer function.”:“內部函數的聲明應該放在此函數的頂部。”,  
“Unreachable ‘{a}’ after ‘{b}’.”:“在’{b}’之后無法獲取’{a}’”,  
“Unnecessary semicolon.”:“不必要的分號”,  
“Label ‘{a}’ on {b} statement.”:“將’{a}’放在{b}的聲明中”,  
“Label ‘{a}’ looks like a javascript url.”:“‘{a}’看上去像一個js的鏈接”,  
“Expected an assignment or function call and instead saw an expression”:“需要一個賦值或者一個函數調用,而不是一個表達式.”,  
“Do not use ‘new’ for side effects.”:“不要用’new’語句.”,  
“Unnecessary \”use strict\”.”:“不必要的\”use strict\”.”,  
“Missing \”use strict\” statement.”:“缺少\”use strict\”的聲明”,  
“Empty block.”:“空的模塊”,  
“Unexpected /*member ‘{a}’.”:“不應出現 /*元素 ‘{a}’.”,  
“‘{a}’ is a statement label.”:“‘{a}’是一個聲明”,  
“‘{a}’ used out of scope.”:“‘{a}’使用超出范圍”,  
“‘{a}’ is not allowed.”:“不允許使用’{a}’”,  
“‘{a}’ is not defined.”:“‘{a}’沒有被定義”,  
“Use ‘{a}’ to compare with ‘{b}’.”:“使用’{a}’與’{b}’相比”,  
“Variables should not be deleted.”:“變量需要被刪除”,  
“Use the object literal notation {}.”:“使用對象的文字符號 {}”,  
“Do not use {a} as a constructor.”:“不要使用{a}作為一個構造對象”,  
“The Function constructor is eval.”:“The Function constructor is eval.”,  
“A constructor name should start with an uppercase letter.”:“一個構造對象的名稱必須用大寫字母開頭.”,  
“Bad constructor.”:“錯誤的構造對象”,  
“Weird construction. Delete ‘new’.”:“構造對象有誤,請刪除’new’”,  
“Missing ‘()’ invoking a constructor.”:“缺少括號()”,  
“Avoid arguments.{a}.”:“避免參數.{a}.”,  
“document.write can be a form of eval.”:“document.write是eval的一種形式”,  
‘eval is evil.’:“盡量不要使用eval”,  
“Math is not a function.”:“Math不是一個函數”,  
“Missing ‘new’ prefix when invoking a constructor.”:“此處缺少了’new’”,  
“Missing radix parameter.”:“缺少參數”,  
“Implied eval is evil. Pass a function instead of a string.”:“傳遞一個函數,而不是一個字符串”,  
“Bad invocation.”:“錯誤的調用”,  
“['{a}'] is better written in dot notation.”:“['{a}']最好用點.的方式”,  
“Extra comma.”:“多余的逗號”,  
“Don’t make functions within a loop.”:“不要用循環的方式創建函數”,  
“Unexpected parameter ‘{a}’ in get {b} function.”:“在{b}方法中不該用到參數’{a}’”,  
“Duplicate member ‘{a}’.”:“重復的’{a}’”,  
“Expected to see a statement and instead saw a block.”:“此處應該是語句聲明.”,  
“Too many var statements.”:“過多var的聲明”,  
“Redefinition of ‘{a}’.”:“‘{a}’被重復定義”,  
“It is not necessary to initialize ‘{a}’ to ‘undefined’.”:“無需將’{a}’初始化為’undefined’”,  
“Expected a conditional expression and instead saw an assignment.”:“此處需要一個表達式,而不是賦值語句”,  
“Expected a ‘break’ statement before ‘case’.”:“在’case’之前需要有’break’.”,  
“Expected a ‘break’ statement before ‘default’.”:“在’default’之前需要有’break’.”,  
“This ‘switch’ should be an ‘if’.”:“此處’switch’應該是’if’.”,  
“All ‘debugger’ statements should be removed.”:“請刪除’debugger’的語句”,  
“‘{a}’ is not a statement label.”:“‘{a}’不是一個聲明標簽.”,  
“Expected an assignment or function call and instead saw an expression.”:“需要一個語句或者一個函數調用,而不是一個表達式”,  
“Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function.”:
“函數的聲明不能放在類似if的塊中,需要放在外部函數的頂部.” “Use '===' to compare with ...”:“這個錯誤是說,我們要是用全等來代替等於,如果表達式兩邊的數據類型是一致的話,建議使用全等來判斷”

 

4、快捷鍵

 
         
------------  基本編輯  -------------

  ctrl + `    //打開控制台

  ctrl + p   //通過文件名搜索

  ctrl + shift + p //
調出命令板(Command Palette)
  ctrl +  ←/→  //進行逐詞移動         ctrl + shift + ←/→  //進行逐詞選擇  

  ctrl + ↑/↓  //移動當前顯示區域   Ctrl + Shift + ↑/↓  //移動當前行

  ctrl + [ //向左縮進
ctrl + ] //向右縮進

  ctrl + shift + V //可以以當前縮進粘貼代碼
   ------------  選擇 -------------

  ctrl + D   //選擇當前光標所在的詞並高亮該詞所有出現的位置,再次Ctrl + D選擇該詞出現的下一個位置,在多重選詞的過程中,使用Ctrl + K進行跳過,使用Ctrl + U進行回退,使用Esc退出多重編輯。

  ctrl + shift + L     //將當前選中區域打散,然后進行同時編輯      

  ctrl + J     //把當前選中區域合並為一行
  ctrl + M     //在起始括號和結尾括號之間切換

  ctrl + shift + M //快速選擇括號間的內容

  ctrl + shift + J //快速選擇同縮進的內容
  ctrl + shift + J   //快速選擇當前作用域(Scope)的內容
  ------------ 查找&替換 -------------

  F3 //跳至當前關鍵字下一個位置

  shift + F3 //跳到當前關鍵字上一個位置

  Alt + F3 //選中當前關鍵字出現的所有位置

  ctrl + F/H //進行標准查找/替換

  ctrl + shift + F //進行標准查找/替換
  ------------ 跳轉 -------------

  ctrl + P //跳轉到指定文件,輸入文件名后可以:

    @ 符號跳轉:輸入@symbol跳轉到symbol符號所在的位置

    # 關鍵字跳轉:輸入#keyword跳轉到keyword所在的位置

    :
 行號跳轉:輸入:12跳轉到文件的第12行

  ctrl + R  //跳轉到指定符號
  ctrl + G  //跳轉到指定行號
  ------------ 窗口 -------------

  ctrl + shift + N //創建一個新窗口
  ctrl  + N   //在當前窗口創建一個新標簽
  ctrl + W   //關閉當前標簽,當窗口內沒有標簽時會關閉該窗口
  ctrl + shift + T   //恢復剛剛關閉的標簽
  ------------ 屏幕 -------------
  
  F11 //切換普通全屏

  shift + F11 //切換無干擾全屏

  Alt + shift + 2 //進行左右分屏
  Alt + shift + 8   //進行上下分屏
  Alt + shift + 5   //進行上下左右分屏
  Alt + shift + 1   //取消分屏

   分屏之后,使用Ctrl + 數字鍵跳轉到指定屏,使用Ctrl + Shift + 數字鍵將當前屏移動到指定屏

 

 
        

5、定制個性化主題

  // 使光標閃動更加柔和 "caret_style": "phase",

  // 高亮當前行 "highlight_line": true,

  // 高亮有修改的標簽 "highlight_modified_tabs": true,

  // 設置tab的大小為2 "tab_size": 2,

  // 使用空格代替tab "translate_tabs_to_spaces": true,

  // 添加行寬標尺 "rulers": [80, 100],

  // 顯示空白字符 "draw_white_space": "all",

  // 保存時自動去除行末空白 "trim_trailing_white_space_on_save": true,

  // 保存時自動增加文件末尾換行 "ensure_newline_at_eof_on_save": true,

 6、常用功能

  定位該文件在文件夾中的位置:  在代碼區域右擊 > Reveal in Side Bar

  按Tab自動補全

7、后續補充

  全局搜索:ctrl + shift + F

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM