### Setup nvim-projectconfig with Lua Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md Basic setup for nvim-projectconfig using Lua in your Neovim configuration. ```lua require('nvim-projectconfig').setup() ``` -------------------------------- ### Get Project Config Path by Extension Source: https://context7.com/windwp/nvim-projectconfig/llms.txt The `get_config_by_ext()` function retrieves the full path to the project configuration file based on the specified file extension (e.g., 'lua' or 'vim'). This is useful for scripting purposes or for checking the existence of a configuration file before attempting to load it. ```lua -- Get the path to the Lua config for current project local lua_config = require('nvim-projectconfig').get_config_by_ext('lua') -- Returns: ~/.config/nvim/projects/myproject.lua -- Get the path to the Vim config local vim_config = require('nvim-projectconfig').get_config_by_ext('vim') -- Returns: ~/.config/nvim/projects/myproject.vim -- Check if a config file exists local config_path = require('nvim-projectconfig').get_config_by_ext('lua') if vim.fn.filereadable(config_path) == 1 then print('Project config exists at: ' .. config_path) end ``` -------------------------------- ### Install nvim-projectconfig with vim-plug Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md This snippet shows how to install the nvim-projectconfig plugin using the vim-plug package manager. ```vim Plug 'windwp/nvim-projectconfig' ``` -------------------------------- ### Configure Specific Project Paths and Loaders Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md This Lua snippet shows how to define specific project configurations, including custom paths and loading functions, for handling projects with the same name or custom loading logic. ```lua require('nvim-projectconfig').setup({ project_dir = "~/.config/projects-config/", project_config={ { -- full path of your project or a lua regex string path = "projectconfig", -- use a function or a path to config file config = function () print("abcde") end }, }, silent = false -- display message after load config file }) ``` -------------------------------- ### Initialize nvim-projectconfig Plugin Source: https://context7.com/windwp/nvim-projectconfig/llms.txt Initializes the nvim-projectconfig plugin with optional configuration parameters. It sets the project directory, controls notification visibility, enables or disables auto-reloading on directory changes, and allows for custom project configurations to handle specific matching rules or provide custom config logic. ```lua -- Basic setup with defaults require('nvim-projectconfig').setup() -- Advanced setup with all options require('nvim-projectconfig').setup({ -- Directory where project configs are stored (default: ~/.config/nvim/projects/) project_dir = "~/.config/nvim/projects/", -- Whether to show notification after loading config (default: true = silent) silent = false, -- Auto-reload config when directory changes (default: true) autocmd = true, -- Custom project configs for handling name conflicts or special cases project_config = { { -- Match by exact path or Lua pattern path = "/home/user/work/awesome-project", -- Config can be a file path config = "~/.config/nvim/projects/work-awesome.lua" }, { -- Use Lua regex pattern for flexible matching path = "frontend%-app", -- Or config can be a function config = function() vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.g.my_project_type = "frontend" end }, }, }) ``` -------------------------------- ### Customize Project Configuration Directory Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md This Lua snippet demonstrates how to change the default directory where project configurations are stored. ```lua require('nvim-projectconfig').setup({ project_dir = "~/.config/projects-config/" }) ``` -------------------------------- ### Open Project Configuration File Source: https://context7.com/windwp/nvim-projectconfig/llms.txt The :EditProjectConfig command opens the project configuration file for the current directory. It prioritizes `.vim` configuration files if they exist, otherwise, it opens or creates the `.lua` configuration file. This command can be mapped to a keybinding for convenient access. ```lua -- In Neovim command mode, open the project config for current directory -- :EditProjectConfig -- You can also map it to a keybinding in your init.lua vim.keymap.set('n', 'pc', 'EditProjectConfig', { desc = 'Edit project config' }) -- Example: If you're in /home/user/projects/myapp/ -- This will open ~/.config/nvim/projects/myapp.lua for editing ``` -------------------------------- ### Enable Autocommand for Project Config Loading Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md This Lua snippet enables an autocommand that automatically loads project configurations when changing directories within Neovim. ```lua require('nvim-projectconfig').setup({autocmd=true}) ``` -------------------------------- ### Manually Load Project Configuration Source: https://context7.com/windwp/nvim-projectconfig/llms.txt The `load_project_config()` function allows for manual reloading of the project configuration for the current directory. It can also accept an options table to override default settings, such as disabling silent mode to show notifications during the reload process. ```lua -- Manually reload the current project's config require('nvim-projectconfig').load_project_config() -- Reload with temporary option overrides require('nvim-projectconfig').load_project_config({ silent = false -- Show notification this time }) ``` -------------------------------- ### Load Project-Specific JSON Data Source: https://context7.com/windwp/nvim-projectconfig/llms.txt The `load_json()` function reads and parses a JSON configuration file associated with the current project. It returns a Lua table containing the parsed data if the file exists and is valid JSON; otherwise, it returns `nil`. This allows for easy access to project-specific settings stored in JSON format. ```lua -- Load project-specific JSON data local project_data = require('nvim-projectconfig').load_json() if project_data then -- Access your stored project settings print('Last opened file: ' .. (project_data.last_file or 'none')) print('Project type: ' .. (project_data.type or 'unknown')) -- Use settings in your workflow if project_data.run_command then vim.keymap.set('n', 'r', function() vim.cmd('!' .. project_data.run_command) end, { desc = 'Run project command' }) end else print('No JSON config found for this project') end ``` -------------------------------- ### Load and Save JSON Data Source: https://github.com/windwp/nvim-projectconfig/blob/master/README.md These Lua snippets provide functions to load and save JSON data using the nvim-projectconfig plugin. ```lua require('nvim-projectconfig').load_json() ``` ```lua require('nvim-projectconfig').save_json(data) ``` -------------------------------- ### Save Project Configuration to JSON (Lua) Source: https://context7.com/windwp/nvim-projectconfig/llms.txt The save_json() function persists a Lua table as JSON to the project's configuration file. This function is useful for storing project-specific state or settings that need to persist across Neovim sessions. It takes a Lua table as input and saves it to a JSON file. ```lua local pc = require('nvim-projectconfig') -- Save project-specific data pc.save_json({ last_file = vim.fn.expand('%:p'), cursor_position = vim.api.nvim_win_get_cursor(0), type = 'nodejs', run_command = 'npm run dev', test_command = 'npm test', custom_settings = { use_prettier = true, eslint_fix_on_save = true } }) -- Example: Auto-save last position on exit vim.api.nvim_create_autocmd('VimLeavePre', { callback = function() local data = pc.load_json() or {} data.last_file = vim.fn.expand('%:p') data.last_position = vim.api.nvim_win_get_cursor(0) pc.save_json(data) end }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.