9

How can I display characters as if they are square in vim? The characters themselves don't need to be square, but if you were to draw a grid through all centre points of the characters it should make a square grid.

I would like to do this because I am designing a fortress layout for Dwarf Fortress. The game is set out on a square/cube grid.

phuclv
  • 30,396
  • 15
  • 136
  • 260
AnnanFay
  • 1,015

3 Answers3

10

On Windows there are some square monospaced fonts in conhost.exe (which was the default terminal used by cmd and PowerShell, nowadays replaced by Windows Terminal) by default like the 8x8 font, but I've never heard of one in Linux. I did a search and found the square font which were made exactly for your purpose

Square is a TTF font intended for roguelike games

Roguelike games consist entirely of text in grid cells, but the problem is that most monospaced fonts are a lot higher than they are wide, which means roguelikes either have non-square cells, or they have square cells and the characters don’t take up the entire box, neither of which looks very aesthetically pleasing.

Square has been designed to make characters fill a square space as evenly and uniformly as possible. It is inspired upon the way Japanese characters always evenly fit a box, no matter their design. It foregoes the typical ascenders/descenders in lowercase characters, and instead makes lowercase characters look like a lighter version of uppercase characters.

Square font

Cross-site duplicates:

I've also found many other fonts on the same category although I didn't have a chance to test them

square fonts example


However if your texts are limited to a small character set (specifically ASCII 21 to 7E plus a few East Asian characters) then you can just use full-width form directly without the need of another font

Below is a small shell script to do the conversion from halfwidth to fullwidth. The string to convert is read from standard input

halfwidth='!"#$%&'\''()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⦅⦆¢£¬¯¦¥₩ '
fullwidth='!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⦅⦆¢£¬ ̄¦¥₩ '
sed -e "y/$halfwidth/$fullwidth/"

Example

$ cat square.txt
0123456789
1-square 8
2####text7
3$$$$$$$$6
4@@@@@@@@5
5(SQUARE)4
6~~~TEXT 3
7>>>2
8////\\\\1
9876543210

$ cat square.txt | sh fullwidth.sh 0123456789 1-square 8 2####text7 3$$$$$$$$6 4@@@@@@@@5 5(SQUARE)4 6~~~TEXT 3 7<<<<>>>>2 8////\\\\1 9876543210

The result may not be perfect squares in many cases due to the font, so you may still need to check for a font with square fullwidth characters on your system if the aspect ratio doesn't fit your requirements

phuclv
  • 30,396
  • 15
  • 136
  • 260
2

Create a square mono-spaced font from Courier using your favourite font-editor. Use that in your Terminal.

If you lack the patience for font editing and have charisma (or something) you can do this instead.

The intertubes suggested this to me but maybe it isn't really square.

1

I was looking for a font to use with the python QR code generator. It seem that this library assumes a precise height:width character ratio of 8:7, so the square fonts above actually produced a QR code wider than it was tall. On my Mac, the Andale Mono font at a point size of 14 or 28 produces perfectly square QR codes. In the iTerm window shown below, for example, the QR code is exactly 168:168.

enter image description here