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.
2 Answers
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
You can set the syntax highlighting by doing:
:set syntax=java
This will work in the unwritten buffer. Change java
for the appropriate value.
-
2Or even
set filetype
if you have mappings/other goodies to use.– D. Ben Knoble ♦Commented Jun 28, 2019 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.– aswineCommented Jun 28, 2019 at 20:09