How can I change certain keywords in vim to all-caps? I would like to know as I am programming in Fortran and the required style is to have all the intrinsic functions in caps. For example the keyword if would change to IF, do would change to DO and call to CALL etc... And constantly using my little finger for the shift key is giving me repetitive strain injury!

If there was some way to take advantage of the snytax highlighting feature in vim that would be great but I don't mind spending half an hour or so typing out all the keywords I want to be made caps if this is the only way.


You can use


or use a function


Change the /gc to /gif you don't want to confirm before changing each match.

  • Ahh thanks, this is helpful. Is there anyway I could make this run constantly so as soon as I type a keyword it makes it all caps? – Michael Portobello Nov 18 '17 at 15:52
  • @MichaelPortobello - Not that it's not possible but you might be taking the wrong route to this. I don't know fortran but I can imagine you having those keywords in comments or elsewhere where you don't want them all-caps. This solution is fine for a one-off thing but too brittle to be run on autopilot. A better solution would be to incorporate the syntax highlighting scaffolding already provided. That's beyond my knowledge level though. You might hae more luck asking the question on SO. – Lieven Keersmaekers Nov 19 '17 at 10:07
  • OK thanks for that, I thought it may be quite involved. I may just map that search and replace command to a key and use that every so often. I've accepted this as the answer. – Michael Portobello Nov 19 '17 at 10:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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