14 ms·
I'm most excited for the treesitter integration and its potential to amplify Vim's "killer feature": text editing as a language. Vim's editing language feels m
by curriculum 5y ago
I'm most excited for the treesitter integration and its potential to amplify Vim's "killer feature": text editing as a language.
Vim's editing language feels most powerful when I'm using its text objects: "ciw" means "change in word", "cis" means "change in sentence", and so on. But Vim's built-in text objects are not always a perfect match for the code you're editing. Suppose you want to change the first argument of a function, for example; there's no built-in "first-argument" text object. But Treesitter integration makes it easy to create text objects that understand the AST. Without much effort, users will be able to make mappings like `cia1` to "change in argument 1", and these mappings will work across all languages with Treesitter support.
- SavantIdiot 5y agoAren't these features are subject to external configuration to behave properly? For example, C/C++ and #defines. The user has to configure yet another file for this to work properly. If the build system/tree is so complicated that I can't figure out what the final #defs are (like building MBED programs with literally a thousand #defs), I end up shutting off this feature entirely. This kills me with VSCode & Sublime, but Eclipse derivatives are usually more tightly coupled. What about neovim?
- Asooka 5y agoYou make your build system emit a compile-definitions.json file that has all the compiler flags for every file you compile and feed it to a language server (rtags or clangd usually, either standalone or part of another plugin like YouCompleteMe). CMake has a flag to do that as part of its configuration step (and remembers it), for other build systems you can use something like bear: https://github.com/rizsotto/Bear https://github.com/rizsotto/Bear .
- samus 5y agoFor future reference, as I found this information to be difficult to find: the flag for CMake is `CMAKE_EXPORT_COMPILE_COMMANDS=YES`. In out-of-source builds, the output file will be in the build directory, therefore one has to create a symlink to ensure the language server finds it in the project root.
- deleted 5y ago[deleted]
- Kaze404 5y agoAre there really no plugins for that? In Doom Emacs "cia" deletes an argument normally, which I assume is done by an evil mode plugin, so I thought there was one for Vim as well.
- curriculum 5y agoThere are, but they usually rely on regex or other brittle approaches, making it difficult to write well. And currently you'll need to use different plugins for different languages (e.g., jedi for python). Treesitter builds the AST, making it easier to create robust text objects. And it provides a unified interface for a bunch of different languages, meaning that I don't need to have 10 different plugins, one for each language, just to get access to text objects.
- sophacles 5y agoVarious plugins can do it on a per language basis, but tree sitter is a nice abstraction that allows such commands to be done with a simple mapping - then tree sitter (with a per-language plugin) will parse to the same ASTish thing, so any language that has function arguments will have the same commands working the same way. I'm actually kind of excited about tree-sitter - it's not a neovim feature, it's an independent project that can be used a lot of places. I think the effect will be similar to how LSP changed the landscape from "every editor does some parts of handling language X well, but the parts each editor does are different from each other" to "all the editors get this feature when the language server does", just for syntax highlighting and syntax aware edition.
- e-v 5y agoThe plugin you are referring to is evil-args (https://github.com/wcsmith/evil-args https://github.com/wcsmith/evil-args), which is included in Doom Emacs by default.
- ashton314 5y agoThank you! I tried this out on my setup, but was disappointed when it didn’t work. I’m new to evil and I’m constantly impressed with how big the ecosystem is!
- markus_zhang 5y agoDamn this looks cool. I always want this kind of flexibility. I'm using both Jetbrain products and VS right now, and one pain point is that it's difficult to define new short-key combinations and assign a key to it.
- alpaca128 5y agoThis is one of the biggest strengths of Vim imho. Defining new keybindings is so intuitive and flexible you wonder why it's usually done differently. With Vim you basically just tell it to map any sequence of inputs to any other sequence of inputs. If you know how to do something in Vim you can define a keybinding for it. And because Vim is 100% controllable via the keyboard you can bind anything to a shortcut.
- ponyous 5y agoI can never remember what all those different maps do: ':map', ':map!', ':nmap', ':vmap', ':imap', ':cmap', ':smap', ':xmap', ':omap', ':lmap', etc. do. There are bunch of questions on StackOverflow about different mapping options so I wouldn't say it's intuitive at all.
- alpaca128 5y agoThe differences that actually matter are self explanatory: map is for all modes, imap for insert mode, nmap for normal mode and vmap for visual mode (& tmap for terminal mode in NeoVim). The rest can be safely ignored as far as I can tell. Little confession: I have no idea what e.g. the difference between "nmap" and "nnoremap" is. But after years of randomly mixing them in hundreds of bindings without a noticeable difference it doesn't seem to matter. Just use map, nmap, imap and vmap, avoid duplicates and everything will be fine imho.
- Omni5cience 5y agoYou're right, for most simple use cases it doesn't matter. But I once spent an hour on a weird bug that turned out to just be some plugin applying a map that I didn't know about and that I didn't know about map expansion. So I might be biased, but I think a loose understanding is helpful. The default behavior is to recursively expand and apply your mappings and "noremap" disables this recursion. For example if you do something like :map j k :map q j :noremap w j q is expanded to k, but w is expanded to j
- azinman2 5y agoDo you find your brain can actually work that way? My issue with all of these relative jump points, repeat this N times, etc of VIM is by the time I’ve calculated in my mind what the command should be I’d have already done it with just standard navigation/mark/yank/repeat. But perhaps you have galaxy brain ;)
- tgb 5y agoI never use the counts (repeat N times) except for the very simple 55G to go to line 55. It's not useful. But the rest of vim is. I think of it like a chess board. A queen has more moves available than a king. Does that make it harder to move to a certain square with the queen than with the king? Not really, they're both pretty straight forward, if you're not trying to achieve the minimal edit distance to do so. You make big edits when it's obvious and just do smaller edits when it's not. The only commands I have to plan out are search-and-replaces.
- SkyMarshal 5y agoFor many commands you’ll only have to make that calculation once, and will remember it going forward. Only commands that are extremely rarely used you may forget and have to reconstruct with the calculation again later.
- curriculum 5y agoNo galaxy brain here ;) I generally don't use counts. If I want to go down a few lines, I don't count the number of lines and use 4j or whatever, I instead use / to search for the exact place I want to move to. This feels more natural and preserves the jump-list, so I can ctrl-o back to where I was. Same if I want to delete a few words. I don't count how many I want to delete and do 4daw, instead I do daw and press . until I've deleted everything I want gone. And I make heavy use of text objects when available. If I want to move to the next function, I use the keybinding for that instead of searching or counting lines.
- vulcan01 5y agoInstead of counting, you can use :set relativenumber (vim/neovim builtin) to quickly see how far away lines are. (see https://jeffkreeftmeijer.com/vim-number/ https://jeffkreeftmeijer.com/vim-number/)
- alpaca128 5y agoI'm excited about it because Vim's usual syntax highlighting is rather fragile. As far as I understand it Vim does the highlighting in the same thread, and to ensure good performance it enforces a time limit for the file parsing. In larger files this frequently leads to weirdly flickering highlighting when scrolling. Going from that to actual syntax parsing is a dream come true.
- bisby 5y agoThat explains a lot. I often have a syntax highlighting quirk where it thinks that a fold has an open quotation mark in it. And will highlight everything below the fold as if it's a part of a string. I unfold, and clears it all up. but it's annoying in the moment. I look forward to all of this
- alpaca128 5y agoYou can often fix it with `:syntax sync fromstart`, but Vim's syntax highlighting just keeps being a bit weird.
- kbenson 5y agoI added 'autocmd BufEnter * syntax sync minlines=4000' to my .vimrc to make it buffer more of large files initially, so it gets less confused when you reopen a file and it resumes at a prior location deep inside and has no syntax highlighting. I guess fromstart would work as well, but is probably best manually run like you do so a very large file doesn't bring the system to a halt.
- OJFord 5y agoThat's why that happens, and a fix - thanks!
- nucleardog 5y agoI usually just keep space bound along the lines of: :noremap <silent> <Space> :silent noh <Bar>echo<cr>:syn sync fromstart<cr> This recalculates syntax highlighting as well as removes highlighting on search results/etc. Basically, whenever stuff "looks weird", just mash space in normal mode and it fixes it. The fact that I have this bound to something like space should tell you how often I end up using it. :)
- jarbus 5y agoWhat treesitter module does this fall under? I'm having a hard time finding this in the documentation. Or do users have to add this functionality themselves? Are there reference implementations for what you are describing?
- b3morales 5y agoRight, Treesitter just gives the client program a syntax tree; it will be up to Neovim to map that to editing commands. (And the fidelity will depend on the quality of the specific language's Treesitter parser.)
- mjlbach 5y agoHave you tried https://github.com/nvim-treesitter/nvim-treesitter-textobjects https://github.com/nvim-treesitter/nvim-treesitter-textobjec...?
- curriculum 5y agoNot yet! I just moved to 0.5 this weekend. But thanks for the link!
- ampdepolymerase 5y agoI just wish Vim had proper S-expression structural editing support. Many editors have vim support but very few have smartparens/paredit with good integration. If Vim can extend its language to include some basic structural editing, then writing any type of tag based code e.g. JSX would become much more pleasant. For example in VS Code's Flutter plugin there is support for "delete surrounding widget" and "wrap child widget in new widget". They just need better keybinding integration.
- SpaceNugget 5y agoVim uses text objects for that kind of thing, t being the tag text object. `dat` deletes the JSX tag enclosing the cursor, `cit` deletes the contents of the tag and leaves you in insert mode, etc. Matchit (included in neovim) can also be configured to have % match tags as well as the default brackets/parens. LSP text objects are also available for more language specific structural editing.
- emidln 5y agovim-sexp is very very good and IMO better than smartparens/paredit. I'm not a fan of the paredit-style keybindings by default, but the way it integrates into vim's model is IMO perfect.
- ampdepolymerase 5y agoBut it is not supported in other editors (VS Code, Intellij etc.), it is not like vim-surround or easymotion where almost every major third-party vim implementation supports it.
- frederikvs 5y agoI just have vim-angry installed. It gives me "cia" and friends, though without the count you mention. Sounds like treesitter will have more flexibility, but for now the vim-angry plugin does what I need it to :-)
- staticshock 5y agoSeconded. vim-angry is an excellent plugin that exposes args as text objects. In an expression such as (foo, ba|r, baz), where | is the cursor, it does the following: via - (foo, |bar|, baz) vaa - (foo|, bar|, baz) vaA - (foo, |bar, |baz)
- je42 5y agotreesitter was the reason why i installed the git version of neovim ;) it is very good. so happy with with it;)
- devenvdev 5y agoPlease someone clean that tpope searchlight! Na na na na na na na na tpope! I would actually pay (although relatively small amount) for better programming text objects. It would feel so much more natural than the currently burned in muscle memory workarounds...