This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version of my neovim config in lua
This took quite a while but I liked doing this. I never really got into vimscript but writing Lua is more fun.
- Loading branch information
Showing
14 changed files
with
361 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vim.bo.shiftwidth = 2 | ||
vim.bo.tabstop = 2 | ||
vim.bo.softtabstop = 2 | ||
vim.bo.expandtab = true | ||
-- code folding using treesitter | ||
vim.wo.foldmethod = 'expr' | ||
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vim.bo.shiftwidth = 2 | ||
vim.bo.tabstop = 2 | ||
vim.bo.softtabstop = 2 | ||
vim.bo.expandtab = true | ||
-- code folding using treesitter | ||
vim.wo.foldmethod = 'expr' | ||
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-- NEOVIM SETTINGS | ||
-- INIT.LUA | ||
|
||
require('settings') | ||
require('options') | ||
require('keymaps') | ||
require('autocmd') | ||
require('plugins') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- NEOVIM AUTOCOMMANDS | ||
-- status updates for lua API on https://github.com/neovim/neovim/pull/14661 | ||
|
||
cmd = vim.cmd | ||
|
||
-- reset the cursor shape back to horizontal when exiting nvim | ||
cmd([[ | ||
augroup tmux_cursor | ||
autocmd! | ||
autocmd VimLeave,VimSuspend * :set guicursor=a:hor100 | ||
augroup END | ||
]]) | ||
|
||
-- disable/hide lsp diagnostics when we enter insert mode, activate/show it in | ||
-- normal mode | ||
cmd([[ | ||
augroup lsp_diagnostics | ||
autocmd! | ||
autocmd InsertEnter * silent! lua vim.diagnostic.hide() | ||
autocmd InsertLeave * silent! lua vim.diagnostic.show() | ||
]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- NEOVIM KEYBINDINGS | ||
|
||
local g = vim.g | ||
local map = vim.api.nvim_set_keymap | ||
local nmap_opt = { noremap = true, silent = true } | ||
local expr_opt = { noremap = true, expr = true } | ||
|
||
-- leader operations | ||
map('n', '<Space>', '<NOP>', {}) | ||
g.mapleader = ' ' | ||
g.maplocalleader = ' ' | ||
map('n', '<Leader>s', ':w<CR>', nmap_opt) | ||
map('n', '<Leader>q', ':wq<CR>', nmap_opt) | ||
map('n', '<Leader>z', ':ZenMode<CR>', nmap_opt) | ||
map('n', '<Leader>u', ':PackerSync<CR>', nmap_opt) | ||
|
||
-- disable arrow keys (why would you use arrow keys in nvim?!) | ||
map('n', '<Up>', '<NOP>', nmap_opt) | ||
map('n', '<Down>', '<NOP>', nmap_opt) | ||
map('n', '<Left>', '<NOP>', nmap_opt) | ||
map('n', '<Right>', '<NOP>', nmap_opt) | ||
|
||
-- center the position of the cursor on the first search result | ||
-- https://vi.stackexchange.com/a/10776 | ||
map('c', '<CR>', 'getcmdtype() =~ "[/?]" ? "<CR>zz" : "<CR>"', expr_opt) | ||
|
||
-- keep the search results on the center position during navigation | ||
map('n', 'n', 'nzz', nmap_opt) | ||
map('n', 'N', 'Nzz', nmap_opt) | ||
|
||
-- clear any highlights when <esc> is pressed | ||
map('n', '<Esc>', ':noh<CR>', nmap_opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
-- NEOVIM OPTIONS AND VARIABLES | ||
|
||
-- API aliases | ||
local g, o, opt = vim.g, vim.o, vim.opt | ||
|
||
-- quit loading these files as soon as they're sourced | ||
local runtime_files = { | ||
'netrw', | ||
'netrwPlugin', | ||
'netrwSettings', | ||
'netrwFileHandlers', | ||
'gzip', | ||
'zip', | ||
'zipPlugin', | ||
'tar', | ||
'tarPlugin', | ||
'getscript', | ||
'getscriptPlugin', | ||
'vimball', | ||
'vimballPlugin', | ||
'2html_plugin', | ||
'logipat', | ||
'rrhelper', | ||
'spellfile_plugin', | ||
'matchit', | ||
'fzf' | ||
} | ||
for _, plug in pairs(runtime_files) do | ||
g['loaded_' .. plug] = 1 | ||
end | ||
|
||
-- don't make nvim search for these providers because we aren't using them | ||
local providers = { | ||
'python_provider', | ||
'python3_provider', | ||
'ruby_provider', | ||
'node_provider' | ||
} | ||
for _, provider in pairs(providers) do | ||
g['loaded_' .. provider] = 0 | ||
end | ||
|
||
-- nvim configuration options | ||
opt.shortmess:append 'I' | ||
local options = { | ||
guicursor = 'n-v-r:block,i:hor100', | ||
secure = true, | ||
number = true, | ||
relativenumber = true, | ||
termguicolors = true, | ||
cursorline = true, | ||
showmode = false, | ||
signcolumn = 'number', | ||
splitright = true, | ||
splitbelow = true, | ||
ignorecase = true, | ||
smartcase = true, | ||
lazyredraw = true, | ||
synmaxcol = 240, | ||
clipboard = 'unnamedplus', | ||
background = 'dark' | ||
} | ||
for k, v in pairs(options) do | ||
o[k] = v | ||
end | ||
|
||
-- disable filetype.vim and enable filetype.lua whenever it becomes usable | ||
-- https://teddit.net/r/neovim/comments/rvwsl3/introducing_filetypelua_and_a_call_for_help/ | ||
-- g.did_load_filetypes = 0 | ||
-- g.do_filetype_lua = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
local clr = 'onedark' | ||
|
||
local ok, _ = pcall(vim.cmd, 'colorscheme ' .. clr) | ||
if not ok then | ||
vim.notify('unable to find ' .. clr) | ||
return | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--[[ | ||
phaazon/hop.nvim is an excellent alternative and it needs equivalent amount of | ||
keystrokes for jumping when you use `:HopPattern` but it won't jump to single | ||
occurence chars without confirmation and I'm not willing to use multiple | ||
different Hop commands mapped to multiple different keys. I want to be able to | ||
reach each and every character on the screen with only `s` and `S`. | ||
The disadvantage of lightspeed is that the characters shown on the screen | ||
aren't really deterministic and need to you understand how lightspeed works | ||
with its indicators. It wants you to keep typing the characters that either | ||
precede or follow the character you want to reach. This can be confusing and | ||
might contribute to mistakes. I'll use lightspeed for now and if I make | ||
mistakes, I'll switch to hop. | ||
the table for lazy loading lightsped is borrowed from | ||
https://github.com/ggandor/lightspeed.nvim/issues/35#issuecomment-939156128 | ||
--]] | ||
|
||
local keys = function() | ||
vim.g.lightspeed_no_default_keymaps = true | ||
local default_keymaps = { | ||
{ 'n', 'f', '<Plug>Lightspeed_s' }, | ||
{ 'n', 'F', '<Plug>Lightspeed_S' }, | ||
{ 'x', 'f', '<Plug>Lightspeed_s' }, | ||
{ 'x', 'F', '<Plug>Lightspeed_S' }, | ||
} | ||
for _, m in ipairs(default_keymaps) do | ||
vim.api.nvim_set_keymap(m[1], m[2], m[3], { silent = true }) | ||
end | ||
end | ||
|
||
keys() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local opts = { | ||
options = { | ||
icons_enabled = false, | ||
theme = 'onedark', | ||
component_separators = { '' }, | ||
section_separators = { '' }, | ||
}, | ||
} | ||
|
||
require('lualine').setup(opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
local ok, pairs = pcall(require, 'mini.pairs') | ||
if not ok then | ||
vim.notify('unable to find mini.pairs') | ||
return | ||
end | ||
|
||
local ok, surround = pcall(require, 'mini.surround') | ||
if not ok then | ||
vim.notify('unable to find mini.surround') | ||
return | ||
end | ||
|
||
local srd = { | ||
mappings = { | ||
find = '', | ||
find_left = '', | ||
update_n_lines = '' | ||
} | ||
} | ||
|
||
pairs.setup() | ||
surround.setup(srd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local ok, null = pcall(require, 'null-ls') | ||
if not ok then | ||
vim.notify('unable to find null-ls') | ||
return | ||
end | ||
|
||
local fn = vim.fn | ||
local null = require('null-ls') | ||
local format = null.builtins.formatting | ||
local linter = null.builtins.diagnostics | ||
|
||
local stylua_path = fn.expand('~/.config/stylua/stylua.toml') | ||
local stylua_status = fn.filereadable(stylua_path) | ||
|
||
-- specify the list of linters and formatters you want to use in this table | ||
local src = { | ||
format.shfmt.with({ | ||
extra_args = { '-i', '2', '-ci', '-sr', '-bn' }, | ||
}), | ||
linter.shellcheck, | ||
format.stylua.with({ | ||
condition = function() | ||
if stylua_status ~= 1 then | ||
vim.notify('unable to find stylua.toml') | ||
return false | ||
else | ||
return true | ||
end | ||
end, | ||
extra_args = { '-f', stylua_path }, | ||
}), | ||
} | ||
|
||
null.setup({ | ||
sources = src, | ||
on_attach = function(client) | ||
-- format on save | ||
if client.resolved_capabilities.document_formatting then | ||
vim.cmd([[ | ||
augroup LspFormatting | ||
autocmd! * <buffer> | ||
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync() | ||
augroup END | ||
]]) | ||
end | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local ok, configs = pcall(require, 'nvim-treesitter.configs') | ||
if not ok then | ||
vim.notify('unable to find nvim-treesitter') | ||
return | ||
end | ||
|
||
configs.setup { | ||
ensure_installed = { | ||
'bash', | ||
'fish', | ||
'json', | ||
'toml', | ||
'yaml', | ||
'lua', | ||
'vim' | ||
}, | ||
highlight = { | ||
enable = true, | ||
additional_vim_regex_highlighting = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local ok, zen = pcall(require, 'zen-mode') | ||
if not ok then | ||
vim.notify('unable to find zen-mode') | ||
return | ||
end | ||
|
||
zen.setup { | ||
plugins = { | ||
tmux = { | ||
enabled = true | ||
} | ||
} | ||
} |
Oops, something went wrong.