Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the syntax for telling VI to read/write a source file with soft-tabs and a specified indentation?

Tags:

vim

vi

emacs

Someplace I saw a snippet of code which told vi to use soft tabs and set the size of a tab. If you put this snippet at the bottom of a source file, then vi would magically use those settings for that file.

What is the syntax and rules for including that snippet in a source file? Can emacs be made to use these settings as well?

like image 995
Ross Rogers Avatar asked Mar 01 '23 02:03

Ross Rogers


2 Answers

You can put this in a comment in your source file:

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

The comment syntax depends on the type of the source file.

For C/C++/Java, this would be:

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

For JSP, this would be:

<%-- ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: --%>

This works if it is placed at the beginning of the source file, but I'm not sure that this'll work if placed at the end of it too.

This will not work for emacs. There might be a different way of achieving the same for emacs.

like image 120
Siddhartha Reddy Avatar answered Mar 09 '23 01:03

Siddhartha Reddy


Check out :h modeline.

Example:

/* vim: ai set sw=4 ts=4 */

See :h modelines for how many lines into a file Vim will check for modeline info. The default is to check the first 5 lines.

like image 23
overthink Avatar answered Mar 09 '23 01:03

overthink