[Question]
  [
Given a non-empty string, keep removing the first and last characters until you get to one or two characters.
For example, if the string was `abcde`, your program should print:
```
abcde
 bcd
  c
```
However, if it was `abcdef`, it should stop at two characters:
```
abcdef
 bcde
  cd
```
Trailing newlines and trailing spaces at the end of each line are optional. You can have as many as you want or none.
## Test cases
```
ABCDEFGHIJKLMNOPQRSTUVWXYZ -> ABCDEFGHIJKLMNOPQRSTUVWXYZ
                               BCDEFGHIJKLMNOPQRSTUVWXY 
                                CDEFGHIJKLMNOPQRSTUVWX  
                                 DEFGHIJKLMNOPQRSTUVW   
                                  EFGHIJKLMNOPQRSTUV    
                                   FGHIJKLMNOPQRSTU     
                                    GHIJKLMNOPQRST      
                                     HIJKLMNOPQRS       
                                      IJKLMNOPQR        
                                       JKLMNOPQ         
                                        KLMNOP          
                                         LMNO           
                                          MN            
ABCDEFGHIJKLMNOPQRSTUVWXYZ! -> ABCDEFGHIJKLMNOPQRSTUVWXYZ!
                                BCDEFGHIJKLMNOPQRSTUVWXYZ 
                                 CDEFGHIJKLMNOPQRSTUVWXY  
                                  DEFGHIJKLMNOPQRSTUVWX   
                                   EFGHIJKLMNOPQRSTUVW    
                                    FGHIJKLMNOPQRSTUV     
                                     GHIJKLMNOPQRSTU      
                                      HIJKLMNOPQRST       
                                       IJKLMNOPQRS        
                                        JKLMNOPQR         
                                         KLMNOPQ          
                                          LMNOP           
                                           MNO            
                                            N             
A -> A
AB -> AB
```
Remember this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins. 
  
[Answer]
# [V](http://github.com/DJMcMayhem/V), 10 bytes
```
ò^llYpr $x
```
[Try it online!](http://v.tryitonline.net/#code=w7JebGxZcHIgJHg&input=YWJjZGVmZ2hpams)
Explanation:
```
ò^ll         " While there are at least two non-whitespace characters on the current line
    Y        " Yank this line
     p       " Paste it below
      r      " Replace the first character with a space
        $    " Move to the end of the line
         x   " Delete a character
```
[Answer]
# ES6 (Javascript), ~~47~~, ~~48~~, 43 bytes
EDIT: Replaced ternary operator with &&, prefixed padding string with the newline. Thanks @Neil for an excellent advice ! 
EDIT: included the function name for the recursive invocation, stripped one byte off by using a literal newline
**Golfed**
```
R=(s,p=`
 `)=>s&&s+p+R(s.slice(1,-1),p+' ')
```
**Test**
```
R=(s,p=`
 `)=>s&&s+p+R(s.slice(1,-1),p+' ')
console.log(R("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
ABCDEFGHIJKLMNOPQRSTUVWXYZ
 BCDEFGHIJKLMNOPQRSTUVWXY
  CDEFGHIJKLMNOPQRSTUVWX
   DEFGHIJKLMNOPQRSTUVW
    EFGHIJKLMNOPQRSTUV
     FGHIJKLMNOPQRSTU
      GHIJKLMNOPQRST
       HIJKLMNOPQRS
        IJKLMNOPQR
         JKLMNOPQ
          KLMNOP
           LMNO
            MN
console.log(R("ABCDEFGHIJKLMNOPQRSTUVWXYZ!"))
ABCDEFGHIJKLMNOPQRSTUVWXYZ!
 BCDEFGHIJKLMNOPQRSTUVWXYZ
  CDEFGHIJKLMNOPQRSTUVWXY
   DEFGHIJKLMNOPQRSTUVWX
    EFGHIJKLMNOPQRSTUVW
     FGHIJKLMNOPQRSTUV
      GHIJKLMNOPQRSTU
       HIJKLMNOPQRST
        IJKLMNOPQRS
         JKLMNOPQR
          KLMNOPQ
           LMNOP
            MNO
             N
```
[Answer]
## Python, 45 bytes
```
f=lambda s,p='\n ':s and s+p+f(s[1:-1],p+' ')
```
Recursively outputs the string, plus a newline, plus the leading spaces for the next line, plus the recursive result for the shortened string with an extra space in the prefix.
If a leading newline was allowed, we could save a byte:
```
f=lambda s,p='\n':s and p+s+f(s[1:-1],p+' ')
```
Compare with a program (49 bytes in Python 2):
```
s=input();p=''
while s:print p+s;s=s[1:-1];p+=' '
```
[Answer]
# [Brainfuck](https://esolangs.org/wiki/Brainfuck), 67 bytes
```
>>,[.>,]<[>++++++++++.<[-]<[<]>[-]++++++++[-<++++>]<[<]>[.>]>[.>]<]
```
This should work on all brainfuck flavors.
[Try it online!](http://brainfuck.tryitonline.net/#code=Pj4sWy4-LF08Wz4rKysrKysrKysrLjxbLV08WzxdPlstXSsrKysrKysrWy08KysrKz5dPFs8XT5bLj5dPlsuPl08XQ&input=QUJDREVGRw)
### Ungolfed code:
```
# Print and read input_string into memory
>>,[.>,]<
while input_string is not empty [
    # Print newline
    >+++++ +++++.<
    # Remove last character
    [-]
    # GOTO start of input_string
    <[<]>
    # Remove first character
    [-]
    # Add space to space_buffer
    +++++ +++[-<++++>]
    # GOTO start of space_buffer
    <[<]>
    # Print space_buffer
    [.>]
    # Print input_string
    >[.>]
<]
```
There should still be some bytes to chop off here; I've only recently began using brainfuck, so my pointer movement is probably very inefficient.
[Answer]
# [J](http://jsoftware.com/), 39 19 16 bytes
```
[:|:]#"0~#\.<.#\
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o61qrGKVlQzqlGP0bPSUY/5rcqUmZ@QrpCmoJyYlp6SmqUP46rq6uuqoUsgy/wE "J – Try It Online")
This was a nice example of how a different perspective can allow J to express a problem more naturally. Originally, I was seeing the problem "horizontally", as described in the OP -- a sequence with successive edges being removed:
[![enter image description here](https://i.stack.imgur.com/UYNl5.png)](https://i.stack.imgur.com/UYNl5.png)
But you can also view it vertically, as a kind of upside down histogram:
[![enter image description here](https://i.stack.imgur.com/9zy3c.png)](https://i.stack.imgur.com/9zy3c.png)
From this perspective, we are just repeating each letter some number of times, an operation J's copy primitive `#` can accomplish in 1 character.
Consider `abcde`:
* `#\.<.#\` Determine the number of times to repeat each character, ie, produce
the mask `1 2 3 2 1`:
```
#\  => 1 2 3 4 5
#\. => 5 4 3 2 1
----------------
<.  => 1 2 3 2 1  NB. elementwise min
```
* `]#"0~` Use that mask to duplicate the input:
```
a  
bb 
ccc
dd 
e  
```
* `[:|:` Transpose:
```
abcde
 bcd 
  c
```
[Answer]
# Python 2, 50 bytes
```
def f(i,j=0):
 print' '*j+i
 if i:f(i[1:-1],j+1)
```
Simple recursive function that keeps shortening the string until it disappears.
Call as f('string')
Output
```
string
 trin
  ri
```
[Answer]
## Perl, 31 bytes
30 bytes of code + `-p` flag.
```
s/( *)\S(.+).$/$& 
 $1$2/&&redo
```
To run it :
```
perl -pE 's/( *)\S(.+).$/$&
 $1$2/&&redo' <<< "abcdef"
```
**Explanations** : The `\S` and `.$` correspond to the first and last character, `(.+)` the middle and `( *)` to the trailing spaces that are added every time we remove one character from the beginning. So the regex removes one character from the beginning, one from the end, and add one leading space each time.
[Answer]
# GNU sed 24 Bytes
Includes +2 for `-rn`
```
:
p
s/[^ ](.+)./ \1/
t
```
Prints, replaces the first non-space character with a space, and deletes the last character until nothing changes.
[Answer]
# [MATL](http://github.com/lmendo/MATL), 9 bytes
```
tg!*YRPRc
```
This produces trailing spaces and newlines.
[Try it online!](http://matl.tryitonline.net/#code=dGchKllSUFJj&input=J0FCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaISc)
### Explanation
```
t      % Input string implicitly. Duplicate
g!     % Convert to logical and transpose: gives a column vector of ones
*      % Multiply with broadcast. This gives a square matrix with the string's
       % ASCII codes on each row
YR     % Lower triangular part: make elements above the diagonal 0
P      % Flip vertically
R      % Upper triangular part: make elements below the diagonal 0
c      % Convert to char. Implicitly display, with char 0 shown as space
```
[Answer]
## Batch, 92 bytes
```
@set/ps=
@set t=
:g
@echo %t%%s%
@set t= %t%
@set s=%s:~1,-1%
@if not "%s%"=="" goto g
```
Takes input on STDIN.
[Answer]
# C, 73 bytes
```
f(char*s){char*b=s,*e=s+strlen(s)-1;while(e-b>-1)puts(s),*b++=32,*e--=0;}
```
Ungolfed:
```
f(char*s) {
  char *b=s,
       *e=s+strlen(s)-1;
  while (e-b>-1)
    puts(s),
    *b++=32,
    *e--=0;
}
```
Usage:
```
main(){
  char a[] = "abcde";
  f(a);
}
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 8 bytes
Code:
```
ÐvNú,¦¨D
```
Explanation:
```
Ð          # Triplicate the input
 v         # Length times do...
  Nú,      # Prepend N spaces and print with a newline
     ¦¨    # Remove the first and the last character
       D   # Duplicate that string
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=w5B2TsO6LMKmwqhE&input=QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVoh)
[Answer]
## Pyke, 10 bytes
```
VQlRc
l7tO
```
[Try it here!](http://pyke.catbus.co.uk/?code=VQlRc%0Al7tO&input=abcdefgh&warnings=0)
[Answer]
# Haskell, ~~47~~ 43 bytes
```
f s@(a:b:c)=s:map(' ':)(f.init$b:c)
f s=[s]
```
[Try it on Ideone](http://ideone.com/pOrwuB). Output is a list of strings which was allowed in the comments of the challenge. To print, run with `(putStr.unlines.f)` instead of just `f`.
Edit: Saved 4 bytes after noticing that trailing whitespace is allowed.
```
Prelude> (putStr.unlines.f)"codegolf"
codegolf
 odegol
  dego
   eg
               --(trailing whitespace)
```
[Answer]
# [Perl 6](https://perl6.org), 42 bytes
```
for get,{S/\w(.*)./ $0/}.../\s..?$/ {.put}
```
## Expanded:
```
for
  # generate the sequence
  get,       # get a line from the input
  {          # bare block lambda with implicit parameter ｢$_｣
             # used to produce the rest of the sequence
    S/       # replace
      \w     # a word character ( to be removed )
      (      # set ｢$0｣
        .*   # any number of any characters
      )
      .      # any character ( to be removed )
    / $0/    # append a space
  }
  ...        # repeat that until
  /          # match
    \s       # whitespace
    .        # any character
    .?       # optional any character
    $        # end of string
  /
{
  .put       # print $_ with trailing newline
}
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `C`, 4 bytes
```
‡ḢṪ↔
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=C&code=%E2%80%A1%E1%B8%A2%E1%B9%AA%E2%86%94&inputs=abcdefghijklmnopq&header=&footer=)
i have turned to the dark side
i am now a flag abuser
thanks to lyxal for helping me get to the 4-byte sol (from 8 bytes)
## Explanation
```
   ↔  While results have not reached a fixed point
‡     2-byte function
 Ḣ    a[1:]
  Ṫ   a[:-1]
C     Center the list and join on newlines
```
The below less cheese program does the same thing. `øĊ` is the same as the `C` flag.
# [Vyxal](https://github.com/Lyxal/Vyxal) `j`, 6 bytes
```
‡ḢṪ↔øĊ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=j&code=%E2%80%A1%E1%B8%A2%E1%B9%AA%E2%86%94%C3%B8%C4%8A&inputs=%22abcdefghijklmnopq%22&header=&footer=)
Since outputting a list was allowed, using the `j` flag to join on newlines is reasonable. You can also append `⁋` to use no flags at all.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
J’⁶ẋoUµ⁺Y
```
[Try it online!](https://tio.run/##ATYAyf9qZWxsef//SuKAmeKBtuG6i29VwrXigbpZ////QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo "Jelly – Try It Online")
If the input is of length \$2n\$, this outputs with \$n\$ lines of trailing newlines and spaces
## How it works
```
J’⁶ẋoUµ⁺Y - Main link. Takes a string A on the left
      µ⁺  - Do the following twice:
J         -   Yield [1, 2, 3, ..., 2n]
 ’        -   Decrement; [0, 1, 2, ..., 2n-1]
  ⁶ẋ      -   Repeat a space that many times; [[], [' '], [' ', ' '], ...]
     U    -   Reverse A
    o     -   Logical OR
        Y - Join by newlines
```
The logical OR command `o` has the following behaviour:
```
[[], [5], [6, 7], [8, 9, 10]] o [1, 2, 3, 4] = [[1, 2, 3, 4], [5, 2, 3, 4], [6, 7, 3, 4], [8, 9, 10, 4]]
```
so only the leftmost characters are replaced by spaces. We do this twice, reversing each time, to get both the left and right side
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 9 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
［Ｌ［ｊｋ｝］∔＼
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXVGRjNCJXVGRjJDJXVGRjNCJXVGRjRBJXVGRjRCJXVGRjVEJXVGRjNEJXUyMjE0JXVGRjND,i=QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVolMjE_,v=8)
[Answer]
## [Retina](http://github.com/mbuettner/retina), 17 bytes
```
;{G:`
\S(.+).
 $1
```
[Try it online!](http://retina.tryitonline.net/#code=O3tHOmAKXFMoLispLgogJDE&input=YWJjZGVmZ2hpag)
[Answer]
# C++14, 117 bytes
```
auto f(auto s){decltype(s)r;auto b=s.begin();auto e=s.rbegin();while(e.base()-b>0)r+=s+"\n",*b++=32,*e++=0;return r;}
```
Assumes input `s` is a `std::string` and returns the animated text.
Ungolfed:
```
auto f(auto s){
  decltype(s)r;
  auto b=s.begin();
  auto e=s.rbegin();
  while(e.base()-b>0){
    r+=s+"\n";
    *b++=32;
    *e++=0;
  }
  return r;
}
```
Usage:
```
main(){
  std::string a{"abcdef"};
  std::cout << f(a);
  std::string b{"abcde"};
  std::cout << f(b);
}
```
[Answer]
## Vim - 14 keystrokes
```
qqYp^r $x@qq@q
```
  
Explanation:
```
qq  -- record a macro named 'q'
Y   -- Copy current line
p   -- Paste it
^r  -- Replace the first non-space character on the new line with a space
$x  -- Delete the last character on the line
@q  -- Recursively call the 'q' macro
q   -- Stop recording the 'q' macro
@q  -- Run the 'q' macro
```
Vim automatically kills the macro once we're out of characters
[Answer]
**Snap! - 16 blocks**
![Snap!](https://i.stack.imgur.com/eGa4c.png)
Output is self-centering. The 'wait' is for humans.
[Answer]
# PHP, 91 bytes
```
<?for(;$i<.5*$l=strlen($s=$_GET[s]);$i++)echo str_pad(substr($s,$i,$l-$i*2),$l," ",2)."\n";
```
Usage: save in a file and call from the browser:
```
http://localhost/codegolf/string-middle.php?s=ABCDEFGHIJKLMNOPQRSTUVWXYZ
Raw output:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
 BCDEFGHIJKLMNOPQRSTUVWXY 
  CDEFGHIJKLMNOPQRSTUVWX  
   DEFGHIJKLMNOPQRSTUVW   
    EFGHIJKLMNOPQRSTUV    
     FGHIJKLMNOPQRSTU     
      GHIJKLMNOPQRST      
       HIJKLMNOPQRS       
        IJKLMNOPQR        
         JKLMNOPQ         
          KLMNOP          
           LMNO           
            MN            
http://localhost/codegolf/string-middle.php?s=1ABCDEFGHIJKLMNOPQRSTUVWXYZ
Raw output:
1ABCDEFGHIJKLMNOPQRSTUVWXYZ
 ABCDEFGHIJKLMNOPQRSTUVWXY 
  BCDEFGHIJKLMNOPQRSTUVWX  
   CDEFGHIJKLMNOPQRSTUVW   
    DEFGHIJKLMNOPQRSTUV    
     EFGHIJKLMNOPQRSTU     
      FGHIJKLMNOPQRST      
       GHIJKLMNOPQRS       
        HIJKLMNOPQR        
         IJKLMNOPQ         
          JKLMNOP          
           KLMNO           
            LMN            
             M             
```
[Answer]
**Mathematica, 71 bytes**
```
Table[#~StringTake~{i,-i},{i,Ceiling[StringLength@#/2]}]~Column~Center&
```
[![animate-finding-the-middle](https://i.stack.imgur.com/m0oPU.png)](https://i.stack.imgur.com/m0oPU.png)
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 7 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ö÷e╧╤ù◘
```
[Run and debug it](https://staxlang.xyz/#p=94f665cfd19708&i=%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22)
## Explanation
```
|]miTiNt
|]m      map each suffix to:
   iT    remove iteration count elements from right
     iNt pad with iteration count number of spaces on left
```
# [Stax](https://github.com/tomtheisen/stax), 117 bytes
```
c%{d
   xitiT|c
   {|,}20*|:xi{xitiTx%|CPFxP
   {|,}20*|:xi{xitiTx%|CPFxitiNtP
   {|,}20*|:xi{xitiTx%|CPFxitiTx%|CP
F
```
[Run and debug it, animated](https://staxlang.xyz/#c=c%25%7Bd%0A+++xitiT%7Cc%0A+++%7B%7C,%7D20*%7C%3Axi%7BxitiTx%25%7CCPFxP%0A+++%7B%7C,%7D20*%7C%3Axi%7BxitiTx%25%7CCPFxitiNtP%0A+++%7B%7C,%7D20*%7C%3Axi%7BxitiTx%25%7CCPFxitiTx%25%7CCP%0AF&i=%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%21%22)
The more fun version. Since stax supports `requestAnimationFrame` from js, `|,` and `|:` can be used to animate each step.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 11 bytes
```
.e
:bUkd_._
```
[Test suite](http://pythtemp.herokuapp.com/?code=.e%0A%3AbUkd_._&test_suite=1&test_suite_input=%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22%0A%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%21%22&debug=0)
[14 bytes to exit without error](http://pythtemp.herokuapp.com/?code=j.e%3AbUkdhc2_._&test_suite=1&test_suite_input=%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22%0A%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%21%22&debug=0)
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~25~~ ~~16~~ 15 [bytes](https://github.com/abrudz/SBCS)
-9 bytes thanks to [Jonah](https://codegolf.stackexchange.com/users/15469/jonah)'s comment!  
-1 bytes thanks to [Adám](https://codegolf.stackexchange.com/users/43319/ad%C3%A1m)!
```
{⍉↑⍵/¨⍨⌊∘⌽⍨⍳⍴⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pRb@ejtomPerfqH1rxqHfFo56uRx0zHvXsBbF7Nz/q3QKUqv2f9qhtwqPevkddzY961wAFD603Bunqmxoc5AwkQzw8g/@nHVqhoO7o5Ozi6ubu4enl7ePr5x8QGBQcEhoWHhEZpY5PUlFdQUNH3VFdE6RIHQA "APL (Dyalog Unicode) – Try It Online")
This is the dfn taking the string as right input `⍵`.
`⍳⍴⍵` the indices of the input string.  
`⌊∘⌽⍨` element-wise minimum of the indices with the indices reversed. This is the number of times each character appears.  
`⍵/¨⍨` repeat each character that many times.  
`↑` arranges the repeated characters in a 2d matrix, padding shorter strings with spaces.  
`⍉` transposes the matrix.
[Try it with step-by-step output!](https://tio.run/##SyzI0U2pTMzJT/8f8KhtQvWjvqlA6lHv1kfdLRC2ujqI2bu19n/1o95OoKKJAUCe/qEVj3pXBDzq6XrUMeNRz14wp3fzo94tYKVpYEP6HnU1P@pdAxQ8tN4YqBFoYHCQM5AM8fAM/p@moO7o5Ozi6qYOAA)
]