Skip to content

Commit

Permalink
Neovim configuration for Go development using lazy.nvim and go.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCarrion committed May 20, 2024
1 parent 78c8350 commit e5ab66c
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 0 deletions.
1 change: 1 addition & 0 deletions 2024/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 2024

* [Go 1.22: What's new?](go-1-22-0/)
* [ Neovim configuration for Golang development using lazy.nvim and go.nvim](nvim-configuration/)
64 changes: 64 additions & 0 deletions 2024/nvim-configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Neovim configuration for Go development using lazy.nvim and go.nvim

* [YouTube Video](https://youtu.be/n5_WLgxwkU8)
* [Blog post](https://mariocarrion.com/2024/05/20/neovim-migrating-to-lazy-and-go-nvim.html)

## Requirements

* Install a patched font, my favorite is [JetBrains patched font](https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/JetBrainsMono).

If you're using [iTerm](https://www.iterm2.com/downloads.html), I recommend the following preferences:

* General -> Working Directory -> Advanced Configuration -> Working Directory for New Tabs -> Reuse previous session's directory
* Text -> Font -> JetBrainsMono Nerd Font
* Text -> Font -> Use ligatures
* Text -> Font -> Anti-aliased
* Keys -> General -> Left Option key -> Esc+
* Keys -> Key Mappings -> Presets -> Natural Text Editing

## Install

You can copy the content of this folder to your Neovim config path or create a
symbolic link, to know your Neovim config path use the following command:

```
:echo stdpath("config")
```

[lazy.nvim](https://github.com/folke/lazy.nvim) is the plugin manager, use `:Lazy` to install all plugins.

### Dependencies

Make sure the following are installed:

* Python 3: `brew install python`. Make sure is a recipe for python3.x, and then `pip3 install neovim`.
* `fd` alternative to `find`: `brew install fd`. Used by "telescope" plugins.

## Tricks

* Beautify JSON buffer: `:%!jq`

## Language Server Protocol Implementations

* [Go: gopls](https://github.com/golang/tools/tree/master/gopls)
```
go install golang.org/x/tools/gopls@latest
```

* [Python](https://github.com/microsoft/pyright)

```
brew install pyright
```

* [Ruby](https://solargraph.org/)

```
gem install solargraph
```

* [PHP](https://github.com/phpactor/phpactor)

```
brew install php
```
2 changes: 2 additions & 0 deletions 2024/nvim-configuration/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("mario.default")
require("mario.lazy")
31 changes: 31 additions & 0 deletions 2024/nvim-configuration/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"barbar.nvim": { "branch": "master", "commit": "c3ab0dbfe143ffb89a245e5b530f5349d6bb64e1" },
"catppuccin": { "branch": "main", "commit": "a1439ad7c584efb3d0ce14ccb835967f030450fe" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"csv.vim": { "branch": "master", "commit": "962f88787ec6873eba1c7dbbd81d2723f1ee3c4b" },
"friendly-snippets": { "branch": "main", "commit": "d5f74ce4dfdd82848f3f4eac65fe6e29ac5df4c2" },
"gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" },
"go.nvim": { "branch": "master", "commit": "24d2fa373d55d9900cd4b502a88214dc17e6fab6" },
"guihua.lua": { "branch": "master", "commit": "9fb6795474918b492d9ab01b1ebaf85e8bf6fe0b" },
"lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" },
"lsp_signature.nvim": { "branch": "master", "commit": "fed2c8389c148ff1dfdcdca63c2b48d08a50dea0" },
"lspkind-nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
"navigator.lua": { "branch": "master", "commit": "29d5f05bf9094cd0770018e19a27da81c247c503" },
"nvim": { "branch": "main", "commit": "6af91673ceccbd6e073b66c439e7fce239f72d24" },
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
"nvim-lspconfig": { "branch": "master", "commit": "1759ea68fbbb1303192020d3e59936189359e0ed" },
"nvim-surround": { "branch": "main", "commit": "6d0dc3dbb557bcc6a024969da461df4ba803fc48" },
"nvim-treesitter": { "branch": "master", "commit": "f197a15b0d1e8d555263af20add51450e5aaa1f0" },
"nvim-treesitter-context": { "branch": "master", "commit": "4fe0a54e86859744968e1a5c7867b49c86855774" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "19a91a38b02c1c28c14e0ba468d20ae1423c39b2" },
"nvim-web-devicons": { "branch": "master", "commit": "aaec87dbdaa776bfa0a13c8694bec9bcb7454719" },
"plenary.nvim": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" },
"telescope-file-browser.nvim": { "branch": "master", "commit": "5ee5002373655fd684a4ad0d47a3de876ceacf9a" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
"telescope.nvim": { "branch": "0.1.x", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" },
"vim-clang-format": { "branch": "master", "commit": "6b791825ff478061ad1c57b21bb1ed5a5fd0eb29" }
}
39 changes: 39 additions & 0 deletions 2024/nvim-configuration/lua/mario/default.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
vim.g.mapleader = ","

vim.opt.encoding = "utf-8"

vim.opt.compatible = false
vim.opt.hlsearch = true
vim.opt.relativenumber = true
vim.opt.laststatus = 2
vim.opt.vb = true
vim.opt.ruler = true
vim.opt.spell = true
vim.opt.spelllang = "en_us"
vim.opt.autoindent = true
vim.opt.colorcolumn = "120"
vim.opt.textwidth = 120
vim.opt.mouse = "a"
vim.opt.clipboard = "unnamed"
vim.opt.scrollbind = false
vim.opt.wildmenu = true

vim.opt.tabstop = 3
vim.opt.shiftwidth = 3

-- filetype related
vim.api.nvim_create_autocmd("FileType", {
pattern = {"gitcommit"},
callback = function(ev)
vim.api.nvim_set_option_value("textwidth", 72, {scope = "local"})
end
})

vim.api.nvim_create_autocmd("FileType", {
pattern = {"markdown"},
callback = function(ev)
vim.api.nvim_set_option_value("textwidth", 0, {scope = "local"})
vim.api.nvim_set_option_value("wrapmargin", 0, {scope = "local"})
vim.api.nvim_set_option_value("linebreak", 0, {scope = "local"})
end
})
18 changes: 18 additions & 0 deletions 2024/nvim-configuration/lua/mario/lazy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git", "--branch=stable", -- latest stable release
lazypath
})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({{import = "mario.plugins"}}, {
checker = {
enabled = false -- disable check for plugin updates
},
change_detection = {
enabled = false -- disable check for config file changes
}
})
56 changes: 56 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/barbar.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
return {
"romgrk/barbar.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons", -- patched fonts support
"lewis6991/gitsigns.nvim" -- display git status
},
init = function() vim.g.barbar_auto_setup = false end,
config = function()
local barbar = require("barbar")

barbar.setup({
clickable = true, -- Enables/disables clickable tabs
tabpages = false, -- Enable/disables current/total tabpages indicator (top right corner)
insert_at_end = true,
icons = {
button = "",
buffer_index = true,
filetype = {enabled = true},
visible = {modified = {buffer_number = false}},
gitsigns = {
added = {enabled = true, icon = "+"},
changed = {enabled = true, icon = "~"},
deleted = {enabled = true, icon = "-"}
}
}
})

-- key maps

local map = vim.api.nvim_set_keymap
local opts = {noremap = true, silent = true}

-- Move to previous/next
map("n", "<A-,>", "<Cmd>BufferPrevious<CR>", opts)
map("n", "<A-.>", "<Cmd>BufferNext<CR>", opts)
-- Re-order to previous/next
map("n", "<A-<>", "<Cmd>BufferMovePrevious<CR>", opts)
map("n", "<A->>", "<Cmd>BufferMoveNext<CR>", opts)
-- Goto buffer in position...
map("n", "<A-1>", "<Cmd>BufferGoto 1<CR>", opts)
map("n", "<A-2>", "<Cmd>BufferGoto 2<CR>", opts)
map("n", "<A-3>", "<Cmd>BufferGoto 3<CR>", opts)
map("n", "<A-4>", "<Cmd>BufferGoto 4<CR>", opts)
map("n", "<A-5>", "<Cmd>BufferGoto 5<CR>", opts)
map("n", "<A-6>", "<Cmd>BufferGoto 6<CR>", opts)
map("n", "<A-7>", "<Cmd>BufferGoto 7<CR>", opts)
map("n", "<A-8>", "<Cmd>BufferGoto 8<CR>", opts)
map("n", "<A-9>", "<Cmd>BufferGoto 9<CR>", opts)
map("n", "<A-0>", "<Cmd>BufferLast<CR>", opts)
-- Pin/unpin buffer
map("n", "<A-p>", "<Cmd>BufferPin<CR>", opts)
-- Close buffer
map("n", "<A-c>", "<Cmd>BufferClose<CR>", opts)
map("n", "<A-b>", "<Cmd>BufferCloseAllButCurrent<CR>", opts)
end
}
52 changes: 52 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/catppuccin-theme.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
return {
"catppuccin/nvim",
name = "catppuccin",
tag = "v1.7.0",
enabled = true,
priority = 1000,
config = function()
vim.opt.termguicolors = true

local catppuccin = require("catppuccin")

catppuccin.setup({
flavour = "mocha",
term_colors = true,
styles = {
conditionals = {},
functions = {"italic"},
types = {"bold"}
},
color_overrides = {
mocha = {
base = "#171717", -- background
surface2 = "#9A9A9A", -- comments
text = "#F6F6F6"
}
},
highlight_overrides = {
mocha = function(C)
return {
NvimTreeNormal = {bg = C.none},
CmpBorder = {fg = C.surface2},
Pmenu = {bg = C.none},
NormalFloat = {bg = C.none},
TelescopeBorder = {link = "FloatBorder"}
}
end
},
integrations = {
barbar = true,
cmp = true,
gitsigns = true,
native_lsp = {enabled = true},
nvimtree = true,
telescope = true,
treesitter = true,
treesitter_context = true
}
})

vim.cmd.colorscheme("catppuccin")
end
}
8 changes: 8 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/clang-format.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
return {
"rhysd/vim-clang-format",
init = function()
vim.cmd([[
autocmd FileType proto ClangFormatAutoEnable
]])
end
}
91 changes: 91 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp", -- cmp_nvim_lsp
"neovim/nvim-lspconfig", -- lspconfig
"onsails/lspkind-nvim", -- lspkind (VS pictograms)
{
"L3MON4D3/LuaSnip",
version = "v2.*",
build = "make install_jsregexp",
dependencies = {"rafamadriz/friendly-snippets"}, -- Snippets
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
-- https://github.com/rafamadriz/friendly-snippets/blob/main/snippets/go.json
end
}, {"saadparwaiz1/cmp_luasnip", enabled = true}
},
config = function()
local luasnip = require("luasnip")
local types = require("luasnip.util.types")

-- Display virtual text to indicate snippet has more nodes
luasnip.config.setup({
ext_opts = {
[types.choiceNode] = {
active = {virt_text = {{"", "GruvboxRed"}}}
},
[types.insertNode] = {
active = {virt_text = {{"", "GruvboxBlue"}}}
}
}
})

local cmp = require("cmp")
local lspkind = require("lspkind")

cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered()
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({select = true}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, {"i", "s"})
}),
sources = cmp.config.sources({
{name = "nvim_lsp"}, {name = "luasnip"}, {name = "buffer"}
}),
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
maxwidth = 70,
show_labelDetails = true
})
}
})

local lspconfig = require("lspconfig")

-- All languages: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md

-- Default lspconfig values for Go are set by `navigator`
-- Go: go install golang.org/x/tools/gopls@latest

-- Python: brew install pyright
lspconfig["pyright"].setup {}

-- Ruby: gem install solargraph
lspconfig["solargraph"].setup {}

-- https://phpactor.readthedocs.io/en/master/usage/standalone.html#installation
lspconfig["phpactor"].setup {}
end
}
5 changes: 5 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/comment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
"numToStr/Comment.nvim",
dependencies = {"nvim-treesitter/nvim-treesitter"},
config = function() require("Comment").setup() end
}
1 change: 1 addition & 0 deletions 2024/nvim-configuration/lua/mario/plugins/csv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {"chrisbra/csv.vim", enabled = true}
4 changes: 4 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return {
"lewis6991/gitsigns.nvim",
config = function() require("gitsigns").setup() end
}
7 changes: 7 additions & 0 deletions 2024/nvim-configuration/lua/mario/plugins/lualine.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
return {
"nvim-lualine/lualine.nvim",
dependencies = {"nvim-tree/nvim-web-devicons", "catppuccin/nvim"},
config = function()
require("lualine").setup({options = {theme = "catppuccin"}})
end
}
Loading

0 comments on commit e5ab66c

Please sign in to comment.