-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 623099b
Showing
19 changed files
with
913 additions
and
0 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,2 @@ | ||
.gitignore | ||
.git/* |
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,2 @@ | ||
.ctagsigore | ||
tags |
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,66 @@ | ||
# Neovim configuration with Lua | ||
|
||
A Neovim setup that (mainly) uses Lua to setup pluggins and configurations in an organized and readable manner. | ||
|
||
## Autocompletion | ||
|
||
### Setting up language servers | ||
|
||
Language servers must be installed from their relevant repo. Most servers are installed using `npm install`, but others like clangd and sumneko for Lua require more involved procedures. Here is a list of servers and installation methods: | ||
|
||
- Bash: bashls | ||
``` | ||
npm i -g bash-language-server | ||
``` | ||
- C/C++: clangd | ||
May have to try several versions, but 13 is the latest one. I am using 12 and 9 or 8 should be available. | ||
``` | ||
sudo apt-get install clangd-13 | ||
``` | ||
Then we must make it the default clangd (example with clangd-13): | ||
``` | ||
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-13 100 | ||
``` | ||
- Docker: dockerls | ||
``` | ||
npm i -g dockerfile-language-server-nodejs | ||
``` | ||
- Julia: julials | ||
``` | ||
julia --project=~/.julia/environments/nvim-lspconfig -e 'using Pkg; Pkg.add("LanguageServer")' | ||
``` | ||
- Json: jsonls | ||
``` | ||
npm i -g vscode-langservers-extracted | ||
``` | ||
- Lua: sumneko_lua | ||
This one is a tricky one as you have to manually clone the repo and then compile it. I did not have any issues, but I did have to install ninja for this, which can be done through `apt install ninja-build`. | ||
1. First clone: | ||
``` | ||
git clone https://github.com/sumneko/lua-language-server | ||
cd lua-language-server | ||
git submodule update --init --recursive | ||
``` | ||
2. Next we manually build the server binaries: | ||
``` | ||
cd 3rd/luamake | ||
./compile/install.sh | ||
cd ../.. | ||
./3rd/luamake/luamake rebuild | ||
``` | ||
The configuration file in the `lsp` folder for this server should reference these binaries and the root folder of the code. I've set it to `~/.local/share/nvim/site/lsp_servers/sumneko` there is `sumneko_lua` there which is the Lua module used to hook into this one, be careful no to overwrite. | ||
- Python: pyright: | ||
``` | ||
npm i -g pyright | ||
``` | ||
- YAML: yamlls | ||
TODO | ||
|
||
|
||
If a module complains about the verion of node being too old (pyright will do this), then run the following: | ||
``` | ||
sudo npm cache clean -f | ||
sudo npm install -g n | ||
sudo n stable | ||
``` | ||
Make sure to use the `-g` on all `npm` installs, otherwise the server won't be found. |
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,6 @@ | ||
-- Load all config files | ||
|
||
require('options') | ||
require('keymaps') | ||
require('plugins') | ||
require('theme') -- Theme at the end, to prevent overwrite by other 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,55 @@ | ||
local Utils = require('utils') | ||
|
||
-- local exprnnoremap = Utils.exprnnoremap | ||
local nnoremap = Utils.nnoremap | ||
local vnoremap = Utils.vnoremap | ||
-- local xnoremap = Utils.xnoremap | ||
local inoremap = Utils.inoremap | ||
-- local tnoremap = Utils.tnoremap | ||
local nmap = Utils.nmap | ||
local xmap = Utils.xmap | ||
|
||
vim.g.mapleader = " " | ||
vim.g.maplocalleader = " " | ||
|
||
-- kj to normal mode | ||
inoremap("kj", "<Esc>") | ||
|
||
-- Run omnifunc, mostly used for autocomplete | ||
inoremap("<C-SPACE>", "<C-x><C-o>") | ||
|
||
-- Save with Ctrl + S | ||
nnoremap("<C-s>", ":w<CR>") | ||
|
||
-- Move around windows | ||
nnoremap("<C-h>", "<C-w>h") | ||
nnoremap("<C-j>", "<C-w>j") | ||
nnoremap("<C-k>", "<C-w>k") | ||
nnoremap("<C-l>", "<C-w>l") | ||
|
||
-- Switch buffers (needs nvim-bufferline) | ||
nnoremap("<TAB>", ":BufferLineCycleNext<CR>") | ||
nnoremap("<S-TAB>", ":BufferLineCyclePrev<CR>") | ||
|
||
-- Delete buffer | ||
nnoremap("<A-w>", ":bd<CR>") | ||
|
||
-- Yank to end of line | ||
nnoremap("Y", "y$") | ||
|
||
-- Copy to system clippboard | ||
nnoremap("<leader>y", '"+y') | ||
vnoremap("<leader>y", '"+y') | ||
|
||
-- TODO: Paste from system clippboard | ||
|
||
-- Telescope | ||
nnoremap("<leader>ff", "<cmd>lua require('telescope.builtin').find_files()<CR>") | ||
nnoremap("<leader>fb", "<cmd>lua require('telescope.builtin').buffers()<CR>") | ||
|
||
-- NvimTree | ||
nnoremap("<leader>e", "<Cmd>NvimTreeToggle<CR>") | ||
|
||
-- EasyAlign | ||
-- xmap("ga", "<cmd>EasyAlign") | ||
-- nmap("ga", "<cmd>EasyAlign") |
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,44 @@ | ||
local fn = vim.fn | ||
local common_on_attach = require('lsp/utils').common_on_attach | ||
|
||
local system_name | ||
if fn.has('mac') == 1 then | ||
system_name = 'macOS' | ||
elseif fn.has('unix') == 1 then | ||
system_name = 'Linux' | ||
elseif fn.has('win32') == 1 then | ||
system_name = 'Windows' | ||
else | ||
print('Unsuported system for sumneko') | ||
end | ||
|
||
|
||
local sumneko_root_path = fn.stdpath('data')..'/lsp_servers/lua-language-server' | ||
local sumneko_binary = sumneko_root_path..'/bin/'..system_name..'/lua-language-server' | ||
|
||
local runtime_path = vim.split(package.path, ';') | ||
table.insert(runtime_path, "lua/?.lua") | ||
table.insert(runtime_path, "lua/?/init.lua") | ||
|
||
require'lspconfig'.sumneko_lua.setup { | ||
-- Does not have a default cmd, so we need to manually provide it | ||
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; | ||
settings = { | ||
Lua = { | ||
runtime = { | ||
version = 'LuaJIT', | ||
path = runtime_path, | ||
}, | ||
diagnostics = { | ||
globals = {'vim'}, | ||
}, | ||
workspace = { | ||
library = vim.api.nvim_get_runtime_file("",true), | ||
}, | ||
telemetry ={ | ||
enable = false, | ||
}, | ||
}, | ||
}, | ||
on_attach = common_on_attach, | ||
} |
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,43 @@ | ||
-- LSP helper function | ||
|
||
local cmd = vim.cmd | ||
|
||
local M = {} | ||
|
||
cmd([[autocmd ColorScheme * highlight NormalFloat guibg=#1f2335]]) | ||
cmd([[autocmd ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]) | ||
|
||
-- This function defines the on_attach function for several languages which share the same key-bidings | ||
function M.common_on_attach(client, bufnr) | ||
-- Set omnifunc | ||
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") | ||
|
||
-- Helper function | ||
local opts = {noremap = true, silent = true} | ||
local function bufnnoremap(lhs, rhs) | ||
vim.api.nvim_buf_set_keymap(bufnr, 'n', lhs, rhs, opts) | ||
end | ||
|
||
-- Keymaps: we need to define keymaps for each of the LSP functionalities manually | ||
-- Go to definition and declaration (use leader to presever standard use of 'gd') | ||
bufnnoremap("<leader>gd", "<Cmd>lua vim.lsp.buf.definition()<CR>") | ||
bufnnoremap("<leader>gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>") | ||
|
||
-- Go to implementations | ||
bufnnoremap("<leader>gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>") | ||
|
||
-- Inspect function | ||
bufnnoremap("K", "<Cmd>lua vim.lsp.buf.hover()<CR>") | ||
|
||
-- Signature help | ||
bufnnoremap("<C-k>", "<Cmd>lua vim.lsp.buf.signature_help()<CR>") | ||
|
||
-- Rename all references of symbol | ||
bufnnoremap("<leader>R", "<Cmd>lua vim.lsp.buf.rename()<CR>") | ||
|
||
if client.resolved_capabilities.document_formatting then | ||
cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()") | ||
end | ||
end | ||
|
||
return M |
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,42 @@ | ||
-- Visual | ||
vim.o.conceallevel = 0 -- Don't hide quotes in markdown | ||
vim.o.cmdheight = 1 | ||
vim.o.pumheight = 10 | ||
vim.o.showtabline = 2 | ||
vim.o.title = true | ||
vim.o.termguicolors = true -- Necessary for some plugins (eg. bufferline) | ||
vim.wo.number = true | ||
vim.wo.relativenumber = true | ||
vim.wo.signcolumn = 'yes' | ||
vim.wo.cursorline = true | ||
|
||
-- Behaviour | ||
vim.o.smarttab = true | ||
vim.o.tabstop = 2 | ||
vim.o.softtabstop = 2 | ||
vim.o.shiftwidth = 2 | ||
vim.o.smartindent = true | ||
vim.o.splitbelow = true | ||
vim.o.splitright = true | ||
vim.o.expandtab = true | ||
vim.o.mouse = 'a' | ||
|
||
-- Vim specific | ||
vim.o.hidden = true -- Do not save when switching buffers | ||
vim.o.fileencoding = "utf-8" | ||
vim.o.spelllang = 'en' | ||
vim.o.completeopt = "menuone,noselect" | ||
vim.o.updatetime = 100 | ||
|
||
-- Disable default plugins | ||
vim.g.loaded_netrwPlugin = false | ||
|
||
-- Disable inline error messages | ||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | ||
vim.lsp.diagnostic.on_publish_diagnostics, { | ||
virtual_text = false | ||
} | ||
) | ||
|
||
-- Define commands | ||
vim.cmd('command! MakeTags !ctags -R [email protected] .') |
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,124 @@ | ||
-- Plugin definition and loading | ||
-- local execute = vim.api.nvim_command | ||
local fn = vim.fn | ||
local cmd = vim.cmd | ||
|
||
-- Boostrap Packer | ||
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' | ||
local packer_bootstrap | ||
if fn.empty(fn.glob(install_path)) > 0 then | ||
packer_bootstrap = fn.system({'git', 'clone','https://github.com/wbthomason/packer.nvim', install_path}) | ||
end | ||
|
||
-- Rerun PackerCompile everytime pluggins.lua is updated | ||
cmd([[ | ||
augroup packer_user_config | ||
autocmd! | ||
autocmd BufWritePost plugins.lua source <afile> | PackerCompile | ||
augroup end | ||
]]) | ||
|
||
-- Load Packer | ||
cmd([[packadd packer.nvim]]) | ||
|
||
-- Initialize pluggins | ||
return require('packer').startup(function(use) | ||
-- Let Packer manage itself | ||
use({'wbtomason/packer.nvim', opt = true}) | ||
|
||
-- Formatting | ||
use 'tpope/vim-commentary' | ||
use 'junegunn/vim-easy-align' | ||
|
||
-- Themes | ||
use 'folke/tokyonight.nvim' | ||
use 'marko-cerovac/material.nvim' | ||
|
||
-- git commands | ||
use 'tpope/vim-fugitive' | ||
-- use 'airblade/vim-gitgutter' -- The standard one I use | ||
-- Trying out gitsigns | ||
use ({ | ||
'lewis6991/gitsigns.nvim', | ||
requires = {'nvim-lua/plenary.nvim'}, | ||
config = function() require('gitsigns').setup() end | ||
}) | ||
|
||
-- LSP server | ||
use({ | ||
'neovim/nvim-lspconfig', | ||
config = function() | ||
require('plugins/lspconfig') | ||
end | ||
}) | ||
use 'williamboman/nvim-lsp-installer' -- Helper for installing most language servers | ||
|
||
-- Autocomplete | ||
use({ | ||
"hrsh7th/nvim-cmp", | ||
requires = { | ||
"L3MON4D3/LuaSnip", | ||
"hrsh7th/cmp-nvim-lsp" | ||
}, | ||
config = function() | ||
require('plugins/cmp') | ||
end | ||
}) | ||
|
||
-- bufferline | ||
use({ | ||
'akinsho/nvim-bufferline.lua', | ||
requires = 'kyazdani42/nvim-web-devicons', | ||
config = function() | ||
require('plugins/bufferline') | ||
end, | ||
event = 'BufWinEnter', | ||
}) | ||
|
||
-- statusline | ||
use({ | ||
'hoob3rt/lualine.nvim', | ||
config = function() | ||
require('plugins/lualine') | ||
end, | ||
}) | ||
|
||
-- NvimTree | ||
use({ | ||
'kyazdani42/nvim-tree.lua', | ||
requires = 'kyazdani42/nvim-web-devicons', | ||
config = function() require('nvim-tree').setup({}) end -- Must add this manually | ||
}) | ||
|
||
-- Treesitter | ||
use({ | ||
'nvim-treesitter/nvim-treesitter', | ||
config = function() | ||
require('plugins/treesitter') | ||
end, | ||
run = ':TSUpdate' | ||
}) | ||
|
||
-- Telescope | ||
use({ | ||
'nvim-telescope/telescope.nvim', | ||
requires = {{'nvim-lua/plenary.nvim'}}, | ||
config = function() | ||
require('plugins/telescope') | ||
end | ||
}) | ||
|
||
use({'nvim-telescope/telescope-fzf-native.nvim', run ='make'}) | ||
|
||
-- Startify | ||
use({ | ||
'mhinz/vim-startify', | ||
config = function() | ||
require('plugins/startify') | ||
end | ||
}) | ||
|
||
if packer_bootstrap then | ||
require('packer').sync() | ||
end | ||
end) |
Oops, something went wrong.