Coder Social home page Coder Social logo

klange / bim Goto Github PK

View Code? Open in Web Editor NEW
281.0 14.0 17.0 2.23 MB

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

License: ISC License

Makefile 0.46% C 71.96% Python 27.58%
text-editor vi-clone terminal-based syntax-highlighting c linux toaruos editor modal-editing code-editor

bim's Introduction

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.

bim's People

Contributors

klange avatar nexos-dev avatar nielsdos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bim's Issues

Tab bar does not handle overflow

When too many buffers are open, the tab bar will be cut off. It should scroll horizontally to ensure the active buffer is visible, and also indicate when more tabs are available to the left or right off screen (as a line does).

bimrc can cause bim -C to print a misrendered status bar

Some bim commands like tabs and spaces cause the status bar to be redrawn. However when using bim -c or bim -C and the ~/.bimrc file contains these commands, this results in an incorrectly rendered status bar on the top of the output.

To reproduce use a .bimrc file with the following contents and then print a file using bim -C:

function onload:*
    spaces
end

Assembly syntax and relative numbers justify

Hello, first of all I wanted to thank you for making such an amazing and lightweight editor.

I would like to suggest 2 things:

  • Assembly syntax for .asm and .s files. I would like to see intel syntax and I also think it would be easier to implement, but obviously that's up to you.
  • Justify the current line number to the left when relativenumbers=1. For example in vim it's displayed like this, and I think it is more readable (of course you could just add an option to toggle justify):
    image

Add option to shift whole screen horizontally on long lines

Currently, only the highlighting line is scrolled horizontally when it is too long. An option should be added to scroll the whole screen. Needs some checks whenever the coffset is changed to redraw other lines; needs global config option; needs changes to redraw_line to always use coffset when the flag is set.

Understand comments when autoindenting

Sometimes we have code like:

if (foo) { /* Do a thing */
    bar();
}

We don't handle indentation for this correctly because we don't see that the previous line ended in a {. We should backtrack through the comments (FLAG_COMMENT) and whitespace to find the { or :.

Implement viewports / splits

There's technically nothing really stopping us from showing multiple views of the same open file, to allow for things like splits, but there's some rendering and mouse input handling to worry about. We'll probably want to disable scrolling, or look into supporting scroll regions in ToaruOS's terminal as well...

Syntax hilighter support checklist

  • C/C++
  • Python
  • ToaruOS Esh
  • Make
  • bimrc
  • gitcommit, gitrebase
  • diff
  • rust
  • ToaruOS conf files (ini, .conf)
  • Java
  • XML
  • JSON
  • Bash/Unix sh
  • Markdown (.md)
  • HTML
  • Protobuf (.proto)

Break out commands into functions

Commands should be registered functions with descriptions, perhaps in two sets (regular commands and prefix commands, to handle s/...). The registered function list can be used for syntax highlighting.

Refuse to load 24-bit color themes in terminals we know they won't work in

Some terminals happily accept 24-bit color escapes but render oddly. Some end up dumping the escapes to the screen - those ones in particular we should try to catch and default back to the ansi theme.

This can also possibly be done for 256-color themes in a handful of places - all 16-color-only terminals should probably be forced to the ansi theme or other future 16-color-only themes.

Support terminals without "bce"

"bce" - background color erase - is currently an expected feature and allows us to quickly fill the rest of a line with the current background color. Some terminals don't support it - tmux in particular is known to not support bce. A nobce option should be added which clears the rest of the line, but this requires some work in certain places where we clear to end without being fully aware of the cursor position.

Implement block selection mode

Vim has a "VISUAL BLOCK" mode that would be nice to replicate - it's kind of a light version of multiple cursors as well.

Restructure syntax highlighters

Currently, all of the syntax highlighters are in the main source file and they have a lot of duplicated code. Shared functionality (like "double quoted strings", /* comments */, etc.) should be broken out into macros and the syntax files should be separate C sources.

Eventually, I would like to have syntax definitions as a series of matching scripts - possibly regex, but I need a regex compiler upstream in ToaruOS for that...

Ideas for Improving ctags Support

  • Parse the extended data from "format 2"
  • Exclude locals from other files - should be easy, just ignore stuff with the l extended type when file isn't us
  • Exclude locals from other functions - can we figure out what function we're in without too much parsing hassle?
  • Try to figure out types of struct objects so we can complete struct members after . or ->

Consider backporting fixes from Bim 3 to Bim 2.x

A number of fixes have been made to Bim 3 that should be applicable to pre-Kuroko codebase. It would be nice for users looking for a small "pure C" editor to have these bugfixes, several of which were crash fixes.

Rewrite modes to not be function calls

Right now, modes like insert work by normal mode calling insert_mode() and waiting for it to return. Let's rewrite the mode interactions and move all of their state into individual buffers so that we can have a centralized place for obtaining input and then calling the modes.

A handful of modes have submodes which will necessity a sort of "stack" of modes, such as when collecting a verbatim character.

Break out source into multiple files

Bim being a single C source file is a legacy holdover from ToaruOS's build system. Bim (~6850) is the largest application in ToaruOS at over twice the LoC of the compositor (~2750), and as such stands as an outlier for the single-file build system. While Bim's large size is useful for dogfooding, it has become unruly to manage and navigate, and some elements such as syntax highlighters and themes offer clear opportunities to break things up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.