1

I'd like to know how to set emacs up to do the equivalent of what vim does when I have this configuration:

cat $HOME/.vimrc 
set tabstop=4
set shiftwidth=4
set expandtab

So basically, whenever I hit tab tab to the next tabstop with tabstops set to every 4 spaces. And use spaces instead of tabs when I type the tab key.

Searching for answer

I did some searches and came up with this:

So if that is the case, I'm mainly interested in shell-script[sh] mode.

PatS
  • 155
  • 6

1 Answers1

2

In the context of shell-script-mode, to set the "indentation size" the variable you're looking for is sh-basic-offset. From C-h v sh-basic-offset:

sh-basic-offset is a variable defined in ‘sh-script.el’.

Its value is 4

The default indentation increment.
This value is used for the ‘+’ and ‘-’ symbols in an indentation variable.

  This variable has an alias: ‘sh-indentation’.
  This variable is safe as a file local variable if its value
  satisfies the predicate ‘integerp’.
  You can customize this variable.

[back]

The variable for "indentation uses spaces" is indent-tabs-mode, which is more of a "global" setting. From C-h v indent-tabs-mode:

indent-tabs-mode is a variable defined in ‘C source code’.

Its value is nil

Indentation can insert tabs if this is non-nil.

  Automatically becomes buffer-local when set.
  This variable is safe as a file local variable if its value
  satisfies the predicate ‘booleanp’.
  You can customize this variable.
  Probably introduced at or before Emacs version 18.

[back]

If you're familiar with Vim's modeline magic, Emacs has a similar facility via file local variables. For instance, one could add the following to the beginning of a shell script to configure "sh mode" for both Vim and Emacs.

#!/bin/sh
# -*- mode: shell-script; sh-shell: sh; sh-basic-offset: 4; indent-tabs-mode: nil -*-
# vim: set ts=4 sts=4 sw=4 et ft=sh:
nega
  • 3,091
  • 15
  • 21