mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 00:25:47 +02:00
No results
13
6. Configurations
Asep Komarudin edited this page 2024-06-25 20:18:14 +07:00
Table of Contents
File Structure
.
├── init.lua * This is the config entrance
├── lazy-lock.json * This is the file generated from Lazy.nvim
├── lua
│ ├── custom
│ │ ├── dashboard.lua * This is for custom dashboard configurations
│ │ └── default.lua * This is for all custom (adjustment to user needs)
│ ├── default
│ │ ├── autocommands.lua * This is for custom auto commands
│ │ ├── init.lua * This is the entry point for all configs
│ │ ├── keymaps.lua * This is for custom keymaps
│ │ ├── lazy.lua * This is the plugins manager config (don't change it)
│ │ └── options.lua * This is for neovim's default config
│ └── plugin
│ ├── dapui.lua * This is an example of a plugin
│ └── init.lua * This is for adding, disabling and overriding plugins
├── my-snippets
│ └── package.json * This is used for custom snippets
└── README.md
KeyMaps
- leader = space bar
- n = normal mode
- i = insert mode
- v = visual mode
Mode | Key | Descriptions |
n | leader | Open the Wich Key |
n | leader + / | Comment String |
n | leader + a | Alpha Dashboard |
n | leader + b | Buffer |
n | leader + c | Close Buffer |
n | leader + e | Exploler (Nvim Tree) |
n | leader + F | Search Text |
n | leader + f | Search File |
n | leader + h | Disable hilight |
n | leader + q | Exit Neovim |
n | leader + w | Write File |
n | leader + g | git |
n | leader + l | LSP |
n | leader + p | Plugin (Lazy) |
n | leader + r | Run Program |
n | leader + s | Search |
n | leader + t | Terminal |
v | leader + / | Comment Blok String |
v/i | Shift + Up | Duplicate Row Up |
v/i | Shift + Down | Duplicate Row Down |
v/i | ALT + UP | Move Row Up |
v/i | ALT + Down | Move Row Down |
v | CTRL + n | Select Multi Cursor |
n | CTRL + a | Selelect all |
n/v/x | CTRL + c | Copy selected |
x/n/v | CTRL + v | Paste |
n | CTRL + / | Comment row focus |
v | CTRL + / | Comment Block visual |
n | CTRL + Left/Right | Resize Window |
n | CTRL + l | Navigate window right |
n | CTRL + h | Navigate window left |
n | CTRL + j | Navigate window Down |
n | CTRL + k | Navigate window Up |
n | SHIFT + h/l | tab buffer navigation |
LSP Configuration
- Install language servers with Mason
:MasonInstall html-lsp css-lsp typescript-language-server
This will install the following language servers:
- html-lsp for HTML
- css-lsp for CSS
- typescript-language-server for TypeScript
Register language servers manually
If the language server you want to install is not listed in the :MasonInstall command, you can register it manually in the lua/custom/register_lsp.lua file.
Language support reference
For a list of all supported language servers, see the Mason.nvim documentation: https://github.com/williamboman/mason.nvim/blob/main/PACKAGES.md.
Comfig Treesitter
- Run the following code on the command
:TSInstall html css javascript ..... dst
- Language Support Reference
https://github.com/nvim-treesitter/nvim-treesitter#supported-languages
Change Dashboard
-
Find the File lua/custom/dashboard.lua
-
Edit this part
-- Change the Dashboard
-- 1. Open the remark on bellow
-- 2. Change the dashboard ASCII art
-- vim.g.pcode_dashboard1 = {
-- [[ _ __ __ ]],
-- [[ ___ ___ (____ / /__ _______ ___/ ___ ]],
-- [[ / _ / _ \ / / _ \/ '_/ / __/ _ / _ / -_) ]],
-- [[ / .__\_____/ /\___/_/\_\ \__/\___\_,_/\__/ ]],
-- [[ /_/ |___/ ]],
-- }
-- vim.g.pcode_dashboard2 = {
-- [[ __ ]],
-- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]],
-- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]],
-- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]],
-- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
-- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
-- }
-- vim.g.pcode_footer = "PCode"
vim.g.pcode_model = 2 -- input 1 or 2 for dashboard model
- Link Generate Dasboard https://patorjk.com/software/taag/
Custom User Config
- Find the file lua/custom/default.lua
-- custom colorscheme
-- colorscheme ready :
-- tokyonight, tokyonight-night, tokyonight-storm, tokyonight-day, tokyonight-moon
-- gruvbox-baby (default)
-- sonokai, sonokai_atlantis,
-- sonokai_andromeda,sonokai_shusia,sonokai_maia,sonokai_espresso
-- material, material_deepocean, material_palenight, material_lighter, material_darker
-- onedark, onedark_darker, onedark_cool, onedark_deep,onedark_warm,
-- onedark_warmer, onedark_light
-- lunar
-- nord
-- catppuccin, catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha
-- dracula
-- nightfox, dayfox, dawnfox, duskfox, nordfox, terafox, carbonfox
vim.g.pcode_colorscheme = "gruvbox-baby"
-- custom transparent mode
-- only support
-- gruvbox-baby,
-- tokyonight,
-- sonokai,
-- material
-- onedark
-- catppuccin
-- nord
-- dracula
-- nightfox
-- 0 =off 1= on
vim.g.pcode_transparent_mode = 0
-- 0 disable progress
-- 1 lualine lsp progress
-- 2 fidget progress
vim.g.pcode_progress = 2
-- style
-- 0 = default
-- 1 = { left = "", right = "" },
-- 2 = { left = " ", right = " " },
-- 3 = { left = "", right = "" },
vim.g.pcode_lualine_style = 0
-- style status icon
-- 0 = default
-- 1 = vim icon " "
-- 2 = vim icon " "
vim.g.pcode_status_icon = 0
-- start custom lualine style
-- contoh style
-- {
-- { left = "│", right = "│" },
-- { left = " ", right = " " },
-- },
-- {
-- { left = " ", right = " " },
-- { left = " ", right = "" },
-- },
-- {
-- { left = " ", right = " " },
-- { left = "", right = "" },
-- },
-- {
-- { left = "", right = "" },
-- { left = "", right = "" },
-- },
-- {
-- { left = " ", right = " " },
-- { left = "", right = "" },
-- },
-- }
vim.g.pcode_custom_lualine = false
vim.g.pcode_component_separators = { left = " ", right = " " }
vim.g.pcode_section_separators = { left = "", right = " " }
-- 0 ( format jalan) 1 (fromat off)
vim.g.pcode_format_on_save = 1
-- ini hanya untuk lsp yg tidak support masson
-- untuk referesi support language kunjungi link dibawah
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
vim.g.pcode_lsp_installer = {
"yamlls",
-- tambahkan di bawah sini
}
-- untuk referesi support language kunjungi link dibawah
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
vim.g.pcode_mason_ensure_installed = { -- sebelumnya register_lsp
"yamlls",
-- "intelephense",
-- "marksman",
-- "csharp_ls",
-- "clangd",
-- "dartls",
-- "kotlin_language_server",
-- tambahkan di bawah sini setelah melakukan :masoninstall
}
vim.g.pcode_unregister_lsp = {
"jdtls", -- tambahkan di bawah ini
}
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md
local formatting = {}
local diagnostics = {}
vim.g.pcode_null_ls_sources = {
formatting.stylua, -- tambahkan di bawah sini
diagnostics.flake8, -- tambahkan di bawah sini
}
-- https://github.com/folke/which-key.nvim
vim.g.pcode_whichkey = {
-- contoh penambahan
-- ["k"] = {
-- name = "Example",
-- k = { '<cmd>lua print("Testing")<cr>', "Example" },
-- },
["r"] = {
name = "Run",
j = { "<cmd>Jaq float<CR>", "Run With Jaq" },
},
["o"] = { "<cmd>SymbolsOutline<cr>", "Symbol Outline" },
}
-- https://github.com/CRAG666/code_runner.nvim
-- ready default java, python, typescript, javascript, rust, cpp, scss
vim.g.pcode_coderunner = {
go = "go run $fileName",
}
Custom Autocommand
- Find the file lua/default/autocommand.lua
- Configure according to your needs
- Example :
vim.cmd([[
augroup _markdown
autocmd!
autocmd FileType markdown setlocal wrap
autocmd FileType markdown setlocal spell
augroup end
]])
Cutom Default Option
- Find the file lua/default/options.lua
- Example :
vim.g.mapleader = " "
vim.g.maplocalleader = " "
local opt = vim.opt
opt.autowrite = true -- Enable auto write
opt.clipboard = "unnamedplus" -- Sync with system clipboard
opt.completeopt = "menu,menuone,noselect"
opt.conceallevel = 3 -- Hide * markup for bold and italic
opt.confirm = true -- Confirm to save changes before exiting modified buffer
opt.cursorline = true -- Enable highlighting of the current line
opt.expandtab = true -- Use spaces instead of tabs
opt.formatoptions = "jcroqlnt" -- tcqj
opt.grepformat = "%f:%l:%c:%m"
opt.grepprg = "rg --vimgrep"
opt.ignorecase = true -- Ignore case
opt.inccommand = "nosplit" -- preview incremental substitute
opt.laststatus = 0
opt.list = true -- Show some invisible characters (tabs...
opt.mouse = "a" -- Enable mouse mode
opt.number = true -- Print line number
opt.pumblend = 10 -- Popup blend
opt.pumheight = 10 -- Maximum number of entries in a popup
opt.relativenumber = true -- Relative line numbers
opt.scrolloff = 4 -- Lines of context
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" }
opt.shiftround = true -- Round indent
opt.shiftwidth = 2 -- Size of an indent
opt.shortmess:append { W = true, I = true, c = true }
opt.showmode = false -- Dont show mode since we have a statusline
opt.sidescrolloff = 8 -- Columns of context
opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time
opt.smartcase = true -- Don't ignore case with capitals
opt.smartindent = true -- Insert indents automatically
opt.spelllang = { "en" }
opt.splitbelow = true -- Put new windows below current
opt.splitright = true -- Put new windows right of current
opt.tabstop = 2 -- Number of spaces tabs count for
opt.termguicolors = true -- True color support
opt.timeoutlen = 300
opt.undofile = true
opt.undolevels = 10000
opt.updatetime = 200 -- Save swap file and trigger CursorHold
opt.wildmode = "longest:full,full" -- Command-line completion mode
opt.winminwidth = 5 -- Minimum window width
opt.wrap = false -- Disable line wrap
if vim.fn.has("nvim-0.9.0") == 1 then
opt.splitkeep = "screen"
opt.shortmess:append { C = true }
end
-- Fix markdown indentation settings
vim.g.markdown_recommended_style = 0
Custom Key Mapping
- Find the file lua/dafault/keymaps.lua
-- custom key maps here
local function map(mode, l, r, desc)
vim.keymap.set(mode, l, r, { desc = desc })
end
-- this is an example
map("n", "]h", '<cmd>lua print("Testing")<cr>', "Testing Mapping")
Custom Plugins
- Find the file lua/plugin/*
- Create file plgins in folder lua/plugin
- Disable plugins
{ "folke/trouble.nvim", enabled = false }, -- ini untuk disable plugin
- Add new custom plugins
{"nvim-treesitter/nvim-treesitter"},
For exaple refer to
https://github.com/folke/lazy.nvim#Examples
Custom-Snippets
- Find the File nvim/my-snippet/package.json
- Add custom snippets in the part
"contributes": {
"snippets": [
{
"language": "html",
"path": "./html/snippets/javascript.json"
},
{
"language": "html",
"path": "./html/javascript/javascript.json"
},
]
}
Manually load custom snippets
- Crate file lua/default/snippets.lua
local status_ok = pcall(require, "luasnip")
if not status_ok then
return
end
-- buat folser di nvim/my-snippets/
-- didalamnya untuk menampung snippet kita (foler html,javascript dsb...)
local lpath = vim.fn.stdpath("config") .. "/my-snippets"
-- buat snippet sesuai kebutuhan saja
-- jika terlalu banyak malah jadi lambat
require("luasnip.loaders.from_vscode").lazy_load({
paths = lpath .. "/html",
})
require("luasnip.loaders.from_vscode").lazy_load({
paths = lpath .. "/javascript-snippet",
})
require("luasnip.loaders.from_vscode").load({ paths = lpath .. "/html" })
require("luasnip.loaders.from_vscode").load({ paths = lpath .. "/javascript-snippet" })
- Call the config from lua/default/init.lua
require("default.snippets")
Neovide Configuration
- Open the file lua/default/options.lua
if vim.g.neovide then
vim.g.neovide_input_use_logo = 1 -- enable use of the logo (cmd) key
vim.keymap.set("n", "<c-s>", ":w<CR>") -- Save
vim.keymap.set("v", "<c-c>", '"+y') -- Copy
vim.keymap.set("n", "<c-v>", '"+P') -- Paste normal mode
vim.keymap.set("v", "<c-v>", '"+P') -- Paste visual mode
vim.keymap.set("c", "<c-v>", "<C-R>+") -- Paste command mode
vim.keymap.set("i", "<c-v>", '<ESC>l"+Pli') -- Paste insert mode
vim.o.guifont = "CaskaydiaCove_Nerd_Font:h17"
vim.g.neovide_padding_top = 0
vim.g.neovide_padding_bottom = 0
vim.g.neovide_padding_right = 0
vim.g.neovide_padding_left = 0
-- config for transparent
--vim.g.neovide_transparency = 0.8
vim.g.neovide_transparency = 1
vim.g.neovide_underline_automatic_scaling = false
vim.g.neovide_refresh_rate_idle = 5
vim.g.neovide_no_idle = true
vim.g.neovide_remember_window_size = true
vim.g.neovide_touch_drag_timeout = 0.17
-- animation config
--vim.g.neovide_scroll_animation_length = 0.3
--vim.g.neovide_cursor_animation_length = 0.13
vim.g.neovide_cursor_trail_size = 0.8
vim.g.neovide_cursor_antialiasing = true
vim.g.neovide_cursor_animate_in_insert_mode = true
vim.g.neovide_cursor_vfx_mode = "torpedo"
vim.opt.cmdheight = 0
end
-- Allow clipboard copy paste in neovim
vim.g.neovide_input_use_logo = 1
vim.api.nvim_set_keymap("", "<c-v>", "+p<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("!", "<c-v>", "<C-R>+", { noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<c-v>", "<C-R>+", { noremap = true, silent = true })
vim.api.nvim_set_keymap("v", "<c-v>", "<C-R>+", { noremap = true, silent = true })
Config Transparant Background
- Find File lua/custom/default.lua and update config
vim.g.pcode_transparent_mode = 1
vim.g.pcode_clear_lualine = 1
- Delete last load config
# linux / mac
rm -rf ~/.local/share/nvim
# windows Powershell
rm -Force ~\AppData\Local\nvim-data
# windows cmd
rd -r ~\AppData\Local\nvim-data
- Create config plugin transparant
- Create file lua/plugin/transparant.lua
return {
{
"akinsho/bufferline.nvim",
event = "BufWinEnter",
config = function()
require("user.bufferline")
end,
},
{
"nvim-lualine/lualine.nvim",
event = "BufWinEnter",
config = function()
require("user.lualine")
end,
},
-- transparant config
{
"xiyaowong/transparent.nvim",
event = "BufWinEnter",
cmd = { "TransparentToggle", "TransparentEnable", "TransparentDisable" },
config = function()
require("transparent").clear_prefix("BufferLine")
-- clear prefix for which-key
require("transparent").clear_prefix("WhichKey")
-- clear prefix for lazy.nvim
require("transparent").clear_prefix("Lazy")
-- clear prefix for NvimTree
require("transparent").clear_prefix("NvimTree")
-- clear prefix for NeoTree
require("transparent").clear_prefix("NeoTree")
-- clear prefix for Lualine
require("transparent").clear_prefix("Lualine")
require("transparent").setup({
extra_groups = {},
exclude_groups = {
-- disable active selection backgroun
"CursorLine",
"CursorLineNR",
"CursorLineSign",
"CursorLineFold",
-- disable nvimtree CursorLine
"NvimTreeCursorLine",
-- disable Neotree CursorLine
"NeoTreeCursorLine",
},
})
end,
},
}
Config Rust
- Open file lua/custom/default.lua
- Add rust_analizer to mason install
pcode.mason_ensure_installed = { -- sebelumnya register_lsp
"rust_analyzer",
}
- add ignore auto config
pcode.unregister_lsp = {
"rust_analyzer",
}
- create file lua/plugin/rust.lua
return {
{
"rust-lang/rust.vim",
ft = "rust",
init = function()
vim.g.rustfmt_autosave = 1
end,
},
{
"saecki/crates.nvim",
tag = "stable",
ft = { "toml" },
config = function()
require("crates").setup()
end,
},
{
"mrcjkb/rustaceanvim",
version = "^4",
ft = { "rust" },
dependencies = "neovim/nvim-lspconfig",
config = function()
local on_attach = require("user.lsp.handlers").on_attach
local capabilities = require("user.lsp.handlers").capabilities
vim.g.rustaceanvim = {
server = {
on_attach = on_attach,
capabilities = capabilities,
},
}
end,
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("neotest").setup({
adapters = {
require("rustaceanvim.neotest"),
},
})
end,
-- stylua: ignore
keys = {
{ "<leader>T","",desc=" Test"},
{ "<leader>Tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
{ "<leader>Tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
{ "<leader>TT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" },
{ "<leader>Tl", function() require("neotest").run.run_last() end, desc = "Run Last" },
{ "<Leader>Ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
{ "<leader>To", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
{ "<Leader>TO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
{ "<Leader>TS", function() require("neotest").run.stop() end, desc = "Stop" },
},
},
{
"mfussenegger/nvim-dap",
event = "BufReadPre",
dependencies = {
"rcarriga/nvim-dap-ui",
"theHamsta/nvim-dap-virtual-text",
"nvim-neotest/nvim-nio",
"williamboman/mason.nvim",
"jay-babu/mason-nvim-dap.nvim",
},
config = function()
require("nvim-dap-virtual-text").setup({
virt_text_pos = "eol",
commented = true,
})
require("mason-nvim-dap").setup({
automatic_installation = true,
automatic_setup = true,
handlers = {},
ensure_installed = { "codelldb" },
})
local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/")
local debugrs_path = mason_path .. "packages/codelldb/extension/adapter/codelldb"
require("user.dapui")
local dap = require("dap")
dap.adapters.codelldb = {
type = "server",
port = "${port}",
executable = {
-- CHANGE THIS to your path!
command = debugrs_path,
args = { "--port", "${port}" },
-- On windows you may have to uncomment this:
detached = vim.fn.has("win32") and false or true,
},
}
end,
keys = {
{ "<leader>d", "", desc = " Debug" },
{ "<leader>dt", "<cmd>lua require'dap'.toggle_breakpoint()<cr>", desc = "Toggle Breakpoint" },
{ "<leader>db", "<cmd>lua require'dap'.step_back()<cr>", desc = "Step Back" },
{ "<leader>dc", "<cmd>lua require'dap'.continue()<cr>", desc = "Continue" },
{ "<leader>dC", "<cmd>lua require'dap'.run_to_cursor()<cr>", desc = "Run To Cursor" },
{ "<leader>dd", "<cmd>lua require'dap'.disconnect()<cr>", desc = "Disconnect" },
{ "<leader>dg", "<cmd>lua require'dap'.session()<cr>", desc = "Get Session" },
{ "<leader>di", "<cmd>lua require'dap'.step_into()<cr>", desc = "Step Into" },
{ "<leader>do", "<cmd>lua require'dap'.step_over()<cr>", desc = "Step Over" },
{ "<leader>du", "<cmd>lua require'dap'.step_out()<cr>", desc = "Step Out" },
{ "<leader>dp", "<cmd>lua require'dap'.pause()<cr>", desc = "Pause" },
{ "<leader>dr", "<cmd>lua require'dap'.repl.toggle()<cr>", desc = "Toggle Repl" },
{ "<leader>ds", "<cmd>lua require'dap'.continue()<cr>", desc = "Start" },
{ "<leader>dq", "<cmd>lua require'dap'.close()<cr>", desc = "Quit" },
{ "<leader>dU", "<cmd>lua require'dapui'.toggle({reset = true})<cr>", desc = "Toggle UI" },
},
},
}
Config LSP JDTLS
return {
"neovim/nvim-lspconfig",
config = function()
require("lspconfig").jdtls.setup({
cmd = {
"jdtls",
"-configuration",
vim.fn.expand("$HOME") .. "/.cache/jdtls/config",
"-data",
vim.fn.expand("$HOME") .. "/.cache/jdtls/workspace",
},
filetypes = { "java" },
root_dir = require("lspconfig.util").root_pattern(
-- Single-module projects
{
"build.xml", -- Ant
"pom.xml", -- Maven
"settings.gradle", -- Gradle
"settings.gradle.kts", -- Gradle
},
-- Multi-module projects
{ "build.gradle", "build.gradle.kts" }
) or vim.fn.getcwd(),
singe_file_support = true,
})
end,
}