After writing some prefix, typing the UP-ARROW

```
sage: prefix<UP-ARROW>
```

Allows you to search the previous entered command starting with `prefix`

.

**EDIT:** To search not only prefixes, but also any occurrences of a keyword, you may show the complete history of inputs by doing:

```
sage: %history
```

or you may use the variable `In`

which contains the list of the inputs (the variable `Out`

contains the outputs) doing as follows:

```
sage: def search_history(keyword):
....: L = ["In[{}]={}".format(i,cmd) for (i,cmd) in enumerate(In) if keyword in cmd]
....: print('\n'.join(L))
```

and then:

```
sage: factor(100)
2^2 * 5^2
sage: print(43)
43
sage: identity_matrix(4)
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
sage: search_history('factor')
In[2]=factor(Integer(100))
In[5]=search_history('factor')
```