Can I set a hotkey to change the style of a line snippet?

I have been using a custom style for code entries for my programming lab papers which is working fine. I just want to know if there is anyway to switch between them with a hotkey. Also I can not figure out how to use the style for just a snippet of code in a regular sentence. The style (background, font, font size) takes over the whole line on me.

For styling words you need to define a character style. The character formatting in the paragraph style is only used, if the character itself has no special formatting.

To use styles via keyboard you have to define your own shortcut keys. You can do this in Tools > Customize > Keyboard. Scroll down, select “Styles”, open + , and select the kind of style in the list “Category”. Select your designed style in the list “Function”. Then select the desired shortcut keys from the above list “Shortcut keys”, Alt+C for example. Then click on button “Modify”. Notice, that this shortcut key will only work, when the style exists. Therefore you should define the style already in the document template.