Developing A Game Engine with Perl: Part 8 - Vim
Tags: perl, gamedev, devjournal, vim
Published: 2021-12-06 07:41:20

[As Always...](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-part-2-mouse-input-43nj) **I DO NOT KNOW WHAT I AM DOING.**

If you want to start reading from the beginning. Check out the [first article in this series](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-3b8)

Let's step back from [typing code](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-part-6-a-colourful-telnet-server-4i7g) for a moment and talk about how that code is typed. There are [many options](https://en.wikipedia.org/wiki/Source-code_editor#Notable_examples) for a developer to code with, and we all have a preference. It's not so much a matter of right and wrong, as it is of comfort and enjoyment. For me, I code in [Vim](https://www.vim.org/download.php). 

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r64ntezh2wlam11ohdhc.jpeg)

## ...and Coding in Vim is fun
I was introduced to Vim back in college. Our school used [AIX](https://en.wikipedia.org/wiki/IBM_AIX) for their server OS and we were taught to use Vim. This was also my first introduction to a Unix environment. Coming from a home Dos/Windows environment and entering the Unix world came with challenges. 

[Using Vim](https://mamchenkov.net/wordpress/2004/05/10/vim-for-perl-developers/) twisted my brain and took a bit to get use to. But today, after using it for many years, it often feels [very rhythmic](https://www.youtube.com/watch?v=0KRxhNrtVIY) and [fun](https://www.youtube.com/watch?v=iurhjlBum0o) to code. Also, not gonna lie, it kinda makes me feel that sense of "coolness" I got when watching [Hackers](https://www.youtube.com/watch?v=Rn2cf_wJ4f4) for the first time. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wan5j8kutdpoihzkhsq.gif)
[Hahaha...](https://www.youtube.com/watch?v=p96KIwW5RIc) That movie does **NOT** hold up well! Teenager me was so impressionable.
```
$me->hides_face_in_shame();
``` 
We can verify my shame level using this code:
```
use strict;
use warnings;
use Shameful::movies;

my $movie  = shift;
my $me     = new Shameful::movies();
my $shame  = $me->watched($movie);
my $return = "Great Movie!";

if ($shame) {
    $return = $me->hides_face_in_shame($movie);
}

print $return;
exit;
```

Running that code prints out the following.

```
localhost:~/Fake_But_Should_Be_Real_Scripts/ # 
perl i_loved_watching.pl Hackers

Hack the planet!... More like Hide your face bro!
```
## ANSI in Vim
Working with ANSI codes directly in Vim I see a lot of `^[`. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx03498arazf6pauu39z.png)
Now this `^[` isn't the same as `shift+6 and [`. No, this represents the escape character and is highlighted blue in my Vim. If it was `shift+6 and [` it would be coloured the same as regular text. Something very useful to know, you can type the escape character in Vim by pressing `ctrl+v` and then the `escape` key. 

## I split Vim up to open multiple files
I use the `:split` and `:vsplit` command in Vim often to load in other files. Using `split` will stack files above/below each other (split horizontally) and `vsplit` does side by side (vertically). Sometimes I need to combine `split` and `vsplit` to have 3 files at once. Switching between each file in (v)split can be done with `ctrl+w+w`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89gr4cikr966i90xijah.png)

## So Colourful
Vim supports colour schemes. It's something I don't change often, so I always forget and have to look it up. Since I just did it recently after [upgrading the dev/test server](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-part-3-hardware-failure-server-upgrade-on1), I'll share here with you all. You can change it with the :colorscheme command. The one I'm using is :colorscheme peachpuff. I also have syntax highlighting turned on with the :syntax on. I made it permanent by adding the commands to ~/.vimrc I code in [OpenSuSE Linux](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-part-4-uefi-vs-opensuse-installer-5e1c), Vim config files may vary with your OS. 

## Don't try this at work
Running a bulk search and replace can cause unexpected results if you're not careful. I know I'm thankful for [whoever invented undo](https://en.wikipedia.org/wiki/Undo#History). 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y96str6utiqwochk8183.png)
There are [many ways](https://linux.die.net/man/1/sed) to [search and replace](https://linux.die.net/man/1/awk) the contents of a file in Linux and [Perl](https://perldoc.perl.org/perlrequick). However, when I'm in Vim, I often find it quickest to use the :%s command. Typically when I need to apply a search and replace to a whole file I use a command like this:
```
:%s/\^[//g
```
The format is `:%s/search_pattern/replace_with/g` The search pattern I used in the above example is to find the escape character `^[` I mentioned earlier and replace every occurrence with nothing `//g`. I have to precede `^[` with `\` so the [regular expression search pattern](http://vimdoc.sourceforge.net/htmldoc/pattern.html) knows it's a literal escape character. I type `^[` using ctrl+v and pressing escape.

## How about you?
Do you code in Vim? What sort of tricks and tips have you learned? What colorscheme do you prefer?

If you have any suggestions or comments please share constructively. Also please visit our social media pages for lots of fun videos and pictures showing the game engine in action. 

[ANSI Game Engine on Instagram](https://www.instagram.com/ANSIGameEngine/)
[ANSI Game Engine on Facebook](https://www.facebook.com/ANSIGameEngine)

[Prev << Part 7 - Fork](https://dev.to/ansigameengine/developing-a-game-engine-with-perl-part-7-fork-3acm)
**_Next >> Coming Soon_**