# Associate a file type with a specific syntax highlighting in the text editor

**URL:** <https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965>\
**Category:** JupyterLab\
**Created:** [May 3, 2019, 6:25pm UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965 "2019-05-03T18:25:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matrs](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/matrs/32/546_2.png) [@matrs](https://discourse.jupyter.org/u/matrs)\
**Post date:** [May 3, 2019, 6:25pm UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965/1 "2019-05-03T18:25:17Z")

</div>

Hello,  
I’ve been running `jupyter-lab` in a cluster and using it in my local computer (ssh tunneling) and that’s been working great. My problem is that I’m editing a lot of `snakemake` files (workflow manager written in python), usually with a `.smk` file extension and every time I open a file, I have to go to the `menu`:  
`view --> text editor syntax highlighting --> python`. I saw in the `Advanced settings editor` that you can create shortcuts, so I tried to create a shortcut to highlight these files using the python syntax, but there aren’t examples relevant to my case in the already created shortcuts and I failed to do it. Also, i don’t know if it’s possible to associate a x file extension with a specific language, so you can open it and have a “proper” syntax highlighting, which would be even better than a shortcut.

I’m running `jupyter-lab 0.35.4`

Cheers

---

<div class="post-metadata">

**Author:** ![ian-r-rose](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ian-r-rose/32/1119_2.png) [@ian-r-rose](https://discourse.jupyter.org/u/ian-r-rose)\
**Post date:** [May 16, 2019, 4:02am UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965/2 "2019-05-16T04:02:16Z")

</div>

Hi @matrs, you should be able to do this with the following keyboard shortcut in the advanced setting editor:

```json
{
       "shortcuts": [
        {
            "command": "codemirror:change-mode",
            "keys": ["Accel P"],
            "args": { "name": "Python" },
            "selector": ".jp-FileEditor"
        }
    ]

}

```

---

<div class="post-metadata">

**Author:** ![matrs](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/matrs/32/546_2.png) [@matrs](https://discourse.jupyter.org/u/matrs)\
**Post date:** [May 18, 2019, 5:02am UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965/3 "2019-05-18T05:02:40Z")

</div>

Hey, thanks. I tried but isn’t working, I tried different `"keys"` like `Ctrl Y` because `Ctrl p` or P are shortcuts for printing in the browser. Checking the existent shortcuts, all look like this

```auto
"application:activate-previous-tab": {
      "command": "application:activate-previous-tab",
      "keys": [
        "Ctrl Shift ["
      ],
      "selector": "body",
      "title": "Activate Previous Tab",
      "category": "Main Area"
    },

```

so aren’t those keys, `title`, `category`, mandatory?

---

<div class="post-metadata">

**Author:** ![ian-r-rose](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/ian-r-rose/32/1119_2.png) [@ian-r-rose](https://discourse.jupyter.org/u/ian-r-rose)\
**Post date:** [May 18, 2019, 5:56am UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965/4 "2019-05-18T05:56:18Z")

</div>

Ah, the format changed between 0.35 and the current 1.0 prerelease (which is where I tested mine). Nevertheless, I think the same command ID, args, and selector should work.

---

<div class="post-metadata">

**Author:** ![eczech](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/eczech/32/2859_2.png) [@eczech](https://discourse.jupyter.org/u/eczech)\
**Post date:** [October 9, 2020, 1:31pm UTC](https://discourse.jupyter.org/t/associate-a-file-type-with-a-specific-syntax-highlighting-in-the-text-editor/965/5 "2020-10-09T13:31:13Z")

</div>

That suggestion from @ian-r-rose still works for me (as of jupyter lab 2.2.2):

```auto
{
    "shortcuts": [
        {
            "command": "codemirror:change-mode",
            "keys": [
                "Shift Ctrl Alt P"
            ],
            "args": { "name": "Python" },
            "selector": ".jp-FileEditor"
        },
    ]
}

```
