1

I pasted some code into a new, unwritten buffer in Vim. I'd like to do some quick edits on the code without saving it to a file, but it hurts my eyes to look at code without syntax highlighting. Can I use syntax highlighting without writing it to a file? I don't want to write it to a file so I don't have to delete the file when I'm done.

  • What are you editing that youre not saving when done? – D. Ben Knoble Jun 28 at 19:21
  • A SQL query that I'm going to run once. – aswine Jul 1 at 14:22
3

In addition to setting the syntax, setting the filetype brings indent options (if you have those on), mappings, and other filetype specific vimscript to bear on your code. So I recommend

:set filetype=java

Which we typically abbreviate in interactive use as

:set ft=java
2

You can set the syntax highlighting by doing:

:set syntax=java

This will work in the unwritten buffer. Change java for the appropriate value.

  • 2
    Or even set filetype if you have mappings/other goodies to use. – D. Ben Knoble Jun 28 at 19:20
  • Thanks, alanboy. That works. @D.BenKnoble That's even better. I'll mark that as the correct answer if you make an answer. – aswine Jun 28 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.