rss.png profile for ebal on Stack Exchange, a network of free, community-driven Q&A sites
vim modeline

a back to vim basics post !


It’s quite obvious that we need different vimrc settings for different files/languages. This is mostly about tabs and characters but it can be extended to more. For example in pytnon (ansible etc) you need to replace the tab to four or eight characters. Most of us are using something like this:

:set tabstop=4 shiftwidth=4  softtabstop=4 expandtab

every time we open a python related file.

But you can set your own options in every file using a comment in the end or in the begging of the file. Like this one:


# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

... (awesome code) ...

This is called: modeline and is something magic!
Just add the below line to your ~./vimrc file or if you need a more global setting append it to your /etc/vimrc

set modeline
Tag(s): vim, modeline
  1. Avatar di orev orev

    Friday, June 19, 2015 - 20:06:43

    FYI, modelines are not interpreted when running vim as root.

  2. Avatar di ebal ebal

    Friday, June 19, 2015 - 20:11:16

    On my system works fine!

    # tail -1 /etc/vimrc
    set modeline

    just test it!

Add comment

Fill out the form below to add your own comments