The challenge is to manipulate strings using basic Vim-like commands
- A string of text to be transformed. The input alphabet is [a-z].
- A string of legal commands
- The transformed string
There are a few ideas you should understand:
The cursor is represented as a location between 2 characters.
| will be used to represent the cursor(s) in this explanation.
|foobar- The cursor at beginning of string
foo|bar- Cursor in the middle of the string
foobar|- Cursor at the end of the string
A selection is a a group of characters between 2 cursors.
|foobar|- The selection is
|foo|bar- The selection is
foo|bar|- the selection is
|foobar- The selection is the empy string (both cursors at same location)
A selection is formed from the previous cursor position and the result of the current command.
Using the command
|foo would make the selection
Commands can be described as functions.
C<selection> is a command that has a selection parameter. The next command provides the selection.
D>deletes the character to the right of the cursor.
DNadeletes from the cursor to the next
As you can see, commands "associate to the right"
DNais parsed as
DDNais parsed as
The insert mode command
I extends until the next command.
DIbar>is parsed as
These are the commands:
>- Move cursor right.
<- Move cursor left.
B- Move cursor to the beginning of the string
E- Move cursor to the end of the string
N<char>- Move cursor to place before next
P<char>- Move cursor to place after previous
I<string>- Enter/exit insert mode. Characters in
<string>are inserted at the current cursor position.
<string>extends until the next command. The cursor is moved to end of insertion
D<selection>- delete characters in
f|r. The output selection from this command is the empty string.
- The cursor cannot move out of bounds.
B<<<is the same as
Nxis the same as
xcan be found.
- The cursor location always starts at the beginning of the string
- The cursor should not be outputted
- Commands are always uppercase, characters are lowercase.
- No text editor scripts like Vimscript
- It's code golf. Lowest character count wins.