Neovim

1954 readers
31 users here now

founded 1 year ago
MODERATORS
26
 
 

I was looking for a good generalist set of keybindings for my Steam Deck's onboard controls that bound all the letter keys and also the necessary commands to navigate web pages and manipulate files. There isn't any obvious layout to bind all the gamepad buttons, joysticks and touchpads to letter keys and keyboard commands/command chords, and further it feels like whatever solution you came up with would be impossible to memorize anyways.

Kind of a silly endeavor perhaps, but... touchscreen keyboards take up wayyyyy too much screen real estate on the Steam Deck, and further the pop up software keyboard sometimes doesn't behave right with software that isn't expecting a pop up touchscreen keyboard (i.e., not like a mobile app designed to handle one).

Then I randomly thought about Qutebrowser and vim keybindings... and I had an evil idea.....

I want to try using this with neovim as well, and I thought y'all might get a kick out of it lol!

edit errr, oooff I don't know how to get lemmy not to dump the text from my linked post completely unformated into this post

27
 
 

Siddharta Govindaraj writes:

As I blogged about in the previous two articles, I recently updated my NeoVim configuration for the fourth time. Although it might sound like a lot of config updates, keep in mind that it happened over a period of four years.

  • The first version was a port of my existing Vim configuration. Because NeoVim is backward compatible with Vim, you can just move the configuration over and it will work
  • In the second version, I migrated my plugin manager to Packer. This config was a mix of old style Vim config and the newer NeoVim style with some plugins migrated to Lua equivalents
  • Then I decided to go 100% Lua config and started using Kickstart.nvim and LazyVim.
  • This fourth time around I used Kickstart and LazyVim as guides to write my own from scratch.

You can find my NeoVim configuration on Github.

In this article I am going to go through and explain my configuration step-by-step. I have a terrible memory, so this post will also serve as a guide when I inevitably need to look through this file in the future.

Read Configuring NeoVim as a Python IDE (2023)

28
1
submitted 7 months ago* (last edited 7 months ago) by [email protected] to c/[email protected]
 
 

btw.nvim

Show "I use Neovim (BTW)" when neovim opens. That's all you need.


Why bother with mini.starter, vim-startify, dashboard-nvim, or any of those distractions? I know you, my friend. Forget about all that noise – all you truly need is I use Neovim (BTW). Embrace it proudly, and let your ego shine!

Features

  • Instant Ego Boost: Get greeted with "I use neovim (BTW)" on launch.
  • I use Neovim (BTW): Show your ego to the world.

29
30
 
 

This is an story I found in 'Learning vi and Vim Editors'


which I started reading to 'vim-maxx':

Mary Ann Horton, who has been involved with Berkeley Unix since almost the begin‐
ning, tells the following story:
While the vi experience was much like Notepad, it was also a very powerful editor.
Students and faculty made heavy use of the power tools available, like the “global”
command that would make the same change on all lines matching some pattern, or
the ability to give commands like “delete 13 paragraphs” or “copy the text through the matching parenthesis.” But vi had a steep learning curve, and first-time users wanted
to use the arrow keys on their terminals to move around in the file, Notepad style.
Arrow keys didn’t work in vi, and for a very good reason. Users had a variety of
different brands of terminals, and all those terminals’ arrow keys sent different codes
when they were pressed.
Bill [Joy] didn’t have to worry about arrow keys. He had found a way to work from
home, getting a Lear-Siegler ADM-3A terminal in his apartment. The ADM-3A was
widely advertised as “the dumb terminal” because it didn’t have a lot of fancy features,
like arrow keys, allowing it to be sold for the then-low price of $995. Instead, LSI
painted arrows on the H, J, K, and L keys.4 Bill had set up vi commands to match: h
moved the cursor left, j down, k up, and l to the right. Every vi user had to learn h, j,
k, and l to move around the file.
What if you wanted to type a word with an “h” in it? vi, like ed, was a “moded” editor.
This meant you were either in “command mode,” where it treated keys you pressed as
commands, or “input mode,” where keystrokes were content to be added to the file.
A command like i for “insert” put you in input mode, and the Escape ( ESC ) key got
you back to command mode.
How to get arrow keys to work in vi? These special keys sent two or three character
sequences, usually beginning with Escape. We called them “escape sequences.” Escape,
however, was already an important vi command. It took you out of input mode, and
if you were already out of input mode, it beeped. One of the first things you learned
in vi was that, if you’d forgotten which mode you were in, you pressed the ESC key
until it beeped, and then you knew you were in command mode.
vi used a terminal capability database file called “termcap,” which told it which codes,
for your specific model terminal, to send to move the cursor, clear the screen, and the
like. It was easy enough to add the arrow key sequences to termcap.
If the computer received an Escape, was the user hitting the ESC key or an arrow
key? Should the editor exit input mode, or should it wait for more text to interpret
an arrow key? Once the editor tried to read more text, the program would hang until
something came in.
Fortunately, a new Unix feature allowed the editor to wait briefly to see if another
character came in. If that character might be part of a valid escape sequence, vi could
keep reading to see what other key the user had pressed. If no more characters came
in for that brief interval, the user must have pressed the ESC key. Problem solved!
Around the spring of 1979, I added code and termcap entries for vi to understand
arrow keys, Home, Page-Up, and other keys that some of the terminals had. I configured termcap as if the ADM-3a had arrow keys that sent h, j, k, and l; and
then I deleted the hardcoded h, j, k, and l commands. I thought I had it all fixed up.
Within a day, I had a line of angry CS grad students outside my office door. Peter
was at the head of the line. He wanted to know why I broke hjkl on his terminal. I
explained to him that his arrow keys worked now, and he didn’t have to use hjkl; he
could use the arrow keys instead.
Peter rolled his eyes. “You don’t understand,” he said. “We like using hjkl! We’re
touch typists. Our fingers are right over the hjkl keys. We don’t want to have to
move them way to the edge of the keyboard to use arrow keys. Give us back our hjkl
commands!” The line of students agreed.
They were right. I put back hjkl and left the arrow key functionality in too. And
I realized how important the key placements of vi commands were. Almost any
command you used often was a lowercase letter. I got really fast with vi, and to this
day I prefer vi to edit text files. I’ve trained several classes of IT professionals how to
get the most out of vi and Unix power tools.
31
1
submitted 7 months ago* (last edited 7 months ago) by [email protected] to c/[email protected]
 
 

im switching to colemak-dh and i need some advice.

im writing this with colemak-dh, beleive me its hard. whats even harder is the hjkl navigation. so should i remap it to neio? you can consider me a long run guy, so your answers can be based on that.

thanks in advance.

32
33
34
35
36
 
 

Really enjoying nvim-dap-ui lately, but I always have to adjust the sizes of the windows. The docs have left me high and dry so far, but maybe one of you have a good solution for a consistent layout when you first attach to a file?

37
 
 

Looking for a way to migrate from Arduino IDE to get everything in NeoVim, but I get lost in the weeds without a working example or reference. I'm wondering if this is actually practical and more than a novelty for anyone here.

38
39
1
Help with snippets? (lemmy.sdf.org)
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
 
 

My goal is to automatically close the environment while editing a tex file. There was an issue for vimtex asking for basically what I want to achieve. They achieve it using snippets as mentioned there.

The problem is, I have no idea how to set it up. I've never used snippets in nvim. I have vim-vsnip and cmp-vsnip installed as it was needed for another plugin to work. Is it possible to implement this using those?

It can be noted that in vimtex, an environment can be closed by typing ]] which is a mapping of vimtex-delim-close. I basically want to emulate the behavior in VS Code using LaTeX Workshop. It auto-closes the environment, adds an indented line in the middle, and moves the cursor there.

If anyone has any other ideas about doing this without snippets, that's welcome too.

40
 
 

Hey. So a few weeks ago I implemented the Zephyr ASDL domain-specific language which is used to generate ASTs in C. ASDL is very useful in language development. Although I myself would like to turn it into a Perl script, or maybe a Ruby or a Python script instead of a stand-alone C program. Whilst I was making it, I thought maybe it would be cool to add my own asdl.vim which I had been using to the source tree. So I added it to /companions/asdl.vim, and also installs to /usr/share/doc/asdl when you install it. You can find asdl.vim in the companions.

I'm pretty new to defining syntax highlighters for NeoVim/Vim. I struggled to have asdl.vim include C code, but I failed :( Although I managed to make a good Vmgen embedding of C code.

Another language that I myself have not implemented, but use frequently is Vmgen. It's a part of Gforth, it's used to generate Vms for interpreters.

Now, I have also defined a highlighter for my own superset of EBNF which is very useful IMO.

You can find ebnf.vim and vmgen.vim here: https://gist.github.com/Chubek/37fa48239ac0de78da45475d9533b123

I know these are very basic definitions and not nearly as cool as the ones you guys probably make. But as I said I have so little time during the day, and I am trying to hack my way through learning VimScript.

Thanks.

41
 
 

Hi I've been looking at nyoom.nvim and it alters the UI of telescope (see screenshot) I was just wondering how this is possible? I looked d through the codebase but couldn't find anything other than the setting of colours?

Here is the repo: https://github.com/nyoom-engineering/nyoom.nvim

42
 
 

cross-posted from: https://discuss.online/post/5797974

TJ has a walkthrough of installing NeoVim and his Kickstart.nvim package for people new to NeoVim. He explains what is going on so you can then further customize your NeoVim setup.

I used NeoVim with Kickstart.nvim to get my NeoVim setup initialized. It's great.

43
1
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
 
 

I'd like a treesitter query that matches a Rust struct together with all of its attributes. For example,

#[derive(Debug)]
#[serde(rename_all = "camel_case")]
pub struct MyType {
    pub foo: i32,
}

The lines beginning with # are attributes that are logically connected to the struct declaration. But the treesitter grammar for Rust parses attributes as adjacent nodes, not as children of the struct declaration:

  (attribute_item ; [27, 0] - [27, 16]
    (attribute ; [27, 2] - [27, 15]
      (identifier) ; [27, 2] - [27, 8]
      arguments: (token_tree ; [27, 8] - [27, 15]
        (identifier)))) ; [27, 9] - [27, 14]
  (attribute_item ; [28, 0] - [28, 35]
    (attribute ; [28, 2] - [28, 34]
      (identifier) ; [28, 2] - [28, 7]
      arguments: (token_tree ; [28, 7] - [28, 34]
        (identifier) ; [28, 8] - [28, 18]
        (string_literal)))) ; [28, 21] - [28, 33]
  (struct_item ; [29, 0] - [31, 1]
    (visibility_modifier) ; [29, 0] - [29, 3]
    name: (type_identifier) ; [29, 11] - [29, 17]
    body: (field_declaration_list ; [29, 18] - [31, 1]
      (field_declaration ; [30, 4] - [30, 16]
        (visibility_modifier) ; [30, 4] - [30, 7]
        name: (field_identifier) ; [30, 8] - [30, 11]
        type: (primitive_type)))) ; [30, 13] - [30, 16]

How can I get produce a query that I can use in mini.ai that matches the struct, and all attributes?

I've tried this query using Neovim's new built-in :EditQuery command:

((attribute_item)* . (struct_item)) @custom_capture.outer

It looks like it does what I want. But when I try using @custom_capture.outer in mini.ai it matches the struct declaration, but not the attributes.

I tried using #make-range! like this,

((attribute_item)* @_start . (struct_item) @_end
  (#make-range! "custom_capture.outer" @_start @_end))

That matches the struct and the second attribute, but does not get the first attribute. I'm guessing that's because the . specifies that nodes must be adjacent, and the second attribute is the only one that is adjacent to a struct_item. Following that thinking I tried this,

((attribute_item)? @_start . (attribute_item)* . (struct_item) @_end
  (#make-range! "custom_capture.outer" @_start @_end))

That gets the struct and all the attributes, but only if my cursor is on the first attribute line when I use the textobject. If my cursor is on any subsequent line then I get the second attribute and the struct, but the first attribute is missed.

One problem is I'm not clear whether ((attribute_item) . (struct_item)) matches an attribute_item and a struct_item that are adjacent, or matches an attribute_item that precedes a struct_item, but does not also match the struct_item. I tried experimenting with the second interpretation and used this query,

(((attribute_item) 
  . [(attribute_item) (struct_item)])* @_start
  (struct_item) @_end
  (#make-range! "custom_capture.outer" @_start @_end))

That captures what I want, but in some cases if I have two struct declarations and I try to match only the second one the query selects both structs instead.

Is that the way to do a lookahead? Or is there another way?

I've kinda hit a wall looking at documentation, other examples, and running my own experiments. Does anyone have any pointers to help understand these queries on a deeper level?

Edit: It looks like this stuff is in flux, so I should mention that I'm using the latest nightly as of March 2 2024, and I made sure that all of my plugins are up-to-date.

44
1
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
 
 

Fairly new neovim user here, so bear with me if I don't get everything.

I'm using neovim with Telescope and I often struggle with the following process: I want to be able to easily save my past yanks and deletions and fuzzily find the one that interest me now. Is there a way to configure Telescope to look into registers for that ?

Also, is there a way to keep the history of deletion as well ? Sometimes I'm deleting A, deleting B, deleting C and want to past A which is no longer accessible (unless I remember to put it in a named register in the first place, which I rarely do).

45
 
 

Hello all, as someone who mainly prefers dark themes but also enjoys black text, I created this semi-light neovim color scheme. https://gitlab.com/sxwpb/halfspace.nvim

The goal was having a theme that uses black text but avoids the eye melting of most light themes. In fact the background color is #808080, which is the midpoint of a monitors brightness. Using such a background comes at a hefty cost of text contrast, thus all chosen syntax colors are kept pretty close to the best possible contrast here which is black text.

Let me know what you think and I know lots of people absolutely despise this type of color combination which I understand, so please be kind in that case.

happy vimming

46
47
48
 
 

kitty-scrollback.nvim v4.0.0 is officially released! Check out the announcement here.

What is kitty-scrollback.nvim?

A Neovim plugin (and Kitty Kitten) that allows you to navigate your Kitty scrollback buffer to quickly search, copy, and execute commands in Neovim.

kitty_scrollback_screencapture_00_kitty_scrollback_nvim

Check out Advanced Configuration Examples for more demos!

What changed?

See Migrating to v4.0.0 for the detailed migration guide.

  • Previously, kitty-scrollback.nvim did not open Neovim with your Neovim configuration by default. This has changed to loading your Neovim configuration by default, with the ability to opt out. If you prefer to continue not loading your Neovim configuration, then follow the steps at No Configuration.
  • If you previously used the flag --no-nvim-args, then delete it from your configuration because it no longer has any effect. The flag --nvim-args remains unchanged and can still be used.
  • ksb_example configurations have been removed and can no longer be referenced by name. If you were previously referencing an example configuration by name, then you can manually copy it from ./tests/example.lua into your kitty-scrollback.nvim configuration. See Plugin Configuration for detailed instructions on configuration kitty-scrollback.nvim.
  • The command KittyScrollbackGenerateKittens and api generate_kittens no longer have an option to generate ksb_example configurations.
    • The command KittyScrollbackGenerateKittens no longer accepts the bang ! modifier
    • The api generate_kittens signature removed the all parameter
  • The reserved global configuration name has been removed and global options are now configured by the first element of the options table without a key. See Global Configuration for more details.
  • The undocumented reserved default configuration name has been removed. kitty-scrollback.nvim defaults to ksb_builtin_get_text_all if no configuration is provided.

Other minor version updates

  • You can now paste and execute commands directly from visual mode! Previously, this could only be done with the paste window that is used for editing commands. Check out the demos in the Features section.

kitty_scrollback_screencapture_03_should_paste_visual_selection_to_kitty

  • The environment variable KITTY_SCROLLBACK_NVIM was added and is set to true while kitty-scrollback.nvim is active. See Environment Variables.
  • Documented the filetype kitty-scrollback and provided an example of using it in an autocmd. See Filetypes.

What's next?

The next feature I plan to work on is adding tmux support (see #155).

If you have any questions, comments, or feedback feel free to create an issue or open a discussion.

49
50
view more: ‹ prev next ›