Skip to content

Instantly share code, notes, and snippets.

@AllanLRH
Last active September 21, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllanLRH/600e20a40c27df81810af2fa5b00f762 to your computer and use it in GitHub Desktop.
Save AllanLRH/600e20a40c27df81810af2fa5b00f762 to your computer and use it in GitHub Desktop.
Christian Sublime Text tips

Hej Christian

Lige et par tips om Sublime Text, siden du er begyndt at bruge den mere :)

Sublime Text (ST) har en pakkemanager. Den hedder Package Control, og kan i nyeste udgave af ST installeres fra Command Palette (ctrl+shift+p) ved at vælge "Install package control". Du kan finde pakker og beskriveser på https://packgecontrol.io.

Jeg vil plejer at dele pakker op i domænespecifikke pakker, fx en linter til Python, og generelle pakker, fx noget som gør navigation i teksten nemmere. Her er de pakker som jeg er gladest for...

Pakker

Generelle pakker

  • MultiEditUtils gør multiple cursors meget mere nyttigere.
  • SelectUntil er ligeledes god med flere selections, og du kan også tage et kig på MarkAndMove nu du er i gang... den bruges dog sjældnere.
  • Origami gør det meget nemmere at benytte flere panels (buffere ved siden af hinanden)... jeg brugte det sjældent før denne pakke.
  • Expand selection to quotes virker godt sammen med ToggleQuotes, særligt i Python, hvor man både kan bruge ' ' og " " til strenge.
  • BracketGuard kan highlighte et mismatch mellem paranteser, fx ([g{f("foo"})"bar"]).
  • MoveText gør det muligt at trække rundt med tekst og hele linjer... det er meget vanedannende, frem for at copy-paste. Har brugt det en del gange til at bytte om på linjerne i denne punktopstilling.
  • MiniPy lader dig evaluere en markeret linje som pythonkode, så du fx kan lave lommeregner-matematik i din editor, eller [word.replace('param_', '') for word in ('param_a', 'param_b', 'param_c', 'param_d', 'param_e', 'param_f', 'param_g', 'param_h')] som bliver til ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'].
  • Surround lander dig skifte omkringsluttende "par-tegn", fx (), [] og "".
  • Wrapplus erstatter ST's indbygge wrap-text-at-line funtion, så den er noget mere brugbar. God til at formatere docstrings og andre lange kommentarer i kode. Ta' også et kig på CommentBanner hvis du har mange flerlinje-kommentarer.
  • AdvancedNewFile lader oprette en ny fil ved at skrive stien på den, og du slipper derved for at skulle igennem en gem-dialog.
  • HightlightWords er god til at få overblik over noget ny kode, da den tager en liste af ord (eller regular expressions), og highlighter forekomster af disse i tekstfilen med hver sin farve.
  • GitGutter markerer ændringer til den fil du arbejder på i gutteren (ved siden af linjenumrene). Virker godt sammen med Git eller GitSavvy som jeg foretrækekr i dag (det er sværere at bruge end Git).
  • InvertSelection bruges sjældent, men det hænder dog.
  • INI tilføjer support for highlighting af INI-filer, og det kan være meget rart på Windows.

Udesende

  • Boxy er en klar vinder her. Det er en samling af fornuftige Themes (UI udseende pånær tekst-området) og Color Schemes (Udseende af tekst-området) som passer samemn, og så kan det tweakes meget nemt, fordi det har en menu til at gøre dette.
  • Zenburn er et andet af mind yndlings-colorschemes.

Af skrifttype, så prøv at give Anonymus Pro (gratis, google den), Source Code Pro (også gratis, og kan også googles) som er min favorit og endelig er FreeMono (google den) heller ikke tosset. En god skrifttype gør IMHO meget.

Domænespecifikke pakker

Python

Syntaksen MagicPython er bedre en ST's indbyggede python, og pakken Anaconda er det bedste Python-IDE plugin jeg har fundet til ST, selvom det kræver en del opsætning og at man i starten skal bede det om at ignorere en del stylistisk beskeder til dig. Her er de ting jeg har bedt den ignorere gennem de sidste par år (kopier det til pakkens user-settings):

"autoformat_ignore":
[
    "E309"
],
"pep8_ignore":
[
    "E309",
    "E501",
    "E226",
    "W391",
    "E731",
    "E241",
    "E221",
    "E402",
    "W293",
    "E201",
    "E303"
    // "E128"
],
"pep257_ignore":
[
    "D203",
    "D209"
],

AutoDocstring er også den bedste docstring-assistent jeg har fundet, og at have den installeret gør det meget nemmere at få lavet en god docstring, så man kan huske hvad en funktion gør engang i fremtiden. Indstil den til at bruge Numpy-stil docstrings.

LaTeX

LaTeXTools gør det godt, og hvis du vil have endnu mere TeXisme i din editor, så kig på LaTeXYZ.

R

Der findes garanteret nogle pakker, men jeg tror ikke at du kan få noget bedre end RStudio eller Visualstudio i forhold til "Code intelligence". Der hvor ST kan være bedre, er nok navigation / generel text-trylle-magi-trickz.

Snippets

Ofte synes jeg man har mere gavn af nogle gode snippets, frem for en ekstern pakke... sørg for at lave nogle gode snippets, og få styr på placeholders, så du fx kan indsætte markeret tekst i dem, og hoppe fra felt til felt.

Keyboard

Sørg for at gøre ST til "din egen" ved at lave nogle keyboard shortcuts som passer til dig, fx ved at tage æøå i brug, da de ikke er optage i forvejen. Der er en del af ST's standard-genveje som er utilgængelige eller meget besværlige på et dansk tastatur, men nogle er meget brugte, fx find_under_expand og find_under_expand_skip. Her er min keyboard-settings fil (til Mac, mest udviklet) og Windows:

[
    {
        "keys": ["alt+d"],
        "command": "selection_fields"
    },
    {
        "keys": ["alt+a"],
        "command": "selection_fields",
        "args": {"mode": "add"}
    },
    {
        "keys": ["ctrl+alt+shift+d"],
        "command": "selection_fields",
        "args": {
                    "mode": "toggle",
                    "only_other": true
                }
    },
    {
        "keys": ["ctrl+alt+d"],
        "command": "selection_fields",
        "args": {
                    "mode": "smart",
                    "only_other": true
                }
    },
    {   "keys": ["super+f"],
        "command": "show_panel",
        "args":
            {
            "panel": "find",
            "regex": true,
            "case_sensitive": false,
            "whole_word": false,
            "in_selection": false,
            "wrap": true,
            "highlight_matches": true,
            "reverse": false
          }
    },
    {
        "keys": ["alt+å"],
        "command": "toggle_comment",
        "args": { "block": false }
    },
    {
        "keys": ["alt+shift+å"],
        "command": "toggle_comment",
        "args": { "block": true }
    },
    {
        "keys": ["super+k", "super+t"],
        "command": "title_case"
    },
    {
        "keys": ["alt+ø"],
        "command": "indent"
    },
    {
        "keys": ["alt+æ"],
        "command": "unindent"
    },
    {
        "keys": ["super+æ"],
        "command": "find_under_expand"
    },
    {
        "keys": ["super+ø"],
        "command": "find_under_expand_skip"
    },
    {
        "keys": ["alt+shift+n"],
        "command": "normalize_region_ends"
    },
    {
        "keys": ["j", "j"],
        "command": "_enter_normal_mode",
        "args": {
            "mode": "mode_insert"
        },
        "context": [{"key": "vi_insert_mode_aware"}]
    },
    {
        "keys": ["alt+1"],
        "command": "insert_snippet",
        "args": {"contents": "$1($SELECTION)$0"}
    },
    {
        "keys": ["alt+2"],
        "command": "insert_snippet",
        "args": {"contents": "$1[$SELECTION]$0"}
    },
    {
        "keys": ["alt+3"],
        "command": "insert_snippet",
        "args": {"contents": "$1{$SELECTION}$0"}
    },
    {
        "keys": ["ctrl+k"],
        "command": "run_macro_file",
        "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"}
    },
    {
        "keys": ["super+enter"],
        "command": "run_macro_file",
        "args": {"file": "Packages/Default/Add Line.sublime-macro"},
        "context": [
            {"operator": "not_equal", "operand": "git-savvy.make-commit", "key": "selector"},
            {"operator": "not_equal", "operand": "git-savvy.diff", "key": "selector"},
        ]
    },
    {
        "keys": ["super+ctrl+a"],
        "command": "align_tab",
        "args" : {"user_input" : "(?:=|\\+=|-=|\\*=|/=|&=|//=|%=|:)/f1"}
    },
    {
        "keys": ["ctrl+y"],
        "command": "show_overlay",
        "args": {"overlay": "command_palette", "text": "Snippet: "}
    },
    {
        "keys": ["super+k", "super+n"],
        "command": "advanced_new_file_new"
    },
    {
        "keys": ["super+k", "super+s"],
        "command": "surround_change"
    },
    {
        "keys": ["super+k", "super+d"],
        "command": "surround_delete"
    },
    {
        "keys": ["super+ctrl+down"],
        "command": "move_text_down"
    },
    {
        "keys": ["super+ctrl+left"],
        "command": "move_text_left"
    },
    {
        "keys": ["super+ctrl+right"],
        "command": "move_text_right"
    },
    {
        "keys": ["super+ctrl+up"],
        "command": "move_text_up"
    },
    {
        "keys": ["alt+m"],
        "command": "mark_and_move_do_it_all"
    },
    {
        "keys": ["alt+n"],
        "command": "mark_and_move_next"
    },
    {
        "keys": ["alt+p"],
        "command": "mark_and_move_prev"
    },
    {
        "keys": ["alt+r"],
        "command": "mark_and_move_recall"
    },
    {
        "keys": ["alt+c"],
        "command": "mark_and_move_clear"
    },
    {
        "keys": ["super+k", "super+m"],
        "command": "set_mark"
    },
    {
        "keys": ["ctrl+t"],
        "command": "transpose_character"
    },
    {
        "keys": ["ctrl+shift+t"],
        "command": "transpose_character",
        "args": {"reverse": true}
    },
    {
        "keys": ["ctrl+d"],
        "command": "duplicate_line"
    },
    {
        "keys": ["super+k", "super+c"],
        "command": "pastebin"
    },
    {
        "keys": ["super+shift+q"],
        "command": "expand_selection_to_quotes"
    },
    {
        "keys": ["ctrl+alt+w"],
        "command": "ace_jump_word"
    },
    {
        "keys": ["super+shift+c"],
        "command": "ace_jump_char"
    },
    {
        "keys": ["ctrl+alt+l"],
        "command": "ace_jump_line"
    },
    {
        "keys": ["ctrl+alt+s"],
        "command": "ace_jump_select"
    },
    {
        "keys": ["ctrl+alt+a"],
        "command": "ace_jump_add_cursor"
    },
    {
        "keys": ["super+k", "super+g"],
        "command": "gs_show_status"
    },
    {
        "keys": ["ctrl+shift+s"],
        "command": "select_until",
        "args": { "extend": true }
    },
    {
        "keys": ["super+l", "f"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/latex/putBackslashInFrontOfWord.sublime-macro"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": true, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.tex.latex", "key": "selector"}
        ]
    },
    {
        "keys": ["ctrl+å"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/Macros/DuplicateLineAndCommentOutOriginal.sublime-macro"}
    },
    {
        "keys": ["ctrl+alt+super+å"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/Macros/linesToStringCommaSeperation.sublime-macro"}
    },
    {
        "keys": ["*"],
        "command": "insert_snippet",
        "args": {"contents": "*${0:$SELECTION}*"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.html.markdown", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["_"],
        "command": "insert_snippet",
        "args": {"contents": "_${0:$SELECTION}_"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.html.markdown", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["|"],
        "command": "insert_snippet", "args": {"contents": "|${0:$SELECTION}|"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.tex.latex", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["¿"],
        "command": "insert_snippet",
        "args": {"contents": "`${0:$SELECTION}`"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.html.markdown", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["super+shift+space"],
        "command": "expand_region"
    },
    {
        "keys": ["super+u"],
        "command": "expand_region",
        "args": {"undo": true},
        "context": [
            { "key": "expand_region_soft_undo" }
        ]
    }
]

Windows:

[
    {   "keys": ["ctrl+f"],
        "command": "show_panel",
        "args":
            {
            "panel": "find",
            "regex": true,
            "case_sensitive": false,
            "whole_word": false,
            "in_selection": false,
            "wrap": true,
            "highlight_matches": true,
            "reverse": false
          }
    },
    {
        "keys": ["alt+å"],
        "command": "toggle_comment",
        "args": { "block": false }
    },
    {
        "keys": ["alt+shift+å"],
        "command": "toggle_comment",
        "args": { "block": true }
    },
    {
        "keys": ["ctrl+k", "ctrl+t"],
        "command": "title_case"
    },
    {
        "keys": ["alt+ø"],
        "command": "indent"
    },
    {
        "keys": ["alt+æ"],
        "command": "unindent"
    },
        {
        "keys": ["ctrl+æ"],
        "command": "find_under_expand"
    },
    {
        "keys": ["ctrl+ø"],
        "command": "find_under_expand_skip"
    },
        {
        "keys": ["alt+1"],
        "command": "insert_snippet",
        "args": {"contents": "$1($SELECTION)$0"}
    },
    {
        "keys": ["alt+2"],
        "command": "insert_snippet",
        "args": {"contents": "$1[$SELECTION]$0"}
    },
    {
        "keys": ["alt+3"],
        "command": "insert_snippet",
        "args": {"contents": "$1{$SELECTION}$0"}
    },
    {
        "keys": ["ctrl+1"],
        "command": "select_by_index",
        "args": { "index": 0 }
    },
    {
        "keys": ["ctrl+2"],
        "command": "select_by_index",
        "args": { "index": 1 }
    },
    {
        "keys": ["ctrl+3"],
        "command": "select_by_index",
        "args": { "index": 2 }
    },
    {
        "keys": ["ctrl+4"],
        "command": "select_by_index",
        "args": { "index": 3 }
    },
    {
        "keys": ["ctrl+5"],
        "command": "select_by_index",
        "args": { "index": 4 }
    },
    {
        "keys": ["ctrl+6"],
        "command": "select_by_index",
        "args": { "index": 5 }
    },
    {
        "keys": ["ctrl+7"],
        "command": "select_by_index",
        "args": { "index": 6 }
    },
    {
        "keys": ["ctrl+8"],
        "command": "select_by_index",
        "args": { "index": 7 }
    },
    {
        "keys": ["ctrl+9"],
        "command": "select_by_index",
        "args": { "index": 8 }
    },
    {
        "keys": ["ctrl+0"],
        "command": "select_by_index",
        "args": { "index": 9 }
    },
    {
        "keys": ["alt+k"],
        "command": "run_macro_file",
        "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"}
    },
    {
        "keys": ["ctrl+enter"],
        "command": "run_macro_file",
        "args": {"file": "Packages/Default/Add Line.sublime-macro"},
        "context": [
            {"operator": "not_equal", "operand": "git-savvy.make-commit", "key": "selector"},
            {"operator": "not_equal", "operand": "git-savvy.diff", "key": "selector"},
        ]
    },
    {
        "keys": ["ctrl+alt+a"],
        "command": "align_tab",
        "args" : {"user_input" : "(?:=|\\+=|-=|\\*=|/=|&=|//=|%=|:)/f1"}
    },
    {
        "keys": ["ctrl+y"],
        "command": "show_overlay",
        "args": {"overlay": "command_palette", "text": "Snippet: "}
    },
    {
        "keys": ["ctrl+k", "ctrl+n"],
        "command": "advanced_new_file_new"
    },
    {
        "keys": ["alt+s"],
        "command": "surround_change"
    },
    {
        "keys": ["alt+d"],
        "command": "surround_delete"
    },
    {
        "keys": ["alt+ctrl+down"],
        "command": "move_text_down"
    },
    {
        "keys": ["alt+ctrl+left"],
        "command": "move_text_left"
    },
    {
        "keys": ["alt+ctrl+right"],
        "command": "move_text_right"
    },
    {
        "keys": ["alt+ctrl+up"],
        "command": "move_text_up"
    },
    {
        "keys": ["alt+m"],
        "command": "mark_and_move_do_it_all"
    },
    {
        "keys": ["alt+n"],
        "command": "mark_and_move_next"
    },
    {
        "keys": ["alt+p"],
        "command": "mark_and_move_prev"
    },
    {
        "keys": ["alt+r"],
        "command": "mark_and_move_recall"
    },
    {
        "keys": ["alt+c"],
        "command": "mark_and_move_clear"
    },
    {
        "keys": ["super+k", "super+m"],
        "command": "set_mark"
    },
    {
        "keys": ["alt+d"],
        "command": "duplicate_line"
    },
        {
        "keys": ["alt+shift+q"],
        "command": "expand_selection_to_quotes"
    },
    {
        "keys": ["super+k", "super+s"],
        "command": "gs_show_status"
    },
    {
        "keys": ["ctrl+shift+s"],
        "command": "select_until",
        "args": { "extend": true }
    },
    {
        "keys": ["ctrl+l", "f"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/latex/putBackslashInFrontOfWord.sublime-macro"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": true, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.tex.latex", "key": "selector"}
        ]
    },    {
        "keys": ["ctrl+å"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/Macros/DuplicateLineAndCommentOutOriginal.sublime-macro"}
    },
    {
        "keys": ["ctrl+alt+å"],
        "command": "run_macro_file",
        "args": {"file": "Packages/User/Macros/linesToStringCommaSeperation.sublime-macro"}
    },
    {
        "keys": ["*"],
        "command": "insert_snippet",
        "args": {"contents": "*${0:$SELECTION}*"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.html.markdown", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["_"],
        "command": "insert_snippet",
        "args": {"contents": "_${0:$SELECTION}_"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.html.markdown", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["|"],
        "command": "insert_snippet", "args": {"contents": "|${0:$SELECTION}|"},
        "context": [
            {"match_all": true, "operator": "equal", "operand": false, "key": "selection_empty"},
            {"operator": "equal", "operand": "text.tex.latex", "key": "selector"},
            {"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}
        ]
    },
    {
        "keys": ["alt+u"],
        "command": "expand_region",
        "args": {"undo": true},
        "context": [
            { "key": "expand_region_soft_undo" }
        ]
    }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment