- Consider looking at DotFiles from folke: github
- Advent of Neovim
- Autocomplete
C-xC-l - To validate auto complete:
<C-n>Next<C-p>previous<C-y>validate/ok
- Use
NVIM_APPNAME=nvimexample(will use a new fresh config, will need to check~/.config/nvimexample - Execute
lua:- on selected lines: Select and then do
:lua - on current line:
:.lua
- on selected lines: Select and then do
- Check the
vim.<other>functions::lua =vim- for
vim.fnthose are defaultvimfunctions that can be called directly, e.g.,vim.fn.stdpath('data')we can use:echo stdpath('data')
- for
autocmd
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})- Executing a command line
let out = vim.fn.system({ "git", "clone", ...})(Check thelazy.nvimrepo) Runtime Paths::echo nvim_list_runtime_paths()- For file type settings. use
./after/ftplugin/<language>.lua optionsare located invim.opt(echo =vim.opt)TreeSitter- Installed by default in
neovim nvim-treesitterplugin is there to have language specific queries:Inspectto list all highlights under cursor:InspectTreeto list all highlights under cursor- We can update the color for a given "node":
vim.cmd [[hi @function.builtin.lua guifd=yellow]]
- Installed by default in
- Formatting youtube
- Use
:lua vim.lsp.buf.format()to manually call the format vim.lsp.formatexpr()TODO: Read the doc
- Use
- Setup short cut to look at lzy packages
vim.keymap.set("n", "<leader>sp", function()
builtin.find_files({ cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy") })
end, { desc = "[S]earch Lazy [P]ackages Files " })-
In
Telescopepicker<C-q>will create a quick-fix -
Windows/Buffer/Tabs navigation
- Tab:
<C-w><C-t>create a new tab -<C-w>Tmove current window to a new tab -gtto next tab,gTto previous tab
- Tab:
-
In
terminalmode:- Go to Normal mode:
<C-/><C-n>
- Go to Normal mode:
-
Quickfix (global to project) vs Location (only for current window)
- To see the error/diagnostics
vim.diagnotics.set :cnextor:cprevfor quickfix<C-j>or<C-k>:lnextor:lprevfor location<M-j>or<M-k>
- To see the error/diagnostics
-
<Esc><Esc>to Normal mode (as<C-\><C-n>is overloaded by windows 11) -
create a small terminal and send command to it
-- avoid line numbers in terminal
vim.api.nvim_create_autocmd("TermOpen", {
group = vim.api.nvim_create_augroup("custom-term-open", { clear = true }),
callback = function()
vim.opt.number = false
vim.opt.relativenumber = false
end,
})
-- create a small terminal window at bottom and allow getting commands without being in the terminal
local channel_id = 0
vim.keymap.set("n", "<space>st", function()
vim.cmd.vnew()
vim.cmd.term()
-- put at bottom
vim.cmd.wincmd("J")
vim.api.nvim_win_set_height(0, 15)
channel_id = vim.bo.channel
end)
vim.keymap.set("n", "<space>example", function()
vim.fn.chansend(channel_id, "git status\r\n")
end)2023-03-31 thePrimeagen
2022-12-17 tj_devries
- kickstart.lua
- Default keymaps
|
<leader>sf| Telescope find file | |<leader>sn| Telescope find file in~/.config/nvim| We have updated to use include 2024-12-08- (without stow) in
~/.config/nvim - with stow move to
/mnt/d/Repos/DotFiles/run:stow -Stv ~ nvimForWindowscopy nvim directoryD:\Repos\DotFiles\nvim\.config\nvimtoc:\Users\<user>\AppData\Local\
- (without stow) in
- Update the type of pickers use
pickers
- Using
plenary - Do not expose with
M._<function> - Create a
testsdirectory - Create files with
_specat end of basename, e.g.,parse_slides_spec.lua
local parse = require("present")._parse_slides
describe("present.parse_slides", function()
it("should parse an empty file", function()
assert.are_same({}, parse({}))
end)
end)- Run
:PlenaryBustedFile %to run file - For Continuous Integration. create a
Makefilein<root>directory (check telescope.nvim)
.PHONY test lint docgen
test:
nvim --headless --noplugin -u tests -c "PlenaryBustedDirectory"- In a file in
plugindirectory that will be automatically loaded, in the<name>.nvimdirectory add a commandvim.api.nvim_create_user_command()
:cd %:p:h:tcd %:p:hfor current tab directory:wcd %:p:hfor current window directory
- Run Time Path
:help rtp- Check also
stdpath("config")
- Check also
- Setting up the current directory as plugin repo
nvim --cmd "set +rtp=. - Create
luamodule in source directorymkdir -p lua/<plugin_name>and files a.touch lua/<plugin_name>/init.luab.touch lua/<plugin_name>/<module_name>.lua - Create function in
<module_name>.luafile
local function greet()
print('hello')
end
return greet- Import module into plugin in
init.lu
local greet = require('<module_name>.<module-name>')
return {
greet = greet
}- Test in load in nvim
:lua require('<plugin_name').greet()
6. Check to debug
Rem: Lua does not reload an already existing module.
You need to delete it and reload an edited version
a. Create a dev/init.lua
--- force lua to import the module again
l package.loaded['dev'] = nil
pacakge.loaded['<plugin-name>'] = nil
pacakge.loaded['<plugin-name>.<module_name>'] = nil
--- can call :luafile dev/init.lua or create a short cut
vim.api.nvim_set_keymap('n', ',r', '<cmd>luafile dev/init.lua<cr>', {})
-- also test
Testing = require('plugin_name')
vim.api.nvim-set_keymap('n', ',w', '<cmd>lua Testing.greet()<cr>', {})- Installing with the plugin manager
- In
~Repos/neovim-lua-config - Create
.config/lua-config
local last_highlighted = ""
function SetFromHighlight()
local _, s_row, _, _ = unpack(vim.fn.getpos("'<"))
local _, e_row, _, _ = unpack(vim.fn.getpos("'>"))
last_highlighted = table.concat(
vim.api.nvim_buf_get_lines(0, s_row - 1, e_row, false), "\n"
)
end
## Using treesitter
- Check [nvim-Femaco](https://github.com/AckslD/nvim-FeMaco.lua/blob/main/lua/femaco/edit.lua)