A classic naval combat game playable directly within Vim. Challenge the computer to a tactical battle and attempt to sink all of its ships before it sinks all of yours. Written entirely in Vim9script to showcase modern language features.
- Multiple Difficulty Levels: Play against NOVICE (random) or EXPERT (probability-based) AI
- Game Variants: Choose between ONE SHOT, HIT BONUS, or SHIP COUNT gameplay
- 5 Ships: Carrier (5), Battleship (4), Cruiser (3), Submarine (3), Destroyer (2)
- Interactive Placement: Visually place your ships before battle
- Strategic AI: Challenge the computer's tactical decision-making
- Full Vim Integration: Seamless gameplay with buffer-local key bindings
- Modern Vim9script Design: Demonstrates classes, interfaces, and type safety
- Vim 9.0 or later with Vim9script support
- NOT compatible with Neovim (requires Vim9-specific features)
If you have git installed, run the following command in your terminal:
Unix/Linux/macOS:
git clone https://github.com/yegappan/battleship.git ~/.vim/pack/downloads/opt/battleshipWindows (cmd.exe):
git clone https://github.com/yegappan/battleship.git %USERPROFILE%\vimfiles\pack\downloads\opt\battleshipIf you prefer not to use Git:
Unix/Linux/macOS:
Create the destination directory:
mkdir -p ~/.vim/pack/downloads/opt/Download the plugin ZIP file from GitHub and extract its contents into the directory created above.
Note: GitHub usually names the extracted folder battleship-main. Rename it to battleship so the final path looks like this:
~/.vim/pack/downloads/opt/battleship/
├── plugin/
├── autoload/
└── doc/
Windows (cmd.exe):
Create the destination directory:
if not exist "%USERPROFILE%\vimfiles\pack\downloads\opt" mkdir "%USERPROFILE%\vimfiles\pack\downloads\opt"Download the plugin ZIP file from GitHub and extract its contents into that directory.
Note: Rename the extracted folder (usually battleship-main) to battleship so the path matches:
%USERPROFILE%\vimfiles\pack\downloads\opt\battleship\
├── plugin/
├── autoload/
└── doc/
Finalizing Setup Since this plugin is installed in the opt (optional) directory, it will not load automatically. Add the following line to your .vimrc (Unix) or _vimrc (Windows):
packadd battleshipAfter adding the line, restart Vim and run the following command to enable the help documentation:
:helptags ALLIf using a plugin manager like vim-plug, add to your .vimrc or init.vim:
Plug 'path/to/battleship'Then run :PlugInstall and :helptags ALL
For other plugin managers (Vundle, Pathogen, etc.), follow their standard installation procedures for local plugins.
:Battleship| Key | Action |
|---|---|
| Arrow Keys | Move up/down/left/right / Select in menus |
k or ↑ |
Move up / Select previous (in menus) |
j or ↓ |
Move down / Select next (in menus) |
h or ← |
Move left |
l or → |
Move right |
H |
Jump to first row of current column |
L |
Jump to last row of current column |
Home or 0 |
Jump to first column of current row |
End or $ |
Jump to last column of current row |
PageUp |
Jump to first row of current column |
PageDown |
Jump to last row of current column |
| Key | Action |
|---|---|
Enter or s |
Place ship (placement phase) or shoot target (battle phase) |
r |
Rotate ship between horizontal and vertical (placement phase) |
ESC |
End your turn during battle |
| Key | Action |
|---|---|
n |
Start a new game |
q |
Quit game and close buffer |
- Difficulty Selection: Choose between NOVICE and EXPERT levels using
j/kand pressEnterorsto confirm. NOVICE uses random AI, EXPERT uses probability-based targeting - Variant Selection: Select your preferred game variant (ONE SHOT, HIT BONUS, or SHIP COUNT)
- Ship Placement: Position all 5 ships on your board (Carrier 5, Battleship 4, Cruiser 3, Submarine 3, Destroyer 2)
- Battle: Fire at the enemy board and defend against their attacks
- Gameover: Win or lose, then start a new game or quit
- You Win: Sink all 5 computer ships before yours are all sunk
- Computer Wins: Sink all 5 of your ships before you sink theirs
- Tie: Impossible in standard Battleship rules
- Each ship must be placed horizontally or vertically (no diagonal placement)
- Ships cannot overlap
- Ships cannot be placed outside the board boundaries
- All ships must be placed before battle begins
- Each shot targets one cell on the opponent's board
- Valid shots: empty water, unshot areas, or previous misses
- Hitting a ship marks that cell as a hit; other cells are misses
- When all cells of a ship are hit, the ship is sunk
- The number of shots per turn depends on your selected game variant
- Exactly one shot per turn for both player and computer
- Classic, methodical gameplay
- Get a bonus shot for each hit
- Multiple consecutive hits create momentum
- Computer gets the same advantage
- Get shots equal to the number of unsunk enemy ships (1-5 per turn)
- Creates dynamic, escalating gameplay
- Computer gets the same advantage
This plugin is licensed under the MIT License. See the LICENSE file in the repository for details.