Replaced init.vim with init.lua. Error Checking feature added in a minimal fashion.#1465
Replaced init.vim with init.lua. Error Checking feature added in a minimal fashion.#1465lukerb52 wants to merge 8 commits intoLukeSmithxyz:masterfrom
Conversation
aartoni
left a comment
There was a problem hiding this comment.
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.
| vim.keymap.set("n", ",,", ":keepp /<++><CR>ca<", { noremap = true }) | ||
| vim.keymap.set("i", ",,", "<Esc>:keepp /<++><CR>ca<", { noremap = true }) |
There was a problem hiding this comment.
There are some new noremaps here that were not present in the Vimscript version, just checking if this was intended or just a typo
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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
| 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']() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I like this. I'll implement it
.config/nvim/init.lua
Outdated
| vim.api.nvim_create_autocmd("VimEnter", { | ||
| callback = function() vim.cmd("PlugInstall") end, | ||
| }) |
There was a problem hiding this comment.
You can just use the Ex command here.
vim.api.nvim_create_autocmd("VimEnter", { command = "PlugInstall" })There was a problem hiding this comment.
Yes I will use this.
.config/nvim/init.lua
Outdated
| vim.opt.ruler = false | ||
| vim.opt.laststatus = 0 | ||
| vim.opt.showcmd = false | ||
| vim.cmd("colorscheme vim") |
There was a problem hiding this comment.
The following is more idiomatic.
vim.cmd.colorscheme("vim")
.config/nvim/init.lua
Outdated
| 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 = '!' | ||
| ]]) |
There was a problem hiding this comment.
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
.config/nvim/init.lua
Outdated
| 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 |
There was a problem hiding this comment.
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
endThere was a problem hiding this comment.
your version is far better thank you.
| 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, | ||
| }) |
There was a problem hiding this comment.
Consider merging these two
There was a problem hiding this comment.
Thank you for catching this
.config/nvim/init.lua
Outdated
| }) | ||
|
|
||
| -- Sudo write | ||
| vim.api.nvim_create_user_command("W", "silent! write !sudo tee % >/dev/null | edit!", {}) |
There was a problem hiding this comment.
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!
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'll leave this one as is for now.
|
from Those |
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]smoves to the next spelling error and[smoves to the previous,]dand[dmove 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.csvin 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.