13 ms·
Ki Editor - an editor that operates on the AST
- armchairhacker 7mo agoVim-like (terminal and VSCode extension) that prioritizes syntax-based navigation. Comparison to Vim and Helix: https://ki-editor.org/docs/comparison#user-content-fn-1 https://ki-editor.org/docs/comparison#user-content-fn-1
- worksonmine 7mo agoThat comparison table is strange and sometimes wrong. Neovim for example detects and updates external file changes by default. And the coherence of the keybindings in Ki is "Great" bit vim/helix: > As you can see, there's no single logical categorization for these keymaps, they are either lowercase-uppercase, normal-alt, left-right bracket, or outright unexplainable. Word, End, Back, Change Word and even Change Inner (, etc are very logical to me and I feel like I'm talking to the editor when editing. I get that it doesn't make sense when one has learned another way to do it, but it does make total sense you just have to make an effort to try and understand it. It's like learning and always driving automatic then calling manual "outright unexplainable". You simply learned another way and are conditioned into believing that's the one true way. It shows the creator comes from VSCode (multi-cursor is a useless feature, just use s/search/replace and get used to macros and a whole new world will open).
- pbronez 7mo agoI had an experience like this when I switched to a Keyboardio split keyboard. It was impossible to use at first. Then I do some deliberate practice with a typing tutor app and now I love it so much I own multiple. Is there a good tutorial for some of these advanced text editing features? In particular I’d like to get platform independent shortcuts / key bindings. I use both windows and MacOS daily, and it throws off my muscle memory for shortcuts like “go to beginning of line”
- davidee 7mo agoI think you've touched on it, but I'm going try to take it one step further into explicitness. Just over a year ago I decided to switch to Neovim. The reason for switching was personal; I was struggling with what I'll call "clutter" in other tools and I wanted a tool that would reinforce, at least lightly, a mode of working that promoted focus on what I was working on, while making it easy to reference other files without loading up my editor with tabs and other visual clutter (buttons/menus) I don't care about most of the time. I took the advice I seemed to bump into repeatedly: try out vim mode in my current editor before making the plunge. I really struggled at first. It felt wildly foreign. All the shortcuts were nowhere near to the world I was familiar with. As I was about to give up, I ran into some advice that was along the lines of "stop trying to memorize shortcuts and start thinking in terms of what you want to achieve" (words and motions in vim-speak). Your example of [C]hange [I]nner is a great one; that one in particular was life changing. Sure there are some words and motions that do require memorization, but so many others just flow naturally. And once you start thinking in actions, it's easy to see how they can layer on top of each other in really elegant ways. I'm not even here trying to tout vim-like editors, I'd wager there are many editors that have some semblance of this kind of interaction, but rather to reiterate there's a shift from a PoV of function vs. goal. Again, I don't think this is "the right way" but rather one of many perspectives that works in context with the phenomenology of me.
- hou32hou 7mo ago> It shows the creator comes from VSCode Hey, one of the creators here, I actually daily drove Neovim for two years, before switching to Helix for a while, then finally Ki. > multi-cursor is a useless feature I was a Neovim macro user until I figured out how insane that was compared to multi-cursor after using Helix.
- cassepipe 7mo agoI still think their point about search and replace still stand though. I make most my edits with regex in neovim nowadays and I feel this is the superior paradigm: You don't even need to get to some specific location in order to edit it. I also almost only use search to move around the file and I can even reuse the searches for substitutions. It makes most vim motions and commands almost useless for me nowadays. I also feel like macros are a more clunky and error prone way to do what substitutions can do. Almost never use them.
- gorjusborg 7mo agoYeah, macros are definitely helpful at times, but not as much as one might think. I think the same goes for multi-cursor, though.
- worksonmine 7mo ago> I was a Neovim macro user until I figured out how insane that was compared to multi-cursor after using Helix. Multi-cursor was the first plugin I installed when I moved from VSCode to Vim because I was used to hitting Ctrl+d to select all words and then replacing. Does Helix do something different? 1) First I reach for <C-v> for visual block selection if everything is neatly aligned. 2) Next choice is %s/search/replace(/c if I need confirm). 3) Macros, and I love it everytime I get to use them. I just record the movements, copy what I need to copy, paste it where I need to paste it, and it's repeatable for every line or block where the *formatting* matches. And this is the important part, the words don't matter. I still feel like a wizard using them. As far as I understand multi-cursor option 3 is a no-go without macros if the words don't match. But macros don't care as long as the movements translate to the same edits. How does Helix multi-cursor work that make macros insane?
- teo_zero 7mo agoRe. incoherence of vim's keybindings, I partially agree. Most of the times, shift means "bigger", and only in a few places it means "invert". Examples of "bigger" are all the motions involving words vs. WORDS, where WORDS are a broader interpretation of words; "V" is like "v" but by lines, thus in larger chunks; "C", "D", "Y" do the same as their unshifted counterparts, but extended to the end of line; etc. Examples of shift meaning "invert" are fewer, and all sound irrational to me: With x/X and o/O, the shift inverts the direction left/right or above/below, but we don't have for example i/I to insert to the left/right of the cursor, and H is not the opposite of h, J is not the opposite of j, etc. With n/N, shift inverts next and previous. Why not n/p? I know, I know: p was already taken for paste, but still... Finally, t/T/f/F are completely mixed up. In my mental model, t/f sound like to/from and I'd rather use them to move forward/backward till (not including) a char, while T/F would be the "bigger" variants which include the destination char.
- Izkata 7mo agoi/I is because we already have a, and A is a super-a in the same way I is a super-i.
- hrmtst93837 7mo ago[flagged]
- shashurup 7mo agoIn my classification of editors: 1. Orthodox. Mostly focused on looks and integrations. 2. Modal, Vim improvement. Focus on keeping basic Vim keybindings with minor improvements. 3. Modal, rethinking Vim approach. Ki falls into the third category which I constantly monitor.
- noosphr 7mo ago4. All of the above. Which is Emacs.
- skydhash 7mo agoVim is Emacs applied to Vi
- School-Cotton 7mo agoNot even close.
- skydhash 7mo agoHow is it not? Scripting language? Check! Custom commands? Check! Windows management? Check! Build tools integration and error-based navigation? Check! File manager? Check!
- johnisgood 7mo agoOperating system? Check or not? :D
- skydhash 7mo agoVim has stopped before that particular threshold. But if ever Neovim get a GUI version, I believe the community will soon have its own Gnus, Eww, and EMMS.
- antiframe 7mo ago
- scriptsmith 7mo agoThe "First-class syntactic selection" reminds me of my most used shortcut(s) in Jetbrains IDEs: the Expand / Shrink Selection. Ctrl + W Ctrl + Shift + W https://www.jetbrains.com/help/idea/working-with-source-code.html#editor_code_selection https://www.jetbrains.com/help/idea/working-with-source-code... It really changed my perspective on interacting with the 'text' of a file. VS Code, Zed, etc. have similar operations, but in my experience they expand and shrink too coarsely.
- enkursigilo 7mo agoAlso available as `incremental selection` in Neovim via tree-sitter.
- hudsonwillis 7mo agoyep and most of these actions can be implemented with simple mappings based on https://github.com/nvim-treesitter/nvim-treesitter-textobjects https://github.com/nvim-treesitter/nvim-treesitter-textobjec...
- parallax_error 7mo agoThis has got to be my favourite feature of IntelliJ, along with the dumb context actions menu
- mystifyingpoi 7mo agoI agree, top feature. Combined with things like "extract method" makes mundane refactorings super fast.
- chamomeal 7mo agoI use it constantly in helix too. The vscode one is meh. I think I saw a discussion in github once about switching to tree-sitter, which would improve AST-related actions. I don't think it went anywhere though. I love AST aware editing. I think it's one reason it's always been so nice to edit lisps. Stuff that is complicated to describe in javascript (and doesn't have LSP support) p much requires a whole AST parser, but in lisp it's just a simple list operation. When I go back typescript after a weekend of clojure, I reeaally miss slurp! and other paredit commands
- hwhshs 7mo agoWhy not a vim plugin
- hou32hou 7mo agoWe have one underway in https://codeberg.org/alicealysia/ki-bindings.nvim https://codeberg.org/alicealysia/ki-bindings.nvim
- cassepipe 7mo ago> Note that the Ki keybindings cannot be simply implemented in Vim/Helix via key- remapping, due to the lack of the concept of Selection Mode, and implementing that requires major architectural changes in the core.
- 0ta2x6j3 7mo agoNot by default, and it's not a neat and tidy solution, but you can rebind keys as a result of inputing other keys in neovim via a callback (and edit the statusbar ofc to display said selection mode) This, alongside the use of a variable means you can, in fact, build your own selection modes! Likewise, nvim does have a seperate select and visual mode. This is primarily designed as an option to replicate the more traditional shift+movement selection and type to replace functionality of something like vscode or notepad, however it can be exploited as an additional layer for storing keybinds in a pinch
- 0ta2x6j3 7mo agoIt's funny you mention that. I am currently working on a neovim plugin which implements the ki-editor keymap. https://codeberg.org/alicealysia/ki-bindings.nvim https://codeberg.org/alicealysia/ki-bindings.nvim Unfortunately however, there's some shortcomings of neovim which make its control scheme impossible (at least not without some workarounds) One of the biggest is ki's momentary layers feature. Ki uses the kitty keyboard protocol to detect when a key is being held and when it is released in order to allow for unique actions when multiple keys are pressed simultaneously, and this functionality is a big part of what makes it so ergonomic. For example, tapping c will copy the currently highlighted text, but pressing c and k simultaneously will duplicate the currently selected text to a new line below the current line. While I'm currently chipping away at a pull request to introduce similar functionality to neovim itself, in the meantime, I'm needing to work around the issue by making a lot of concessions.
- Myzel394 7mo agoI'll wait till an Emacs package is available
- reedlaw 7mo agohttps://github.com/mickeynp/combobulate https://github.com/mickeynp/combobulate
- okayokay123 7mo ago[dead]
- evelant 7mo agoI made the vscode integration for this. I feel bad that I haven’t contributed much since, it’s a really cool project. IMO it’s important to try to innovate in the foundational tools of our craft (editors, languages, tooling, OS, etc) which Ki does.
- Sammi 7mo agoThis one? https://marketplace.visualstudio.com/items?itemName=ki-editor.ki-editor-vscode https://marketplace.visualstudio.com/items?itemName=ki-edito...
- evelant 7mo agoYeah that’s it. Bundles the editor binary with the extension so you don’t have to install it separately.
- herrherrmann 7mo agoThank you for that! I find it really daunting to try a new editor, but having a vs code extension as an entry point really helps me and increases the chances of trying it out soon!
- groundzeros2015 7mo agoHave you seen any of the lisp tree editing modes for eMacs or vim?
- irenetusuq 7mo ago[dead]
- deleted 7mo ago[deleted]
- muixoozie 7mo agoI can't wait to try it. Love that it's keyboard layout agnostic. A lot of other good sounding ideas in the docs. Especially inspiration from Emacs as everything being an editable buffer. There's always some massive tradeoffs between editors though. Guess I'll have to see.
- exidex 7mo agoIt's a shame that editors are build around the editing model, so much time has been wasted by recreating everything. Neovim is a perfect editor in many aspects but editing model is not one of them, in my opinion. Helix or even Ki would not be needed if Neovim allowed to completely replace the vim part of it with plugins
- wizzwizz4 7mo agoCan you elaborate on how this might look, both from an abstract perspective, and (if you've thought about it) from an API perspective?
- exidex 7mo agoI didn't really spent time thinking about it, because from reading their issue tracker, I very much doubt neovim would consider something like that. Partially because of how much of it is already vim specific and it would be very difficult to abstract that away, but mostly because of ideology. You can already to a lot in Neovim with plugins, including recreating Helix, Ki, whatever. But the problem is that the vim state machine is always present underneath it, resulting in unwanted behaviors or impossibility to implement some things. I would envision it to pretty much allow to listen on raw keyboard and mouse events. However cursed it sounds, it should be possible to fully implement vscode or any other editing model in neovim
- wizzwizz4 7mo agoI'm not sure how that's not "recreating everything". What's still shared if you replace the whole state machine (handling file management, etc) and also replace the whole input handling system? A terminal emulator and a copy of Lua?
- ramon156 7mo agoI didn't fully understand until I saw the examples > First-class syntactic modification > Notice the comma between the current and the next node is also deleted. > Notice how comma is added automatically. This is awesome! And I bet it arguably requires less logic to do so as well. Cool stuff. Now I'm wondering how much effort it would be to get a ki integration (or at least an AST-first rewrite) in Zed
- evelant 7mo agoI wrote the vscode extension for Ki. It would almost certainly be usable with Zed since it talks with the editor over a websocket. Check out the code in the Ki repo.
- sigbottle 7mo agoI feel so illiterate when it comes to AST editing sometimes. I understand what an AST is from a computer science perspective. But I've never worked on a huge software refactor before that required direct AST textobject editing. Maybe an indication of my skill level... The extent of my usage is having nice textobjects to easily interact with arglists and functions which aren't native to (neo)vim. Very cute and nice to just write "daf" somewhere in a function and just have it "just delete". Or hook it up with basic macros: search for regex, "daf". I guess it's hard for me to edit things that I don't see right in front of me or aren't super simple changes (like name changes). Or at least, basic things I can reason about (such as finding by regex then deleting by textobject or something). As for LSP's, I do use go to definition and rename all references, which is nice. But the huge structural refactoring part I have never really done. I don't really use many LSP features besides those two either... Basically, I gotta up my editor game.
- freedomben 7mo agoI feel the same way. Learning Elixir and getting into macro writing was really helpful for me. Lisp is also the same way though for me the syntax of Elixir resonated a lot better for me. Many paths to the destination and all that, but figured I'd share in case it's helpful to someone
- hou32hou 7mo agoTBH, it's actually not as hard as you think, most of the time, what I do is just select the whole syntax node and delete it, copy it, or replace it, and only 20% of the time would actually require deliberate understanding of how the AST is structured in the current language I'm coding in.
- aragonite 7mo ago> I guess it's hard for me to edit things that I don't see right in front of me or aren't super simple changes (like name changes). Or at least, basic things I can reason about (such as finding by regex then deleting by textobject or something). This is actually what's nice about tools like ast-grep. The pattern language reads almost like the code itself so you can see the transformation right in front of you (at least for small-scale cases) and reason about it. TypeScript examples: # convert guard clauses to optional chaining ast-grep -pattern '$A && $A.$B' --rewrite '$A?.$B' -lang ts # convert self-assignment to nullish coalescing assignment ast-grep -pattern '$X = $X ?? $Y' --rewrite '$X ??= $Y' -l ts # convert arrow functions to function declarations (need separate patterns for async & for return-type-annotated though) ast-grep -pattern 'const $NAME = ($$$PARAMS) => { $$$BODY }' --rewrite 'function $NAME($$$PARAMS) { $$$BODY }' -l ts # convert indexOf checks to .includes() ast-grep -pattern '$A.indexOf($B) !== -1' --rewrite '$A.includes($B)' -l ts The $X, $A etc. are metavariables that match any AST node and if the same metavariable appears twice (e.g. $X = $X ?? $Y), it requires both occurrences to bind to the same code so `x = x ?? y` will match but `x = y ?? z` won't. You can do way more sophisticated stuff via yaml rules but those are less visually intuitive. Sadly coding agents are still pretty bad at writing ast-grep patterns probably due to sparse training data. Hopefully that improves. The tool itself is solid!
- alfanick 7mo agoThere was some Show HN some weeks ago on VCS/diff that operates on AST instead of lines/chars, anyone remembers its name?
- jpambrun 7mo agoDiffsitter and/or weave?
- lwhsiao 7mo agoThere is difftastic
- conartist6 7mo agoThere was Weave which just uses git for VCS and tree-sitter for conflicts. Gritzko is on-thread with his Beagle system, and I'm here too for BABLR ; )
- messh 7mo agoI don't like the positional keybindings. There is no real difference from regular keybindings configured with profiles for Qwerty, Dvorak, etc. In practice, it just means presenting them drawn into keyboards in a way that is hard to quickly search or use in the terminal and anywhere really. Where's the "line" key? Search the drawing! (Oh... it is there in th top left corner, but which exact key?) I prefer a list. So, really, it is not even that big of a "special thing" except the presentation.
- hou32hou 7mo agoHave you actually tried it?
- lorenzohess 7mo agoThis is like slurp, barf, splice, raise, kill, cut, yank for lisps.
- mgaunard 7mo agoDoes it support C++?
- shashurup 7mo agoFirst impression. Muscle memory is a problem :( Vim's j moves down. Ki's j in line mode moves up... Cannot figure how to create new file
- hou32hou 7mo agoPlease feel free to ask for help in https://ki-editor.zulipchat.com/join/zzhagqzl6wyzpqfeqxcsrkin/ https://ki-editor.zulipchat.com/join/zzhagqzl6wyzpqfeqxcsrki... :)
- kfse 7mo agoHow does this work in the many cases where in-progress edits result in an unparseable structure?
- jillesvangurp 7mo agoYou just complete to a parsable structure. This stuff reminds me of intentional programming (Charles Simonyi). That never really panned out but the premise with intentional programming was that programming is about AST transformations that are correct (sort of like refactoring) but all the way down to the machine code level. You get these increasingly more complex languages that are defined in terms of building blocks that are ASTs. Refactoring of course is based on the same notion that manipulating code correctly at the AST level is a lot easier than messing around with text files. That came out of the smalltalk world originally which also had very fancy IDEs already in the nineties where everything (including the IDE) was something you could mess with. Refactorings were defined as syntactically correct transformation of one AST into another (rename, extract class, move function to parent class, etc.). Charles Simony had a solution for what you describe as well. Just serialize stuff to text if somebody wants to "edit" and then parse it back when they are done. What happens to the text in between of course is the programmer's problem.
- igouy 7mo ago> Refactorings were defined as syntactically correct transformation of one AST into another Refactorings preserved behavior. Maybe that isn't what we wanted: "A very large Smalltalk application was developed at Cargill to support the operation of grain elevators and the associated commodity trading activities. The Smalltalk client application has 385 windows and over 5,000 classes. About 2,000 classes in this application interacted with an early (circa 1993) data access framework. The framework dynamically performed a mapping of object attributes to data table columns. Analysis showed that although dynamic look up consumed 40% of the client execution time, it was unnecessary. A new data layer interface was developed that required the business class to provide the object attribute to column mapping in an explicitly coded method. Testing showed that this interface was orders of magnitude faster. The issue was how to change the 2,100 business class users of the data layer. A large application under development cannot freeze code while a transformation of an interface is constructed and tested. We had to construct and test the transformations in a parallel branch of the code repository from the main development stream. When the transformation was fully tested, then it was applied to the main code stream in a single operation. Less than 35 bugs were found in the 17,100 changes. All of the bugs were quickly resolved in a three-week period. If the changes were done manually we estimate that it would have taken 8,500 hours, compared with 235 hours to develop the transformation rules. The task was completed in 3% of the expected time by using Rewrite Rules. This is an improvement by a factor of 36." from “Transformation of an application data layer” Will Loew-Blosser OOPSLA 2002 https://dl.acm.org/doi/10.1145/604251.604258 https://dl.acm.org/doi/10.1145/604251.604258
- nine_k 7mo ago/* A source code editor that operates directly on the AST, and affords different visual representations on top of it, was the topic of my (unfinished) PhD thesis about 30 years ago. */
- mmooss 7mo agoWhat can you tell us about it? What worked and what didn't? What was hard?
- radford-neal 7mo agoMany years ago, I created an editor operating on syntax trees that I think is more "hard-core" than this - that is, only tree-oriented operations are done. There is no parsing of text, since entering plain text, rather than a tree, is impossible. Hence, there can be no syntactically invalid programs. The challenge is getting this to be a useable way of entering programs. I think I made progress on this, but the feasibility varies with the programming language. I can't run it any more, since the display hardware it assumed is no longer available, but you can read about it at https://ucalgary.scholaris.ca/items/da8b823b-c344-4ffb-aa37-baf3f37c3fd7 https://ucalgary.scholaris.ca/items/da8b823b-c344-4ffb-aa37-...
- Normal_gaussian 7mo ago> The challenge is getting this to be a useable way of entering programs. Well exactly. When the path between Program A and Program B can only be valid programs, you are going to end up with either a much longer, less intuitive path, or deleting everything and starting again. It can also be quite possible to invent structures which are valid but have no valid path to creating them.
- radford-neal 7mo agoWell, I think most common transformations work reasonably well. One usually doesn't want to do things completely contrary to the AST, such as convert "while a<b" to "whilea = b". And it's certainly possible to create any valid AST in the editor I describe. The set of valid trees is extended to those with "holes" in places, which one fills in when entering a program, and it's always possible to do this. The challenge is one of finding an intuitive user interface, not whether it's possible at all. One issue is that infix notation is unnatural for entering trees (prefix is more natural).
- socalgal2 7mo agono syntax error editing seems like https://scratch.mit.edu/ https://scratch.mit.edu/
- 7mo ago
- dataangel 7mo agoAs always emacs has it already https://github.com/mickeynp/combobulate https://github.com/mickeynp/combobulate
- XJ6w9dTdM 7mo agoYeah and using combobulate feels so natural, I just wish it was easier to add support for other languages. In addition to the navigation, and simple edits (e.g. M-k kills node) you have Searching/editing/etc. using tree-sitter queries directly within emacs, possibly replacing other uses of external tree-sitter based tools. It makes editing supported languages almost as pleasant as editing Lisp. With how well the integration already work in existing editors, I'm curious how the UX can be improved further by an editor made specifically with AST editing in mind.
- arikrahman 7mo agoI highly appreciate the Nix-first approach
- readitalready 7mo agoThe problem with editors is that each one has a huge cognitive load for minimal benefit. I can't imagine learning this one just to be able to move blocks around easier. At this point you can just let your IDE's AI refactor any code by just telling it what you want to do.
- ileonichwiesz 7mo agoTrue, but muscle memory and a couple keyboard shortcuts (or heck, even using the mouse to select and drag the block) is always going to be faster then describing the changes you want and reviewing the output, at least for simple stuff.
- rmetzler 7mo agoI misread this a little bit, as KI is the German equivalent of AI (Artificial Intelligence = Künstliche Intelligenz).
- gigatexal 7mo agoOk ok all talk of the giant heavy java written jet brains IDE which I’m sure is great. What about all the experiences of using Ki and similar editors?
- __MatrixMan__ 7mo agoI think the challenge with AST editing is discoverability. Like, I know what I want to select, I can see it there on the screen, but I don't know its name. I've been dreaming of writing a plugin that surrounded the cursor in differently colored scopes. So instead of "next function" I'd be thinking "next blue" (blue being the color that functions are currently painted in).
- wtetzner 7mo agoI think there's still value in generic AST-level operations. Like expand selection and shrink selection. Or select around the current node vs select inside (whatever that means for the current node type).
- hou32hou 7mo agoIn Ki you don't have to know the name of the syntax node, you can just press `d m`, and the editor will show the labels of all the syntax node visible that you can jump to.
- __MatrixMan__ 7mo agoOh neat, I'm gonna give it a try!
- arikrahman 7mo agoA great addition to the helix workflow, I knew something was missing from the movement -> action approach. This completes the trifecta.
- jimmydoe 7mo agoI like this editor, but I have less code to type nowadays. I don't know what to feel
- alex_dev42 7mo ago[dead]
- cryptonector 7mo ago> vim's modal editing is powerful but the movements are text-based. Eh, v + showmatch / % gets you very far in languages that use ()[]{}<> (angle brackets you have to add to matchpairs). It gets you nowhere in Python though, not without plugins.
- Izkata 7mo agoIn python you can use {} to jump paragraphs. It's not great since it's based on blank lines and you'll probably need a few for a whole indented block, but it's built in and nicer than going line by line.
- agentultra 7mo agoI always liked Lisps for how easy it is to edit them with proper editor support such as Paredit in EMacs. Always wanted something like that for more syntactically dense languages. If it’s all tree-sitter based though I think it ought to be possible to do this in EMacs too.
- jbgreer 7mo agoI’m wondering who else recalls Charles Simonyi’s Intentional Software efforts at similar concepts? Not completely novel even then (1995) but mature for the time.
- novoreorx 7mo agoI just want to ask a practical question to people who are familiar with Vim and have already tried Ki, what are your thoughts on it? Is it easy to get used to Ki's keybindings?