Due to some USB issues, I recently had the need to go hacking around in the Linux Kernel USB code. Since my goal was to make a fix, I wanted to push the patch upstream once it was done. Thus, I Googled around for the ViM formatting commands that would make my editor adhere to the Linux Kernel Coding Standard for the changes. Strangely, I had some issues locating anything.

The best thing I could find was Vivien's ViM plugin, which would certainly do the job, but unfortunately would apply the changes to all of my C and C++ files. As it turns out, I really don't care for the Kernel Style, at all, so that wasn't appealing. I decided to fork the project and make the necessary changes.

ViM kernel-coding-style Plugin

I haven't made any major changes to Vivien's plugin - just changed how it was invoked and added a readme, so far. You can find the plugin on my github, here: kernel-coding-style ViM Plugin


Drop the plugin into your Pathogen bundle/ directory, or your personal scripts directory. Simple!


To prevent these settings from overwriting your personal settings for C and C++ files, they will not be auto-applied to the files you open. You must invoke the appropriate 'SetLinuxFormatting' command to apply them. Also, changes will only take place in your local buffer - they are not global settings, and there is no way to apply them to all buffers at once, for now.

An example of mapping applying the settings using the command key:

nnoremap <silent> <leader>k :SetLinuxFormatting<cr><cr>


I would like to add more features eventually. Toggling the settings on/off (thus requiring saving your personal settings somehow) would be cool. Also, I may add an option to apply the settings globally instead of just to the local buffer. I might address these if other people start using the plugin. For now, it is simple, and it works.

I also filed a pull request on Github, here, so my changes might get merged into Vivien's original project, eventually

Happy hacking =)