This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e
8 changed files with 94691 additions and 0 deletions

View file

@ -0,0 +1,40 @@
Basics 3
- cursor location
`<C-g>` to show location in file and file status. It means 'Ctrl+G'.
`gg` is used to to start of file like using Ctrl+Home in gui editors
`G` for end of file
To go to specific line number `<line_number>G`. Eg: for line number 123 type `123G`.
- Search command
To search word type `/<word>`. To search error type `/error`. Then type `n` to go to next search and `N` to go to opposite one.
`/` is used to search in direction from up to down. To search in direction from down to up use `?`.
Note: To remove highlighting of previous search type `:let @/ = ""` or use `:noh`
Reference: https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting
To go back to where you came from press `<C-o>`.
(keep `<Ctrl>` pressed down while pressing the letter `o`).
Repeat to go back further. `<C-i>`{normal} goes forward.
- Matching parenthesis search
Type `%` to find a matching `)`,`]`, or `}`.
Place the cursor on parenthesis For eg on `(`
tree (they r here [done] )
Then type `%`. it will move to `)` . Now type `%` again and it will move back to `(`.
- Substitute command
Type `:s/old/new/g` to substitute "new" for "old".
Move the cursor to line where subtitution needed to be take place. If g is not used then only first occurence will be substituted instead of all occurences of current line.
`:201,204s/old/new/g` : replace old with new from line 201 to 204
For whole file
`%s/old/new/g`
For whole file but with prompt
`%s/old/new/gc`
- Executing external commands
`:!ls` or `:!pwd`
- Selecting text to write
To start selecting text press `v` then move cursor right and down to area u want ti selected. To finish selecting a text type colon `:` `'<,'>` will appear now just type `w` and file name where u want to be saved
`'<,'>w Test.txt`. Now selected text will be saved in filename 'Test.txt'
- Retrieving and merging file
Move cursor to desired line and type
`:r TEST` :This will copy contents of file TEST to current position
`:r !ls` : This will copy output of commands ls to current position

View file

@ -0,0 +1,44 @@
Basics 4
- Open a line
To insert empty line below cursor and toggle insert mode type `o`
To insert empty line above cursor and toggle insert mode type `O`(capital o)
- Append command
Normally when we insert text, its inserted before the cursor so in the word say `li`. If cursor at `i`. and we press i then type q then we have `lqi` so using
`a` first cursor is moved one character right and then goes to insert mode so if after using `a` we type q, then we have `liq`.
- Replace Mode
Toggled by `R`(capital R). if it is on word say `the` and cursor is at beginning ie `T` then when we type Say then it will become `Say` not SayThe.
NOTE: Replace mode is like Insert mode, but every typed character
replaces an existing character
- Copy and paste
Highlight the text to be copied. We can do this by going to visual mode by pressing `v` and moving cursor to select text. Press Esc to escape visual mode. Press `y` to copy and `p` tp paste.
y here stands for yank
p stands for put
- Set option
To alter some settings in nvim
when searching to ignore case type `:set ic`
To turn off ignore case type `:set noic`
To toggle ignorecase setting `:set invic`
NOTE: If you want to ignore case for just one search command, use `\c`
in the phrase: `/ignore\c`
- Switch between windows
`<C-w><C-w>` means Ctrl+w 2 times
- Creating startup script
Neovim is a very configurable editor. You can customise it any way you like.
To start using more features create an "init.vim" file.
1. Start editing the "init.vim" file.
`:call mkdir(stdpath('config'),'p')`
`:exe 'edit' stdpath('config').'/init.vim'`
2. Write the file with:
`:w`
- Auto Completion
When typing any command to get the listed list of commands begining with whatever typed , press `<C-d>`. Now press `tab` to auto-complete it.
Eg: If we type `:e` then pressing Ctrl+d witll list commands starting from `e` and pressing tab will autocomplete with first result
- Switching between files
When u have opened nvim in folder and that folder contains some files then use the relative path to access them by
`:e main.c` or `:e Makefile`

View file

@ -0,0 +1,42 @@
Basics
↑
k Hint: The `h`{normal} key is at the left and moves left.
← h l → The `l`{normal} key is at the right and moves right.
j The `j`{normal} key looks like a down arrow.
↓
h (left) j (down) k (up) l (right)
- Install xclip for x11 Display server
`pacman -S xclip`
For others
- g:clipboard
- pbcopy, pbpaste (macOS)
- wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
- waycopy, waypaste (if $WAYLAND_DISPLAY is set)
- xclip (if $DISPLAY is set)
- xsel (if $DISPLAY is set)
- lemonade (for SSH) https://github.com/pocke/lemonade
- doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
- win32yank (Windows)
- termux (via termux-clipboard-set, termux-clipboard-set)
- tmux (if $TMUX is set)
- To maximize the current editor section use Ctrl+w then press 'o'
- To close the current editor type `:close`
- Closing it
`:q`
Closing it and ignore any changes made
`qa!`
- Deleting character under mouse:
Press x button
- Inserting character : i button
- Appending character : A button
As it is capital A so make sure to 'shift+a' or 'Capslock then a'.
- Saving file
:w : saving file
:wq : saving and closing

View file

@ -0,0 +1,84 @@
Basics2
- To delete a word type `dw`
- deleting from left to right(end of line) type `d$`
- Many commands that change text are made from an [operator](/tmp/.mount_JoplinZ52JzN/resources/app.asar/operator "operator") and a [motion](/tmp/.mount_JoplinZ52JzN/resources/app.asar/navigation "navigation").
The format for a delete command with the [d](/tmp/.mount_JoplinZ52JzN/resources/app.asar/d "d") delete operator is as follows:
d motion
Where:
d - is the delete operator.
motion - is what the operator will operate on (listed below).
A short list of motions:
```text
w - until the start of the next word, EXCLUDING its first character.
e - to the end of the current word, INCLUDING the last character.
$ - to the end of the line, INCLUDING the last character.
```
- Number itself can be used to move cursor
`2w` can be used to move cursor 2 words forward and at start of the 2nd word next to it
`2e` like 2w but instead of first character it moves to last character of the word
`0` works like home button ie to move to beginning of line
Eg:
Before using `2w` cursor is on
==L==orem ipsum try it
After using it
Lorem ipsum ==t==ry it
&nbsp;
Before using `2e` cursor is on
==L==orem ipsum try it
After using it
Lorem ipsum tr==y== it
- Now using `operator number motion` syntax
`d2w` : will delete 2 words ie current word and next word
with syntax `number operator motion`
`dd`: will delete the whole current line
`2dd` : will delete 2 lines ie current and next one
- Undo command
Loprem ipsum try it
Some changes like
Loorem ipsum try it
`u` : to undo previous change
Loprem ipsum try it
Some more changes like
Looooorem ipsi bipsy try it
So many changes r there
`U` : to undo all changes for current line and bring back to its original state
Loprem ipsum try it
Redo : `<C-r>` Ctrl+R
&nbsp;
- Put command
For example if u delete a line using `dd` than that line will be stored in neovim register
then we can put the line below the cursor using `p`
Before using dd for a
a. 1st line
b. 2nd line
After using it
b. 2nd line
then on moving cursor to line b and using `p`
b. 2nd line
a. 1st line
Note: `p` is used to put down/next to but `P` is used to put it up/before to it
- Replace command
`r` will used for replacing a character
Eg : Lor==a==m
Now pressing `r` then `e`
=> Lor==e==m
- Change
Like using insert or i but with a variation ie before going to insert word it will delete the corrent word. , type `ce`
Its a combination `de` and `i`
c is like d actually with diffrence that it will put into insert mode after deletion
so `c2w` is `d2w`+`i`.

View file

@ -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`.

View file

@ -0,0 +1,125 @@
Configuring c++ on neovim
https://www.youtube.com/watch?v=lsFoZIg-oDs
- Installing clangd(LSP)
In ensure_installed section then type `:MasonInstallAll`.
In lspconfig.lua add this
```lua
lspconfig.clangd.setup{
on_attach=on_attach,
capabilities=capabilities,
init_options={
preferences={
disableSuggestions=true,
}
}
}
```
Add instead this in `lspconfig.lua` to remove warning
```lua
local cmp_nvim_lsp = require "cmp_nvim_lsp"
require("lspconfig").clangd.setup {
on_attach = on_attach,
capabilities = cmp_nvim_lsp.default_capabilities(),
cmd = {
"clangd",
"--offset-encoding=utf-16",
},
}
```
- Autoformatter
Install clang-format. Add following in `plugins.lua`
```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 type this
```lua
local null_ls= require("null-ls")
local opts={
sources={
null_ls.builtins.formatting.clang_format,
}
}
return opts
```
Press space and type `fm` to format it
To have a custom file formatting we need to have `.clang-format` in out project folder. Generate using this
`~/.local/share/nvim/mason/bin/clang-format --style GNU --dump-config > .clang-format`
- Setup autoformat on save
In `null-ls.lua` file
modify it like this
```lua
local augroup=vim.api.nvim_create_augroup("LspFormatting",{})
local null_ls= require("null-ls")
local opts={
sources={
null_ls.builtins.formatting.clang_format,
},
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,
})
end
end,
}
return opts
```
- Debugger
With mason, install `codelldb` plugin too.
To able to debug them use `--debug` flag after gcc command when compiling like this
`gcc --debug main.cpp -o main`
And when running debugger mention name of executable file ie `main` here
In `plugins.lua` add this
```lua
{
"mfussenegger/nvim-dap",
config=function (_, _)
require("core.utils").load_mappings("dap")
end
},
-- Also add this
{
"jay-babu/mason-nvim-dap.nvim",
event="VeryLazy",
dependencies={
"williamboman/mason.nvim",
"mfussenegger/nvim-dap",
},
opts={
handlers={}
},
},
-- Add nvim-dap-ui too from javascript debugger too
```
Also changes in `chadrc.lua` and add `mappings.lua` like with js debugger too

View file

@ -0,0 +1,39 @@
Configuring neovim
https://www.youtube.com/watch?v=stqUbv-5u2s
https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua
- Copy init.lua from the github link to `~/.config/nvim/init.lua`
- Next time when nvim is started all plugins definied in this will be loaded
- Press space then type `sf` to switch through files
- Type `:Telescope keymaps` to get some new keymaps feature
- Type `:Mason` to install language servers for autocompletions
Plugins
- Install vim plug
```
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
```
- Configure vim-plug
To install plugins like coc.nvim
type following in `init.vim` or `vimrc.vim`
```text
call plug#begin()
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
```
As init.lua is already there so init.vim cant be there so change its name to `vimrc.vim` and include it in `init.lua` like this
```lua
local vimrc = vim.fn.stdpath("config") .. "/vimrc.vim"
vim.cmd.source(vimrc)
```
- PlugInstall
Then in neovim type `:PlugInstall` to install plugin listed in `vimrc.vim` file.
and remaining extensions like this
`:CocInstall coc-json coc-tsserver`

View file

@ -0,0 +1,9 @@
Extras
- Multi cursor typing in neovim
https://stackoverflow.com/questions/12399572/vim-how-to-insert-in-visual-block-mode
Try this
After selecting a block of text, press Shift+i or capital I.
Lowercase i will not work.
Then type the things you want and finally to apply it to all lines, press Esc twice.