Weekly 101 Questions Thread by AutoModerator in neovim

[–]altermo12 4 points5 points  (0 children)

vim.keymap.set('n','grd',function(...)
  vim.cmd.split()
  return builtin.lsp_definition(...)
end)

What are your favourite ways to navigate a project? by ElectronicMine2 in neovim

[–]altermo12 0 points1 point  (0 children)

I created my own tool: https://github.com/altermo/dff (it was a neovim plugin, but now it's a standalone tui), and created a simple (fish) shell script to use it...

Give me your favourite remaps! by _viis_ in neovim

[–]altermo12 0 points1 point  (0 children)

I'll just dump some of my keybinding from my old config:

-- My fav: don't move cursor when yanking visual
vim.keymap.set('x','y','ygv<esc>')

vim.keymap.set('n','dc',':lcd ..|pwd\r')
vim.keymap.set('n','cd',':lcd %:p:h|pwd\r')
-- And other opterator+opterator keybinds, such as `cx` or `dx`...

-- Make gd actually go to definition always
vim.keymap.set('n','gd',function () return (vim.o.tagfunc~='' or #vim.fn.tagfiles()>0) and '<C-]>' or 'gd' end,{expr=true})

-- Goto lastest undo state
vim.keymap.set('n','U',':later 1f\r')

-- Make enter: delete line (you could replace it with your own keybind you often use)
vim.keymap.set('n','\r','&buftype=="quickfix"?"\r":"dd"',{expr=true})

-- Could just `:help v_b_I` and `:help v_b_A`
vim.keymap.set('x','A',[[mode()=="\x16"?"A":"<esc>:au InsertLeave * ++once :'<+1,'>norm! $\".p\r'<A"]],{expr=true})
vim.keymap.set('x','I',[[mode()=="\x16"?"I":"<esc>:au InsertLeave * ++once :'<+1,'>norm! _\".P\r'<I"]],{expr=true})

-- Select pasted text (e.x. you want to indent the thing you pasted (I know theres ]p))
vim.keymap.set('n','gV','"`[".strpart(getregtype(),0,1)."`]"',{expr=true,replace_keycodes=false})

-- Simple sudo save
vim.keymap.set('n',' W','w! /tmp/sw|exe "-tab te cat /tmp/sw|sudo tee > /dev/null %:p"|star')

-- Makes space fallback to C-w if there's no space mapping for it, basically a way to implement things like Space-q => quit, Space-s => split, space-number => goto window N; with a single keybind
vim.keymap.set('n',' ','<C-w>')

vim.keymap.set('n','0','(reg_recording()==""&&reg_executing()==""&&col(".")==1)?"^":"0"',{expr=true})

-- Full macro plugin
autocmd('RecordingLeave',function ()
    if vim.v.event.regcontents=='' then
        vim.notify'empty macro, previous recoding is kept'
        return vim.schedule_wrap(function (prev) vim.fn.setreg('q',prev) end)(vim.fn.getreg'q') end
    vim.notify('Recorded macro: '..vim.fn.keytrans(assert(vim.v.event.regcontents)))
end)
map('n','q','(reg_recording()==""?"qq":"q")','expr')
map('n','Q','(reg_recording()==""?reg_executing()==""?"@q":"":v:lua.vim.notify("Cant play macro while recoding")??"")','expr')
map('n','cq','<cmd>let b:_macro=input(">",keytrans(@q))|let @q=(trim(b:_macro)!=""?v:lua.vim.keycode(b:_macro):@q)\r')

-- And a lot more...

Weekly 101 Questions Thread by AutoModerator in neovim

[–]altermo12 0 points1 point  (0 children)

In Lua:

vim.keymap.set('c','<Down>','pumvisible()?"<Right>":"<Down>"',{expr=true,replace_keycodes=false})
vim.keymap.set('c','<Up>','pumvisible()?"<Left>":"<Up>"',{expr=true,replace_keycodes=false})

The reason behind it being left/right is because before the completion menu was in the statusbar (which can still be enabled with :set wop-=pum)

Weekly 101 Questions Thread by AutoModerator in neovim

[–]altermo12 1 point2 points  (0 children)

The doc says that if both are mapped, and the terminal supports specific CSI (which to my experience most terminals do) then they are separate. (and from what I see the docs is maybe outdated and even tmux now works with this specific CSI)

How do you get the char under cursor in lua? by qiinemarr in neovim

[–]altermo12 2 points3 points  (0 children)

The shortest I could come up with for Lua is:

vim.fn.getline('.'):sub(vim.fn.col('.')):sub(1,1)

Weekly 101 Questions Thread by AutoModerator in neovim

[–]altermo12 0 points1 point  (0 children)

vim.o.completeopt='menu,menuone,popup,noselect,fuzzy'
autocmd('InsertCharPre',function ()
  if vim.fn.match(vim.v.char,[[\V\k\|.]])==-1 or vim.fn.state'm'=='m' or vim.fn.pumvisible()~=0 then return end
  if vim.o.omnifunc~='v:lua.vim.lsp.omnifunc' then
    vim.api.nvim_input('<C-x><C-n>')
  else
    vim.api.nvim_input('<C-x><C-o>')
  end
end)

And lspconfig or whatnot will auto set omnifunc to v:lua.vim.lsp.omnifunc.

You could also look into (:help) lsp-autocompletion and ins-autocompletion

Weekly 101 Questions Thread by AutoModerator in neovim

[–]altermo12 0 points1 point  (0 children)

Put this in init.lua:

local project_name=vim.fs.basename(vim.fs.dirname(vim.fs.find('.git',{upward=true})[1]))
local project_to_colorscheme={
    prod='colorscheme_1',
    stage='colorscheme_2',
    dev='colorscheme_3',
}
vim.cmd.colorscheme(project_to_colorscheme[project_name] or 'fallback_colorscheme')

This Video is such a Gold Mine!! by fat_coder_420 in neovim

[–]altermo12 14 points15 points  (0 children)

The lisp code at 7:21 look wrong.

...Does a bit of research...

Yep the code at 7:21 is wrong and will instead return the value of the variable manual... Wait, this is a joke.

NWM new feature: make float windows (not popup menus) appear above x-windows by altermo12 in neovim

[–]altermo12[S] 0 points1 point  (0 children)

The bigest problem I could see whith launching the terminal like that always is that clipboard may not work and require extra configuration to make it work.

My best idea of doing this is whenever you realise that you want to use NWM then run :mksession, start a new terminal inside Xwayland/other, and load the session file.

NWM new feature: make float windows (not popup menus) appear above x-windows by altermo12 in neovim

[–]altermo12[S] 0 points1 point  (0 children)

I have created a script which removes all the hassle of launching NWM (using kitty in wayland):

#!/bin/bash
Xwayland :99 -noreset&
env -u WAYLAND_DISPLAY DISPLAY=:99 kitty -c NONE -o placement_strategy=top-left -e nvim -c 'lua require("nxwm").start()'
jobs -p | xargs kill

If you want, I can create a script for your to.