• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    C
  • License
    ISC License
  • Created about 6 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extensible, lightweight terminal text editor with syntax highlighting and plugin support.

Bim - A Text Editor

screenshot

Bim is a terminal text editor with syntax highlighting.

Inspired by Vim (one might say a Bad Imitation) and featuring similar mode-based editing, Bim was originally written for ToaruOS, but it has also been tested in Linux, Sortix, FreeBSD, and macOS.

Goals / Purpose

Bim is intended as the included text editor in ToaruOS, a hobby operating system built from scratch.

Bim aims to be lightweight and featureful with no external* dependencies, providing a modern editing experience in a lightweight, extensible package.

Features

  • Vim-like modal interactions.
  • Arrow-key and traditional vi hjkl navigation.
  • Syntax highlighting (currently for C/C++, Python, Makefiles, Java, Rust, and a few others).
  • Integrated scripting environment with Kuroko.
  • Themes, including 256-color and 24-bit color support.
  • Indentation adjustment and naïve automatic indentation.
  • Multiple editor tabs.
  • Basic Unicode support (sufficient for things like Japanese, but not capable of more complex scripts).
  • Efficient screen redrawing.
  • Terminal support tested in ToaruOS, Sortix, xterm, urxvt, Gnome, XFCE, Linux and FreeBSD consoles, macOS Terminal.app, iTerm2.
  • Mouse support in Xterm-like terminals.
  • Line and character selection, with yanking (paste buffer).
  • Incremental forward and backward search with match highlighting, smart case sensitivity, some regex support.
  • Undo/redo stack.
  • Highlight matching parens/braces.
  • Multi-line insert mode.
  • Persistent cursor location between sessions.
  • Git integration, shows git diff status in-line, along with unsaved changes.
  • Convert syntax highlighted code to an HTML document.
  • Split viewports to view multiple files or different parts of the same file.
  • Simple autocompletions using ctags.

Build Requirements

Bim requires a sufficiently Unix-like C library and a C99 compiler with certain GNU extensions (such as __attribute__((constructor))).

Bim 3 also needs Kuroko, which has has similar requirements. Bim is typically statically linked with the Kuroko interpreter for Linux builds, and dynamically linked for ToaruOS builds.

Bim has been built successfully for a number of targets, including various BSDs, ToaruOS, Sortix, and others.

Installation

First, install Kuroko:

git clone https://github.com/kuroko-lang/kuroko
cd kuroko
make && sudo make install # You can obtain deb packages, or build one with 'fpm' with 'make deb'

Then build Bim:

git clone https://github.com/klange/bim
cd bim
make && sudo make install

Then install the example config:

cp docs/example.bim3rc ~/.bim3rc

Terminal Support

Bim has been tested in a number of terminals, and while it does not use terminfo databases, basic functionality should be available in the vast majority of remnant emulators and even classic DEC hardware.

If the terminal you are using has some quirks or does not play well with the default assumptions, you can modify the behavior to suit your environment.

Capability features can be controlled with "quirks", either through the quirk command in a bimrc, or with the -O command line option.

The format of the quirk command is quirk(envvar,teststr,'no...','can...',...) where ENVVAR is the name of an environment variable and teststr is a string to check against which must be a prefix of the environment variable.

For example, quirk('TERM','xterm','nounicode') will disable Unicode output on all terminals starting with "xterm" (including "xterm-256color").

You may also specifies quirks with the $COLORTERM environment variable, or the $TERMINAL_EMULATOR variable set by certain IDEs.

Some example quirk configurations are provided in docs/example.bim3rc and may be a good place to start if you are experiencing rendering issues.

Unicode/UTF-8 support is recommended and assumed by default. The nounicode quirk option will disable output of UTF-8 characters and render them as codepoint hints like <U+1234> instead.

256-color and 24-bit color are also assumed by default, disable them with the no256color and no24bit quirks respectively.

If you have a particularly low-color terminal, the nobright quirk will hint to themes that only the lower 8 colors should be used.

Three scroll modes are supported: shift scrolling, insert/delete scrolling, and redraw scrolling.

Shift scrolling (^[[1S/^[[1T) is assumed by default. If your terminal supports insert/delete scrolling (^[[L/^[[M), enable the caninsert quirk.

If neither scrolling option is available, use the noscroll quirk to redraw the text field when scrolling. This will probably be slow!

Mouse support with ^[[?1000h is assumed by default. Use the nomouse quirk to disable it.

If your terminal supports SGR mouse modes ("1006"), enable the cansgrmouse quirk. Most xterm-like terminals support this and it will provide support for click on cells in larger terminal windows.

Alternate screen support is also assumed. This is normally fine even if your terminal doesn't support it, but if it causes issues the noaltscreen quirk will disable it.

Key Bindings

Default keybindings can be found in docs/mappings.md.

This listing can be generated with bim --dump-mappings.

Commands

A complete listing of available commands can be found in docs/commands.md.

This listing can be generated with bim --dump-commands.

Additional Bim Functionality

You can use Bim to display files in your terminal with syntax highlighting with bim -c (no line numbers) and bim -C (with line numbers).

screenshot

You can pipe text to bim for editing with bim -. Note that Bim will wait for end-of-file before launching, so this is not suitable for use as a pager (pager support is planned).

Bim can also be used to generate HTML documents with syntax-highlighted source code with bim --html; the configured theme will be used.

Themes

Bim includes a handful of color schemes for the interface and syntax highlighting.

ANSI

A plain 16-color theme. Can be configured for use on terminals with or without bright color support. Looks a bit like Irssi.

ansi

Sunsmoke

An original 24-bit color theme with rustic browns and subdued pastel colors.

sunsmoke

Sunsmoke-256

A 256-color version of Sunsmoke for use in terminals that do not support 24-bit color.

sunsmoke256

Wombat

A 256-color theme based on the theme of the same name for Vim.

wombat

Solarized Dark

A 24-bit color theme based on the popular color palette.

solarized-dark

City Lights

A 24-bit color theme based on the one for Atom and Sublime, featuring low contrast blues.

citylights

Light

Based on selenized by Jan Warchoł

light

Config File

Bim will automatically import ~/.bim3rc on startup.

A detailed bimrc example is available at docs/example.bim3rc.

Bim scripts are written in Kuroko.

Syntax Support

Not all syntax highlighters are complete or support all features of their respective languages.

  • C/C++
  • Python
  • Java
  • diffs
  • Generic INI-style config files
  • Rust
  • git commits and interactive rebase
  • Make / GNU Make
  • Markdown (with some inline code highlighting support)
  • JSON
  • XML / HTML
  • Protobuf
  • Bash

Code Structure

Bim's core functionality lives in bim.c.

Syntax highlighters and themes are written in Kuroko and found in the syntax and themes directories.

Regex Syntax

Bim's regular expression engine is something I cooked up haphazardly. Its functionality is somewhat limited and behavior is subject to change.

  • Search matching is on a single line. Multi-line matching is not implemented.
  • Some characters with special meaning can be escaped with \.
  • ^ matches the start of a line, $ matches the end.
  • . matches any character.
  • [] brackets can be used for alternative matches.
    • ^ as the first character negates the match.
    • Use a-b for simple ranges.
    • To include - in a bracket expression, place it before any other character but after a negating ^, such as [-_*].
    • To include ^ in a bracket expression, use it any position after the first. [^^] means "anything except ^".
    • To include ] in a bracket expression, use \].
    • Tab characters may be represented as \t. Use \\ for a literal backslash.
  • ., [], and single characters may be combined with the following, with backtracking:
    • ? optionally matches once.
    • * matches any number of occurances.
    • + matches at least on occurance.
    • * and + are greedy by default, but can be followed with ? to make them non-greedy.
  • () parentheses can be used at the top level for capture groups.
    • Up to 9 capture groups will capture for replacements.
    • Parentheses may be nested, but nested groups currently do not capture.
    • Capture groups can not be combined with repetition operators (but repetition operators can be used within them).

When performing replacements, some escape sequences are supported:

  • \t inserts a tab character. \\ inserts a literal backslash.
  • \0 inserts the entire matched string.
  • \1 through \9 insert captured groups.

Bim is not Vim

Some interactions in Bim work differently from Vim, and sometimes this is intentional. Bim's primary interactions are built around a selection, while Vim has verbs and navigation nouns. CHAR SELECTION does not let the cursor move past the end of the line, unlike VISUAL mode in Vim.

Bim wants to be more like Vim

Some interactions in Bim work differently from Vim, and sometimes this is unintentional. Bim is missing many features I would like to implement, like regular expression search (and replacement).

License

Bim is released under the terms of the ISC license, which is a simple BSD-style license. See LICENSE for details.

Development

Bim is still primarily developed alongside ToaruOS. This repository is a mirror with fake history going back to the start of that project. Pull requests merged here will be patched into ToaruOS.

Community

If you're using Bim, want to contribute to development, or have ideas for new features, join us in #bim on Libera.

More Repositories

1

toaruos

A completely-from-scratch hobby operating system: bootloader, kernel, drivers, C library, and userspace including a composited graphical UI, dynamic linker, syntax-highlighting text editor, network stack, etc.
C
5,759
star
2

nyancat

Nyancat in your terminal, rendered through ANSI escape sequences. This is the source for the Debian package `nyancat`.
C
1,397
star
3

ponyos

My Little Unix: Kernels are Magic!
C
497
star
4

taylor

Swift on bare metal. Explorations of compiling Swift code without a standard library.
Shell
183
star
5

cgiserver

A simple CGI webserver written in C with no dependencies.
C
102
star
6

toaru-nih

NOTICE: The ToaruOS-NIH Project has been MERGED UPSTREAM. This repository is now archived.
C
68
star
7

hobby-os-landscape

A guide to hobbyist operating systems
55
star
8

assholedoth

[satire] A complete language backed by C++
C
21
star
9

toarucc

(wip) toaru c compiler
C
17
star
10

generate-copyright

tool to generate copyright lines for files from git history
Shell
15
star
11

pocketmiku

Linux tools and Python package to control a Pocket Miku
Python
15
star
12

tales-of-darwinia

Nintendo DS homebrew game
C++
12
star
13

mboot-kernel

Demo multiboot kernel
Assembly
10
star
14

toaru_jpeg

C rewrite of a minimal Python JPEG decoder
C
10
star
15

SDL

MIRROR of SDL (1.2) with additional とあるOS bits
C
9
star
16

tsundere.me

I'm- I'm not making this web API because I like you or anything!
HTML
9
star
17

resume

The source for my CV/résumé, in LaTeX and Python scripts.
Python
8
star
18

esh

ToaruOS's "Experimental SHell"
C
8
star
19

toaru-rpi

Abandoned とあるOS Raspberry Pi port
C
7
star
20

isla

yet another dumb irc bot, sorta conceptually based on hubot; dead-simple regex-based plugins
Python
7
star
21

cs421

UIUC CS421 MPs
OCaml
6
star
22

uiharu

(WIP) Attempt at an HTML rendering engine
6
star
23

pyrail

Minecraft / Railcraft / Computercraft automated train system server in Python
Lua
6
star
24

webvn

Pure CSS/HTML5 visual novel generator
HTML
5
star
25

toaru-playmp3

MP3 player for ToaruOS using minimp3 (also builds libminimp3.so)
C
5
star
26

amppy

Python rewrite of Acoustics Media Player, a web-based jukebox and music browser.
JavaScript
5
star
27

Python-Asteroids-Clone

Python asteroids clone written during the Spring of 2008 for the Strongsville High School Computer Club
Python
4
star
28

cs418

Various machine problems from UIUC CS418
C
4
star
29

pyqtschema

Tool to generate Qt forms from JSON schemas.
Python
4
star
30

nyancat-opencomputers

Port of nyancat-cli to Lua/OpenComputers for Minecraft
Lua
3
star
31

scootaloo.in

An HTML5 <audio> and CSS @keyframes animation demo.
CSS
3
star
32

toaru-boot

[DEPRECATED] This repository has been merged into toaru-nih
C
3
star
33

toaru-opengl

OpenGL demos previously shipped with ToaruOS (as well as build tools for Mesa)
C
3
star
34

firesdl

Mirror/Fork of David Ashley's SDL fire demo
C
3
star
35

glass-scouter

Joke app for Glass. Adds a voice trigger for "what does the scouter say about his power level".
Java
3
star
36

sdlquake

mirror of sdlquake with some toaruos patches?
C
3
star
37

toaru-pdfviewer

Hacked up port of `mudraw` from the MuPDF package, to render PDF pages under とあるOS
C
2
star
38

aoc2021

Python
2
star
39

Audacious2-Xchat2-plugin

Control Audacious2 from Xchat2
2
star
40

niterm

Japanese framebuffer terminal for Linux (fork of bogl term with embedded Anthy)
C++
2
star
41

toaru-vidplayer

libav video player for とあるOS
C
2
star
42

toaru-netboot

Tools to make netboot images for ToaruOS
C
2
star
43

toaru-art

SVG sources for some ToaruOS assets
2
star
44

acoustics-art-blob

GTK3 tool for displaying "now playing" data from Acoustics, including album art.
Python
2
star
45

snesdev

some experiments with maybe building a snes game in C
C
2
star
46

toaru-build-tools

This is repo is old and outdated. Docker scripts for setting up a toolchain to build ToaruOS are now in the main repo: https://github.com/klange/toaruos/tree/master/util/docker
Shell
2
star
47

text_adventure

Python Text Adventure (teaching demo)
Python
1
star
48

klange-dev-photo

photography portfolio website
CSS
1
star
49

pycairo

Fork of upstream pycairo (Cairo python bindings), for ToaruOS
C
1
star
50

isitearlyaccessyet

isitearlyaccessyet.us
JavaScript
1
star
51

pheap

intrusive pairing heap
C
1
star
52

prboom

MIRROR of prboom with hacks to get things working in とあるOS
C++
1
star
53

toaruos-grub

Legacy tools for building GRUB rescue images with ToaruOS
Makefile
1
star
54

cs440-hw

Various homeworks from UIUC CS440
Python
1
star
55

aoc2020

Python
1
star
56

acoustics-desktop

Acoustics Media Player desktop utilities (mostly Python scripts)
Python
1
star
57

aoc2022

Python
1
star
58

acoustics-windows

Acoustics now-playing and taskbar controller for Windows 7.
C#
1
star
59

nyancat-cc

nyancat-cli ported to CC:Tweaked
Lua
1
star
60

ksdots

my dotfiles
Vim Script
1
star
61

klange.github.io

JavaScript
1
star
62

motodr

Mitsuba EDR GPS extractor
Python
1
star