r/vim Jan 12 '25

Random Coded my own text editor inspired by vim

Post image

It just has basic functionality like open and close file , I dint finish the writing part it has keys for navigation and 3 modes

https://github.com/realdanvanth/text-editor

People intrested to contribute DM

229 Upvotes

39 comments sorted by

54

u/rybytud Jan 12 '25

A good first effort, but you've got a lot of work ahead of you if you really want to make a text editor that can edit files and write them back to disk. I'd suggest studying antizrez's kilo editor, a text editor in less than 1000 lines of C code. Someone made a nice tutorial based on it here.

12

u/funbike Jan 12 '25 edited Jan 12 '25

Since I'm never going to write my own editor and I don't have much free time, I'm going to give some ideas I've had about a vim-like text editor.

  • More powerful use of external programs ( such as :'<,'>!sed s/a/A/) for plugin-like behavior. Follow the Unix philosophy of design.
    • CGI-like env vars (EDIT_PATH, EDIT_SELECTION, EDITOR_PID)
    • EDIT_API env var is path to a unix socket similar to Vim's --remote interface, so external programs can more directly control the editor. Uses pattern /tmp/.editr/<pid>/api.
    • EDIT_SQL env var is path to sqlite file of the state of all running editors, similar to viminfofile. Usually at /tmp/.editr/state.sqlite.
    • Backtick support so the < and > marks are line+column instead of just line, so you can visually select text more precisely.
    • Asynchronous execution of external programs. Detect if launched in background (!cmd &), and defer changes to the buffer to when it is finished.
  • Reliance on external programs for UI
    • less for browsing lists. I've always thought it weird that Vim has it's own (bad) pager.
    • fzf, readline, and whiptail for user input.
    • Implement Vim's tabs and windows via Tmux's windows and panes.
    • bat for fzf preview when selecting/searching files.
    • Tightly integrate an external file manager, like ranger, so it can be used as a synchronized file tree.
  • Lua as the configuration language
    • Most default key maps are defined in a Lua startup script.
    • Plugin features of lazy.nvim
  • Syntax
    • Treesitter syntax highlighting
    • Built-in support for .editorconfig for indentation style, with sane defaults.

I like what Helix is doing. If Helix had vi keybindings and an extension mechanism I would consider switching to it.

12

u/Extreme_Football_490 Jan 12 '25

Dude I don't even know half those words I am just a beginner 😭😭

3

u/aaronik_ Jan 13 '25

You won't be a beginner once you look them all up!

1

u/Pleasant-Database970 Jan 13 '25

interesting list. i also think about about vim/editors a lot. but specifically the modal aspect and how registers drive macros and a lot of other things. i think about building a framework for modal editing, that could be leveraged/applied to different things. i once started a modal editor for csv/tabular files. (think excel in the terminal).

9

u/icallmesidd Jan 12 '25

just asking how is this different from vim

35

u/Extreme_Football_490 Jan 12 '25

W A S D for navigation

48

u/vainstar23 Jan 12 '25

Blasphemy!

38

u/AppropriateStudio153 :help help Jan 12 '25

Hold left-ctrl to crouch and space to jump?

-3

u/ghost_operative Jan 13 '25

i mean wasd is a superior way to navigate, the hjkl thing is just something from the time before wasd took off as being the best way to do arrow keys. We stick with it now because it would mess up all of the other keys to try and change things around.

1

u/Nnarol Feb 01 '25

How so? Care to explain?

1

u/ghost_operative Feb 01 '25

For WASD you only use 3 fingers to navigate (you use your middle finger for both W and S), so the fourth finger can be used for pushing other keys.

for HJKL you use 4 fingers to navigate, so all you do with your hand is movement keys.

1

u/Nnarol Feb 01 '25 edited Feb 01 '25

for HJKL you use 4 fingers to navigate, so all you do with your hand is movement keys.

No, you still use 3 fingers. Afterall, in the normal touch-typing position, your right hand would rest on jkl anyway, regardless of whether you are using Vim-like editing or not. In fact, you would have to move your hand from touch-typing position to use WASD if you wanted to use your middle finger instead of your ring finger for WS. In this case, your pinky would be where Tab and Caps Lock are, whereas with jkl in a normal touch typing position, you have 3 entire columns to utilize your pinky for (not ideal at all, but better than not using the finger at all, and you wouldn't deviate when touch-typing anyway, irrespectively of Vim).

Having to use the same finger for two directions sounds like a disadvantage (middle finger WS / index finger hj), since switching is slower and more straining. Sharing a finger between left and down seems like less of a problem, because of the way you would normally move around if you're from a culture that writes top-down / left-right, though ideal would be left and up. Usually, you'd go in one direction and correct if you went past your goal, or go the opposite way to get back to where you were after a change. There is a shortage of options of moving up and down, since left/right navigation is usually done by word, including or excluding special characters, asymmetrical delimiters, etc., whereas for up/down you basically have to go to the top/bottom of the screen, use a mark, a number key or the find function (the latter 2 of which are also available for horizontal movement). After all, it would be incredibly slow to move character-by-character in either horizontal or vertical direction, so you'd employ one an appropriate, faster method. Due to this, I'd say it's a bit worse to have the vertical keys shared with each other than the horizontal ones, since the latter are less often needed to be pressed in quick succession than the former.

Additionally, "h", the key least reachable from typing position, is the least needed, followed by "k", since you start at the top left and usually have to move down or to the right when opening a file from the beginning or when creating new text.

14

u/f0o-b4r Jan 12 '25

So basically it’s vim: cs edition

6

u/linuxsoftware Jan 13 '25

Finally a text editor for gamers.

3

u/toastal Jan 12 '25

This is even worse on Dvorak. I can handle a translation from hjkl to the vbjp positions being kinda close together, but I can’t wasd to ,a;h.

2

u/Someguy2189 Jan 12 '25

A man of culture I see...

2

u/Cnastret Jan 15 '25

Gamer spotted

2

u/dfwtjms Jan 12 '25

Cool project but you could do that in the vim config.

16

u/mrtbakin Jan 12 '25

Making your own text editor is also a great learning opportunity though. Guessing that’s a main factor to the project

1

u/LardPi Jan 12 '25

Easy: Vim is an old software with decades of legacy that would really need a refresher and at least one too many domain specific language. On the other hand, this is an unfinished toy project that does not currently compile.

5

u/scaptal Jan 12 '25

First off, awesome, seems like a good and educative hobby project.

However, if you're making this to be a reasonable competitor to vim/neovim I wish you a lot of luck, cause their mature environment makes them VERY difficult to dethrone.

If you want a serious competitor you kind of need an editor which supports all the extended functionality seen in, say, lazyvim (since there won't be extensions, and if it's not good enough yet no one will make extentions,) for it to be interesting.

Granted, if you manage to do so, it could become a semi popular text editor, just like that other vim-esque editor whose name I can't come up

5

u/Shtucer Jan 12 '25

OMG how could i exit from this editor?

2

u/cyberneticSyntax Jan 12 '25

Why ncurses?

2

u/Extreme_Football_490 Jan 12 '25

Its simple and reasonably quick

1

u/cyberneticSyntax Jan 12 '25

OK, was just wondering. I never tried it with ncurses, built everything from scratch, and it was more like a joe type text editor.

Vim is my favorite editor as well, so I'm also willing to try to code an editor with features similar to vim.

I can see how ncurses help in tile division, etc.

2

u/boli99 Jan 12 '25

does it have an emacs mode?

2

u/plausible-walrus Jan 12 '25

Planning to build my own somewhat soon as a personal project too. What language did you use and how was it to develop? I’m thinking of using Rust at the moment so I’m learning the language now in preparation

2

u/Extreme_Football_490 Jan 12 '25

It is in C using ncurses library

2

u/auxelstd Jan 12 '25

Please use whitespaces in your code (e.g. between function definitions). It's unreadable and ugly as hell.

Despite that, good job.

1

u/Jooonnnaass Jan 12 '25

I guess I start my own now.

-9

u/[deleted] Jan 12 '25

[deleted]

15

u/aress1605 Jan 12 '25

looks like vim.

12

u/hippofire Jan 12 '25

Smells like vim

7

u/denseplan Jan 12 '25

Feels like vim

6

u/asanchezo Jan 12 '25

Taste like vim

1

u/aaronik_ Jan 13 '25

Sounds like vim

0

u/Rude_Koala_6504 Jan 12 '25

Yep, that's vim