Skip to content

Replaced init.vim with init.lua. Error Checking feature added in a minimal fashion.#1465

Open
lukerb52 wants to merge 8 commits intoLukeSmithxyz:masterfrom
lukerb52:master
Open

Replaced init.vim with init.lua. Error Checking feature added in a minimal fashion.#1465
lukerb52 wants to merge 8 commits intoLukeSmithxyz:masterfrom
lukerb52:master

Conversation

@lukerb52
Copy link
Contributor

@lukerb52 lukerb52 commented Apr 12, 2025

This PR removes the init.vim which uses the legacy vimscript and replaces it with init.lua, which uses the more extensible lua script. Everything from the old init.vim is still here. Airline is still the statusbar, and plug is still the main plugin manager.

The main addition is nvim-lspconfig, which is a native plugin that allows neovim to handle LSP files, an open standard for syntax and error checking. In this config, errors are handled like spell check is. Just like ]s moves to the next spelling error and [s moves to the previous, ]d and [d move to the next diagnosis (error or warning) respectively.

Using LSP involves installing the LSP package for each language/syntax type you want to use. I'm opting not to include these in the progs.csv in the LARBS package to allow each user to install only what they need. These LSP packages are loaded at line 232 in init.lua, and installation instructions are provided for some of the more basic packages. I've decided to leave the potentially uninstalled LSP packages uncommented, as it will only give a simple warning when opening a relevant file in neovim.

Copy link
Contributor

@aartoni aartoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lukerb52! I have been working on the exact same thing for a while (well, except for the LSP refactor), however I never had the chance to actually test it.

I have added some comments for you. I have to admit that your version looks definitely better than mine in almost every aspect but I wanted to give you a few refactoring ideas anyway in the hope that you'll like at least some of them.

Please excuse the pedantic comments but I really wanted to make sure that I had checked everything possible against my own version. Hopefully this will speed up @LukeSmithxyz's review as well.

Comment on lines +16 to +17
vim.keymap.set("n", ",,", ":keepp /<++><CR>ca<", { noremap = true })
vim.keymap.set("i", ",,", "<Esc>:keepp /<++><CR>ca<", { noremap = true })
Copy link
Contributor

@aartoni aartoni May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some new noremaps here that were not present in the Vimscript version, just checking if this was intended or just a typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands are for working with <++> placeholders. I don't use them much but I also don't see a reason to take them away.

end

-- Mappings for ,,
vim.keymap.set("n", ",,", ":keepp /<++><CR>ca<", { noremap = true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some places I see you have translated maps to vim.keymap.set("n", ...) instead of vim.keymap.set("", ...), just checking if this was intended or just a typo

Comment on lines +20 to +36
vim.fn['plug#begin'](vim.fn.stdpath('config') .. '/plugged')
vim.fn['plug#']('tpope/vim-surround')
vim.fn['plug#']('preservim/nerdtree')
vim.fn['plug#']('junegunn/goyo.vim')
vim.fn['plug#']('jreybert/vimagit')
vim.fn['plug#']('vimwiki/vimwiki')
vim.fn['plug#']('vim-airline/vim-airline')
vim.fn['plug#']('nvim-tree/nvim-web-devicons')
vim.fn['plug#']('tpope/vim-commentary')
vim.fn['plug#']('ap/vim-css-color')
-- New Plugins for LSP Server
vim.fn['plug#']('neovim/nvim-lspconfig')
vim.fn['plug#']('hrsh7th/nvim-cmp')
vim.fn['plug#']('hrsh7th/cmp-nvim-lsp')
vim.fn['plug#']('hrsh7th/cmp-buffer')
vim.fn['plug#']('hrsh7th/cmp-path')
vim.fn['plug#end']()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my version I have decided to create an alias to improve readability, I figured you might be interested.

local Plug = vim.fn["plug#"]
vim.fn['plug#begin'](vim.fn.stdpath('config') .. '/plugged')
Plug('tpope/vim-surround')
-- ...
Plug('ap/vim-css-color')
vim.fn['plug#end']()

Note that this is more or less the usage provided by the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. I'll implement it

Comment on lines +10 to +12
vim.api.nvim_create_autocmd("VimEnter", {
callback = function() vim.cmd("PlugInstall") end,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use the Ex command here.

vim.api.nvim_create_autocmd("VimEnter", { command = "PlugInstall" })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will use this.

vim.opt.ruler = false
vim.opt.laststatus = 0
vim.opt.showcmd = false
vim.cmd("colorscheme vim")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is more idiomatic.

vim.cmd.colorscheme("vim")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll use this

Comment on lines +87 to +95
vim.cmd([[
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.colnr = ' C:'
let g:airline_symbols.linenr = ' L:'
let g:airline_symbols.maxlinenr = ' '
let g:airline#extensions#whitespace#symbol = '!'
]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this in plain Lua!

local airline_conf = vim.g.airline_symbols or {}
airline_conf.colnr = " C:"
airline_conf.linenr = " L:"
airline_conf.maxlinenr = ""
vim.g.airline_symbols = airline_conf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you.

Comment on lines +208 to +223
local hidden_all = 0
local function toggle_hidden_all()
if hidden_all == 0 then
hidden_all = 1
vim.opt.showmode = false
vim.opt.ruler = false
vim.opt.laststatus = 0
vim.opt.showcmd = false
else
hidden_all = 0
vim.opt.showmode = true
vim.opt.ruler = true
vim.opt.laststatus = 2
vim.opt.showcmd = true
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a shorter version!

local hidden_all = false
local function toggle_hidden_all()
    vim.opt.showmode = hidden_all
    vim.opt.ruler = hidden_all
    vim.opt.showcmd = hidden_all
    vim.opt.laststatus = hidden_all and 2 or 0
    hidden_all = not hidden_all
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your version is far better thank you.

Comment on lines +153 to +166
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
pattern = "/tmp/neomutt*",
callback = function()
vim.cmd("Goyo 80")
vim.api.nvim_feedkeys("jk", "n", false)
end,
})
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
pattern = "/tmp/neomutt*",
callback = function()
vim.keymap.set("n", "ZZ", ":Goyo!|x!<CR>", { buffer = true, noremap = true })
vim.keymap.set("n", "ZQ", ":Goyo!|q!<CR>", { buffer = true, noremap = true })
end,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider merging these two

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this

})

-- Sudo write
vim.api.nvim_create_user_command("W", "silent! write !sudo tee % >/dev/null | edit!", {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NeoVim provides an API for cabbrev since 0.10! Consider using it.

vim.keymap.set("ca", "w!!", "execute 'silent! write !sudo tee % >/dev/null' | edit!")

Also, remember to state the change from w!! to W in the description of your PR. I like it!

Comment on lines +171 to +180
local currPos = vim.fn.getpos(".")
vim.cmd("%s/\\s\\+$//e")
vim.cmd("%s/\\n\\+\\%$//e")
if vim.bo.filetype == "c" or vim.bo.filetype == "h" then
vim.cmd("%s/\\%$/\r/e")
end
if vim.fn.expand("%"):match("neomutt") then
vim.cmd("%s/^--$/-- /e")
end
vim.fn.setpos(".", currPos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use the native Lua way of setting the position, however I must admit I don't consider it as readable as the vim.fn version.

local currPos = vim.api.nvim_win_get_cursor(0)
-- ...
vim.api.nvim_win_set_cursor(0, currPos)

The 0 here specifies the current window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this one as is for now.

@yushisora
Copy link

yushisora commented Sep 20, 2025

from :h nvim_create_autocmd()

Note: `pattern` is NOT automatically expanded (unlike with |:autocmd|),
thus names like "$HOME" and "~" must be expanded explicitly: >lua
    pattern = vim.fn.expand('~') .. '/some/path/*.py'

Those ~ in pattern of nvim_create_autocmd should be expand with vim.fn.expand('~') or vim.fs.normalize("~/some/path").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants