initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
|
|
@ -0,0 +1,362 @@
|
|||
Configuration neovim pt2(Another way)
|
||||
https://www.youtube.com/watch?v=CVCBHHFXWNE
|
||||
https://files.catbox.moe/hyab70.mp4
|
||||
https://github.com/NvChad/NvChad
|
||||
|
||||
|
||||
[nvim.zip](../../../_resources/nvim.zip)
|
||||
|
||||
|
||||
|
||||
- Cloning to nvim
|
||||
`git clone https://github.com/NvChad/NvChad ~/.config/nvim depth 1`
|
||||
- Initializing
|
||||
Restart neovim and press N when ask to bout installation of something custom.Then wait for some installation.
|
||||
- Choose Theme
|
||||
Press space and type `th` to select through themes
|
||||
- Open TreeView
|
||||
Using `<C-N>`(Ctrl+N)
|
||||
- Switch between trreeview and normal text file
|
||||
`<C-H>` to go to treeview. `<C-L>` to go to normal text area
|
||||
- Create new file with treeview
|
||||
Type `a` to create new file when inside treeview
|
||||
|
||||
- Installing LSP
|
||||
In `~/.config/nvim/lua/custom/chadrc.lua` add this before `return M` line
|
||||
`M.plugins="custom.plugins"`
|
||||
Then create `~/.config/nvim/lua/custom/plugins.lua` and add
|
||||
```lua
|
||||
local plugins={
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
opts={
|
||||
ensure_installed={
|
||||
"typescript-language-server"
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
return plugins
|
||||
```
|
||||
And add tsserver inside ensure_installed like this and restart nvim and install it using the command `MasonInstallAll`.
|
||||
- Initializing nvim-lspconfig
|
||||
Add more like this
|
||||
```lua
|
||||
local plugins={
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
opts={
|
||||
ensure_installed={
|
||||
"typescript-language-server"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
config= function ()
|
||||
require "plugins.configs.lspconfig"
|
||||
require "custom.configs.lspconfig"
|
||||
end,
|
||||
},
|
||||
}
|
||||
return plugins
|
||||
```
|
||||
Create `~/.config/nvim/lua/custom/configs/lspconfig.lua` and open it. Here we store all our lsp configurations
|
||||
```lua
|
||||
-- Default nvchad configs
|
||||
local config=require("plugins.configs.lspconfig")
|
||||
-- Other default configs
|
||||
local on_attach =config.on_attach
|
||||
local capabilities =config.capabilities
|
||||
|
||||
-- For tsserver
|
||||
local lspconfig =require("lspconfig")
|
||||
|
||||
-- Here suggestions are set to be disabled to avoid useless clutter as useless suggestions were there
|
||||
lspconfig.tsserver.setup{
|
||||
on_attach=on_attach,
|
||||
capabilities=capabilities,
|
||||
init_options={
|
||||
preferences={
|
||||
disableSuggestions=true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
- Linting
|
||||
In `~/.config/nvim/lua/custom/plugins.lua` add eslint-lsp like this
|
||||
```
|
||||
ensure_installed={
|
||||
"eslint-lsp",
|
||||
"typescript-language-server"
|
||||
}
|
||||
|
||||
```
|
||||
Using nvim-lint by adding entry in plugins.lua like this
|
||||
```lua
|
||||
local plugins={
|
||||
{
|
||||
"mfussenegger/nvim-lint",
|
||||
event="VeryLazy",
|
||||
config=function ()
|
||||
require "custom.configs.lint"
|
||||
end
|
||||
},
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
opts={
|
||||
ensure_installed={
|
||||
"eslint-lsp",
|
||||
"typescript-language-server"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
config= function ()
|
||||
require "plugins.configs.lspconfig"
|
||||
require "custom.configs.lspconfig"
|
||||
end,
|
||||
},
|
||||
}
|
||||
return plugins
|
||||
```
|
||||
Create `~/.config/nvim/lua/custom/configs/lint.lua` and open it. Type this
|
||||
```lua
|
||||
require('lint').linters_by_ft={
|
||||
javascript={'eslint'},
|
||||
typescript={'eslint'}
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd({"BufWritePost"},{
|
||||
callback=function ()
|
||||
require("lint").try_lint()
|
||||
end,
|
||||
})
|
||||
|
||||
```
|
||||
Before working in project install eslint config in it by this
|
||||
`npm init @eslint/config`
|
||||
|
||||
- Auto-formatting
|
||||
Add "prettier" in ensure_installed section. Then add entry like this `plugins.lua`
|
||||
```lua
|
||||
local plugins={
|
||||
{
|
||||
"mhartington/formatter.nvim",
|
||||
event="VeryLazy",
|
||||
opts = function ()
|
||||
return require "custom.configs.formatter"
|
||||
end
|
||||
},
|
||||
{
|
||||
"mfussenegger/nvim-lint",
|
||||
event="VeryLazy",
|
||||
config=function ()
|
||||
require "custom.configs.lint"
|
||||
end
|
||||
},
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
opts={
|
||||
ensure_installed={
|
||||
"eslint-lsp",
|
||||
"prettier",
|
||||
"typescript-language-server"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
config= function ()
|
||||
require "plugins.configs.lspconfig"
|
||||
require "custom.configs.lspconfig"
|
||||
end,
|
||||
},
|
||||
}
|
||||
return plugins
|
||||
```
|
||||
Create `~/.config/nvim/lua/custom/configs/formatter.lua` and open it. Type this
|
||||
```lua
|
||||
local M={
|
||||
filetype={
|
||||
javascript={
|
||||
require("formatter.filetypes.javascript").prettier
|
||||
},
|
||||
typescript={
|
||||
require("formatter.filetypes.typescript").prettier
|
||||
},
|
||||
javascriptreact = {
|
||||
require("formatter.filetypes.javascript").prettier
|
||||
},
|
||||
typescriptreact = {
|
||||
require("formatter.filetypes.typescript").prettier
|
||||
},
|
||||
["*"]={
|
||||
require("formatter.filetypes.any").remove_trailing_whitespace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd({"BufWritePost"},{
|
||||
command = "FormatWriteLock"
|
||||
})
|
||||
|
||||
return M
|
||||
```
|
||||
|
||||
- null ls(optional)
|
||||
in `plugins.lua` file remove the entries for formatter and lint and instead add this entry
|
||||
```lua
|
||||
{
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event="VeryLazy",
|
||||
opts= function()
|
||||
return require "custom.configs.null-ls"
|
||||
end,
|
||||
},
|
||||
```
|
||||
Create `~/.config/nvim/lua/custom/configs/null-ls.lua` and open it. Type this
|
||||
```lua
|
||||
local augroup=vim.api.nvim_create_augroup("LspFormatting",{})
|
||||
local null_ls=require("null-ls")
|
||||
|
||||
local opts={
|
||||
sources= {
|
||||
null_ls.builtins.diagonstics.eslint,
|
||||
null_ls.builtins.formatting.prettier,
|
||||
},
|
||||
on_attach= function(client,bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({
|
||||
group=augroup,
|
||||
buffer=bufnr,
|
||||
})
|
||||
vim.api.nvim_create_autocmd("BufWritePre",{
|
||||
group=augroup,
|
||||
buffer=bufnr,
|
||||
callback=function()
|
||||
vim.lsp.buf.format({bufnr=bufnr})
|
||||
end,
|
||||
})
|
||||
}
|
||||
```
|
||||
Advantage : Linter runs dynamiclly rather than saving a file
|
||||
- Debugger
|
||||
We will use DAP(Debug Adapter Protocol)
|
||||
Add "js-debug-adapter" in ensure_installed section.
|
||||
Add this entry too in `plugins.lua` section
|
||||
```lua
|
||||
{
|
||||
"mfussenegger/nvim-dap",
|
||||
config=function ()
|
||||
require "custom.configs.dap"
|
||||
end
|
||||
},
|
||||
|
||||
```
|
||||
Create `~/.config/nvim/lua/custom/configs/dap.lua` and open it. Type this
|
||||
```lua
|
||||
local dap= require("dap")
|
||||
|
||||
dap.adapters["pwa-node"]={
|
||||
type="server",
|
||||
host="127.0.0.1",
|
||||
port=8123,
|
||||
executable={
|
||||
command="js-debug-adapter",
|
||||
}
|
||||
}
|
||||
|
||||
for _, language in ipairs {"typescript","javascript"} do
|
||||
dap.configurations[language]={
|
||||
{
|
||||
type="pwa-node",
|
||||
request="launch",
|
||||
name="Launch file",
|
||||
program="${file}",
|
||||
cwd="${workspaceFolder}",
|
||||
runtimeExecutable="node",
|
||||
},
|
||||
}
|
||||
end
|
||||
```
|
||||
We need to add ui for debugger too so add this as entry in `plugins.lua`
|
||||
```lua
|
||||
{
|
||||
|
||||
"rcarriga/nvim-dap-ui",
|
||||
event="VeryLazy",
|
||||
dependencies = "mfussenegger/nvim-dap",
|
||||
config=function ()
|
||||
local dap=require("dap")
|
||||
local dapui=require("dapui")
|
||||
require("dapui").setup()
|
||||
dap.listeners.after.event_initialized["dapui_config"] = function ()
|
||||
dapui.open()
|
||||
end
|
||||
dap.listeners.before.event_terminated["dapui_config"]=function ()
|
||||
dapui.close()
|
||||
end
|
||||
dap.listeners.before.event_exited["dapui_config"]=function ()
|
||||
dapui.close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
},
|
||||
```
|
||||
|
||||
Custom mappings for debugger
|
||||
Create `~/.config/nvim/lua/custom/mappings.lua` and open it and type.
|
||||
```lua
|
||||
local M = {}
|
||||
|
||||
M.dap={
|
||||
plugin=true,
|
||||
n = {
|
||||
["<leader>db"]={
|
||||
"<cmd> DapToggleBreakpoint <CR>",
|
||||
"Add breakpoint at line"
|
||||
},
|
||||
["<leader>dr"]= {
|
||||
"<cmd> DapContinue <CR>",
|
||||
"Run or continue the debugger"
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
```
|
||||
Now add this in nvim-dap entry like this in `plugins.lua`
|
||||
```lua
|
||||
{
|
||||
"mfussenegger/nvim-dap",
|
||||
config=function ()
|
||||
require "custom.configs.dap"
|
||||
require("core.utils").load_mappings("dap")
|
||||
end
|
||||
},
|
||||
```
|
||||
Finally in `chadrc.lua` add the mappings file too
|
||||
```lua
|
||||
|
||||
local M = {}
|
||||
|
||||
M.ui = { theme = 'oceanic-next' }
|
||||
M.plugins="custom.plugins"
|
||||
M.mappings=require "custom.mappings"
|
||||
|
||||
return M
|
||||
```
|
||||
|
||||
- Using debugger
|
||||
space and `db` to toggle breakpoint.
|
||||
To run debugger space and `dr`.
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue