diff --git a/docs/books/nvchad/.pages b/docs/books/nvchad/.pages new file mode 100644 index 0000000000..7f3351f127 --- /dev/null +++ b/docs/books/nvchad/.pages @@ -0,0 +1,9 @@ +--- +nav: + - ... | index*.md + - ... | additional_software*.md + - ... | install_nvim*.md + - ... | install_nvchad*.md + - ... | nerd_fonts*.md + - NvChad UI: nvchad_ui + - Customisation: custom diff --git a/docs/books/nvchad/additional_software.md b/docs/books/nvchad/additional_software.md new file mode 100644 index 0000000000..ba3104d0fc --- /dev/null +++ b/docs/books/nvchad/additional_software.md @@ -0,0 +1,67 @@ +--- +title: Additional Software +author: Franco Colussi +contributors: Steven Spencer +tested with: 9.0 +tags: + - nvchad + - coding +--- + +# Additional Software Needed + +There are several pieces of additional software that, while not required, will aid in the overall use of NvChad. The sections below will walk you through that software and its uses. + +## RipGrep + +`ripgrep` is a line-oriented search tool that recursively searches the current directory for a _regex_ (regular expression) pattern. By default, _ripgrep_ respects the rules of _gitignore_ and automatically skips hidden files/directories and binaries. Ripgrep offers excellent support on Windows, macOS and Linux, with binaries available for each release. + +Ripgrep is software written in _Rust_ and is installable with the `cargo` utility. Note, however, that `cargo` is not installed by the default installation of _rust_ so you have to install it explicitly. + +```bash +dnf install rust cargo +``` + +Once the necessary software is installed, we can install `ripgrep` with: + +```bash +cargo install ripgrep +``` + +The installation will save the `rg` executable in the `~/.cargo/bin` folder which is outside the PATH, to use it at the user level we will link it to `~/.local/bin/`. + +```bash +ln -s ~/.cargo/bin/rg ~/.local/bin/ +``` + +At this point we can check that everything is okay with: + +```bash +rg --version +ripgrep 13.0.0 +-SIMD -AVX (compiled) ++SIMD +AVX (runtime) +``` + +RipGrep is needed for recursive searches with `:Telescope`. + +## Lazygit + +[LazyGit](https://github.com/jesseduffield/lazygit) is an ncurses-style interface that allows you to perform all `git` operations in a more user-friendly way, it is required by the _lazygit.nvim_ plugin, this plugin makes it possible to use LazyGit directly from NvChad, it opens a floating window from where you can perform all operations on your repositories, thus allowing you to make all changes to the _git repository_ without leaving the editor. + +To install it we can use the repository for Fedora. On Rocky Linux 9 it works perfectly. + +```bash +sudo dnf copr enable atim/lazygit -y +sudo dnf install lazygit +``` + +Once installed we open a terminal and type the command `lazygit` and an interface similar to this will appear: + +![LazyGit UI](images/lazygit_ui.png) + +with the x key we can bring up the menu with all available commands. + +![LazyGit UI](images/lazygit_menu.png) + +Now that we have all the necessary supporting software on our system we can move on to installing the basic software, the editor on which all the configuration is based, [Neovim](install_nvim.md). diff --git a/docs/books/nvchad/custom/.pages b/docs/books/nvchad/custom/.pages new file mode 100644 index 0000000000..b97ab2d66b --- /dev/null +++ b/docs/books/nvchad/custom/.pages @@ -0,0 +1,9 @@ +--- +nav: + - ... | custom_folder*.md + - ... | chadrc_lua*.md + - ... | init_lua*.md + - ... | mappings_lua*.md + - ... | override_lua*.md + - Plugins: plugins + - ... | lsp*.md diff --git a/docs/books/nvchad/custom/chadrc_lua.md b/docs/books/nvchad/custom/chadrc_lua.md new file mode 100644 index 0000000000..04d3233d78 --- /dev/null +++ b/docs/books/nvchad/custom/chadrc_lua.md @@ -0,0 +1,52 @@ +--- +title: WIP - chadrc.lua +tags: + - nvhad + - coding + - editor +--- + +# chadrc.lua + +The chadrc.lua file in our `custom` folder contains information about where NvChad should look for additional configurations and personal plugins. + +Special attention must be paid to the file hierarchy as there may be multiple files with the same name (see *init.lua*) but in different locations, the location is what determines the order in which the files are included in the configuration. Respectively `core` -> `custom` -> `plugins`. + +The contents of the `chadrc.lua` file are as follows: + +```lua +local M = {} +local override = require("custom.override") + +M.ui = { + theme = "everforest", + theme_toggle = { "everforest", "everforest_light" }, +} + +M.mappings = require("custom.mappings") + +M.plugins = { + user = require("custom.plugins"), + override = { + ["kyazdani42/nvim-tree.lua"] = override.nvimtree, + ["nvim-treesitter/nvim-treesitter"] = override.treesitter, + ["lukas-reineke/indent-blankline.nvim"] = override.blankline, + }, +} + +return M +``` + +The first call you encounter refers to the inclusion of our *custom/override.lua* file containing the custom settings for the plugins in the *override* table defined in `M.plugins`, in particular the customizations refer to the state of the files with respect to a Git *repository* (if you are working with one), the automatic installation of *treesitter parsers* and the exclusion of the reference lines of nested routines and commands, this functionality in writing documentation in Markdown is not that important, in case you want to have this functionality as well just remove the line: + +```lua +["lukas-reineke/indent-blankline.nvim"] = override.blankline, +``` + +And perform a `:PackerSync`. + +Then follows the configuration of the default theme with its clear variant and next the `require` call of the *custom/mapping.lua* file that contains the custom commands. + +We then find settings that call up personal configuration files (contained in *custom/plugins*) that will replace the default settings. + +So we can say that the *chadrc.lua* file is the file that takes care of some aspects of the UI and more importantly to include our files in the NvChad configuration. diff --git a/docs/books/nvchad/custom/custom_folder.md b/docs/books/nvchad/custom/custom_folder.md new file mode 100644 index 0000000000..101f35d1f3 --- /dev/null +++ b/docs/books/nvchad/custom/custom_folder.md @@ -0,0 +1,98 @@ +--- +title: WIP -Custom Folder +tags: + - nvchad + - coding +--- + +# Advanced configuration of the Custom Folder + +## Introduction + +NvChad uses the version manager `git` for updates, this implies that at every update part or the whole configuration is overwritten by new commits, consequently it would be useless to make customizations within the default configuration. To solve this problem the NvChad developers have set up the possibility to make your changes in a folder called `custom` which must be mandatorily placed in `.config/nvim/lua/`. Below we have a representation of the basic structure of a standard NvChad installation + +```text +nvim/ +├── examples +│   ├── chadrc.lua +│   └── init.lua +├── init.lua +├── LICENSE +├── lua +│   ├── core +│   └── plugins +└── plugin + └── packer_compiled.lua +``` + +### Structure Creation + +To start the customization we have to create for first the `custom` folder that will contain all our files, let's take the opportunity to also create the `plugins` folder that will contain the _configuration files_ of our plugins, since surely the folders will not be present we will use the `-p` flag to tell the _mkdir_ command to create the missing folders, the command will be as follows: + +```bash +mkdir -p ~/.config/nvim/lua/custom/plugins +``` + +The structure of the `nvim/lua` folder should now look like this: + +```text +├── lua +│   ├── core +│   ├── custom +│   │   └── plugins +│   └── plugins +``` + +The choice of path is not accidental but responds to the need to preserve this folder from updates, otherwise with each update the folder would simply be deleted as it is not part of the repository. The NvChad developers have prepared a `.gitignore` file for this, which determines its exclusion. + +```bash +cat .config/nvim/.gitignore +plugin +custom +spell +``` + +### Structure of the Custom Folder + +The structure of the _custom_ folder used for this guide is as follows: + +```text +custom/ +├── chadrc.lua +├── init.lua +├── mappings.lua +├── override.lua +└── plugins + ├── init.lua + └── lspconfig.lua +``` + +We are going to analyze its contents and briefly describe the files it contains; the files will be analyzed in detail later on the pages dedicated to them. + +- `chadrc.lua`: this file allows the override of default configurations. It also allows plugins to be overridden so that they can then be associated with _override.lua_ configurations. For example, it is used to save the interface theme with: + +```lua +M.ui = { + theme = "everforest", +} +``` + +- `init.lua`: this file is executed after the main `init.lua` file contained in `nvim/lua/core/` and allows the execution of personalized commands at NvChad startup. + +- `mappings.lua`: allows the setting of custom commands, these commands are normally used to abbreviate standard commands. An example is the abbreviation of the command `:Telescope find_files` which with this setting in _mapping.lua_: + +```lua +["\\\\"] = { " Telescope find_files", "file finder" }, +``` + +Allows you to retrieve **:Telescope find_files** by typing two `\\` + +![Telescope Find Files](../images/telescope_find_files.png) + + +- `override.lua`: this file contains the custom configurations that replace the default ones, this is possible thanks to the override effected upstream in _chadrc.lua_. + +Let us now move on to the `plugins` folder, the folder contains all the configuration files of the various plugins installed and most importantly the `init.lua` file. In the `init.lua` file should be inserted the plugins we want to install on our IDE. Once inserted and configured, if necessary, they will be installable via the `:PackerSync` command. + +The only plugin required is _neovim/nvim-lspconfig_, which enables LSP (language server) functionality for advanced editing. + diff --git a/docs/books/nvchad/custom/init_lua.md b/docs/books/nvchad/custom/init_lua.md new file mode 100644 index 0000000000..f1fdfbb800 --- /dev/null +++ b/docs/books/nvchad/custom/init_lua.md @@ -0,0 +1,34 @@ +--- +title: WIP - init.lua +tags: + - nvchad + - coding + - editor +--- + +# init.lua + +The *nvim/lua/custom/init.lua* file is used for overwriting the default NvChad options defined in *lua/core/options.lua* and setting its own options. It is also used for the execution of Auto-Commands. + +Writing documents in Makdown does not require much modification; we are going to set some behaviors such as the number of spaces for tabbing, a setting that makes formatting Markdown files very smooth. + +Our file will look like this: + +```lua +vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync()]] +-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead + +local opt = vim.opt + +opt.tabstop = 4 +opt.softtabstop = 4 +opt.shiftwidth = 4 +opt.shiftround = false +opt.expandtab = true +opt.autoindent = true +opt.smartindent = true +``` + +In our example we used an auto-command for synchronous buffer formatting and formatting options. + +To summarize, the *init.lua* file is used for overwriting the default settings, this is because being read after the *core/init.lua* file replaces all previous options with the new ones we set. diff --git a/docs/books/nvchad/custom/lsp.md b/docs/books/nvchad/custom/lsp.md new file mode 100644 index 0000000000..f159b2d3ff --- /dev/null +++ b/docs/books/nvchad/custom/lsp.md @@ -0,0 +1,196 @@ +--- +title: Language Server Protocol +author: Franco Colussi +contributors: Steven Spencer +tested with: 9.0 +tags: + - NvChad + - coding + - LSP +--- + +## LSP + +What is the Language Server Protocol? + +It is a server service that provides support for advanced editing functions, such as automatic source code completion or *"Go to Definition"*, for a programming language in an editor or IDE. + +The Language Server Protocol (LSP) is the product of standardizing the messages exchanged between a development tool and a language server process. The goal of LSP is to simplify this type of integration, and to provide a useful framework for exposing language features to a variety of tools. + +### LSP in NvChad + +NvChad provides an automatic mechanism for installing language servers through the `williamboman/mason.nvim` plugin; a little gem of the Neovim plugin ecosystem that provides a graphical interface for installing language servers and more. + +![Mason UI](../images/mason_ui.png) + +To learn about all available commands, simply press the g? key to have the full legend available. + +![Mason Help](../images/mason_help.png) + +### Introduction to *nvim-lspconfig* + +*nvim-lspconfig* is a collection of configurations, provided by the community, for the language client server built into the Nvim core. This plugin provides four main features: + +- default startup commands, initialization options, and settings for each server. +- a root directory solver that attempts to locate the root of the project +- an automatic command mapping that launches either a new language server, or a language server for each open buffer if it is part of a traced project. +- utility commands such as LspInfo, LspStart, LspStop, and LspRestart, for managing language server instances. + +The combined use of the two plugins allows the required language servers to be downloaded and automatically configured by NvChad. + +#### Downloading Language Servers + +To download the language server of choice, we open the interface of *Mason* from our editor with the command `:Mason`. Suppose we want to install the language server for *Markdown*. To do so, we type 2 to take us to the `LSP` section. Now we go down with the arrow key until we find the language server `marksman`. By pressing the space bar we can get some information about the server as you can see in the screenshot below. + +![Mason Marksman](../images/mason_marksman.png) + +To install the server, simply press the i key, and after Mason completes the installation we will find it among the installed servers. + +![Marksman Installed](../images/mason_installed.png) + +The servers to be installed by this procedure are: + +- **marksman**: for markdown support +- **yaml-language-server**: for frontmatter support +- **lua-language-server**: for lua support +- **html-lsp**: for HTML support + +### Configure `lspdconfig.lua` + +Installed servers are not yet configured in NvChad. To perform server registration we need to perform additional configuration. + +First we create the `custom/plugins` folder in `~/.local/nvim/lua`: + +```bash +mkdir -p ~/.local/nvim/lua/custom/plugins +``` + +We used the `-p` flag since the _custom_ folder was definitely not present. Once the folder is created, we need to create two files: `init.lua`, which will take care of instructing *Packer* to install the plugin, and `lspconfig.lua`, which will define our servers. + +Let's start by creating the two files first: + +```bash +touch ~/.config/nvim/lua/custom/plugins/init.lua +touch ~/.config/nvim/lua/custom/plugins/lspconfig.lua +``` + +The folder structure at this point should look as follows: + +```text +└── plugins + ├── init.lua + └── lspconfig.lua +``` + +We now move on to edit the two files to include support for *Language Servers*. + +#### init.lua + +Inserting the following code tells Packer to install the `neovim/nvim-lspconfig` plugin using the code contained in *nvim/lua/plugins/lspconfig.lua* and *nvim/lua/custom/plugins/lspconfig.lua* respectively. For configuration, through, we need `require` calls. Special attention should be paid to the sequence of the calls as they use the override technique, and reversing the order could result in inconsistencies in the configuration. + +```lua +return { + ["neovim/nvim-lspconfig"] = { + config = function() + require "plugins.configs.lspconfig" + require "custom.plugins.lspconfig" + end, + }, +} +``` + +We then go on to edit our file with NvChad: + +```text +nvim ~/.config/nvim/lua/custom/plugins/init.lua +``` + +![NvChad init.lua](../images/init_custom_plugins.png) + +Once the changes are finished, we save the file with the command `:wq`. + +We can now edit the configuration file of our local servers. + +#### lspconfig.lua + +This is our `lspconfig.lua` configuration file, and it is inserted after the NvChad *lspconfig* configuration has finished setting up the environment. + +```lua +-- custom.plugins.lspconfig +local on_attach = require("plugins.configs.lspconfig").on_attach +local capabilities = require("plugins.configs.lspconfig").capabilities + +local lspconfig = require "lspconfig" +local servers = { "html", "marksman", "yamlls"} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end +``` + +Let's open our editor again and edit the file: + +```textile +nvim ~/.config/nvim/lua/custom/plugins/lspconfig.lua +``` + +![Custom lspconfig.lua](../images/lspconfig_custom.png) + +After finishing the changes we save and close the editor as before with `:wq` + +As we can see, we have added in the table of `local servers` the servers we have installed with *Mason*: + +```lua +local servers = { "html", "marksman", "yamlls"} +``` + +This gives *nvim-lspconfig* a way to retrieve the configurations needed for their operation in the IDE. + +Once we have finished the changes, to make them effective we need to tell *Packer* to synchronize them. This is done with a simple `:PackerSync` at the end of which the new installation of *neovim/nvim-lspconfig* will be highlighted in the log. Now opening a Markdown file should bring up a gear icon in the lower right corner and say `LSP - marksman`. + +![Marksman Enable](../images/marksman_enable.png) + +![Marksman Server](../images/marksman_server_info.png) + +### Introduction to Used LSP + +#### SumnekoLua + +A very important component is the `lua-language-server`, which completely changes the experience of writing Lua code, and consequently also the editing of NvChad configuration files that are written in this language. This is also the default LSP for *lua* + +The executable is provided by the [SumnekoLua](https://github.com/sumneko/lua-language-server). + +![Lua Language Server](../images/lua-language-server.png) + +It should be noted that the lua server does not need to be configured in the `lspconfig.lua` configuration file. Since it is the default server for NvChad, this works without the need of any additional configuration. + +![Lua Diagnostic](../images/lua_diagnostic.png) + +#### Marksman + +Marksman is a language server for Markdown that provides auto-completion, go-to definitions, reference searching, diagnostics, etc. All types of links support completion, hover, and goto/reference definition. In addition, Marksman provides diagnostics for wiki links to detect broken references and duplicate/ambiguous titles. + +![Marksman Server](../images/marksman_assistant.png) + +And if we try to create some errors, (in our example we will create a few blank lines that in markdown are not an error but are considered as bad formatting), we will get a visual warning (the pink squares to the left of the line number) that will alert us of the problem. + +![Marksman Diagnostic](../images/marksman_diagnostic.png) + +#### yamlls + +`yamlls` provides functions to validate the entire yaml file, check for errors and warnings regarding code, autocomplete commands, plus hovering over a node displays the description, if available. + +The language server is provided by the package [yaml-language-server](https://github.com/redhat-developer/yaml-language-server). + +![Yaml Server](../images/yamlls_server.png) + +Once installed it will spring into action whenever we open a `.yaml` file by making a valuable contribution to writing and debugging code. + +### Final Considerations + +The use of LSPs greatly aids the editing process, enriching it with advanced features. It also allows us to keep track of its consistency in real time. It is definitely a tool to have in our IDE. + +The introduction of *Mason*, although some manual intervention is still required to configure the environment, has made available an automated procedure for the installation of language servers, and more importantly, allows us to avoid the periodic checks for updates that would have been necessary in the case of manual installation. Once installed and configured, all our servers will be upgradeable from the *Mason GUI* with a simple press of the U key. diff --git a/docs/books/nvchad/custom/mappings_lua.md b/docs/books/nvchad/custom/mappings_lua.md new file mode 100644 index 0000000000..84ec3cce23 --- /dev/null +++ b/docs/books/nvchad/custom/mappings_lua.md @@ -0,0 +1,67 @@ +--- +title: WIP - mappings.lua +tags: + - nvchad + - coding + - editor +--- + +The *custom/mappings.lua* file allows us to set up custom commands, these allow to perform even non-editor tasks as well as greatly shortening the typing of full commands. + +This is probably the most "personal" file of those contained in the `custom` folder in that everyone has their own set of commands and associated utilities to which they are accustomed. We will try to lay out the subject in a general way to give you the foundation on which to build your own mapping. + +The interesting thing about mappings is that they can be inserted into the various working states of the editor (INSERT, NORMAL..) giving us a way to have even more granular customization of commands. + +The states are denoted by the letters `n`, `v`, `i`, `t`. As can be seen these are corresponding to the various NORMAL, VISUAL, etc. Let us take the following example to introduce the configuration: + +```lua +local M = {} + +M.general = { + i = { + -- navigate within insert mode + [""] = { "", "move left" }, + [""] = { "", "move right" }, + [""] = { "", "move down" }, + [""] = { "", "move up" }, + }, +} + +M.packer = { + n = { + ["ps"] = { "PackerSync", "Packer Sync" }, + ["pS"] = { "PackerStatus", "Packer Status" }, + ["pu"] = { "PackerUpdate", "Packer Update" }, + }, +} + +M.telescope = { + n = { + [""] = { " Telescope", "open telescope" }, + ["\\\\"] = { " Telescope find_files", "file finder" }, + ["\\f"] = { " Telescope live_grep", "telescope live grep" }, + }, +} + +M.git = { + n = { + ["lg"] = { "LazyGit", "open lazygit" }, + ["gc"] = { " Telescope git_commits", "git commits" }, + ["gs"] = { " Telescope git_status", "git status" }, + }, +} + +return M +``` + +In this file the `M` variable initialized in the first line passes and collects all our mappings before being returned to the configuration from the last line, so everything we set in this file will be available in the editor in the form of keyboard shortcuts. + +The first part `M.general` is an example of overriding the default settings, the new mapping replaces the default mapping for movement between rows in INSERT mode `i = {` with one that is easier to remember (and also more logical, the original shortcut Ctrl + l to move to the right is an example) + +In the second part we have the command mapping for plugin management with `:Packer` this time set for the NORMAL `n = {` state. + +And in the final part of our example we have two sets of shortcuts both for the NORMAL `n = {` state, one concerning the opening of *Telescope* for searching files and some shortcuts for controlling and managing *Git repositories*, + +As you can see this file allows you to manage the keyboard shortcuts of all NvChad/Neovim commands and also of its plugins allowing a much faster workflow. + +This example is only meant to be an introduction to a level of customization that can be very high; to consult the standard mapping you can refer to [this file](https://github.com/NvChad/NvChad/blob/main/lua/core/mappings.lua), while for plugin-specific commands you must refer to the various projects. diff --git a/docs/books/nvchad/custom/override_lua.md b/docs/books/nvchad/custom/override_lua.md new file mode 100644 index 0000000000..57566dd165 --- /dev/null +++ b/docs/books/nvchad/custom/override_lua.md @@ -0,0 +1,92 @@ +--- +title: WIP - override.lua +tags: + - nvchad + - coding + - editor +--- + +# override.lua + +The `custom/override.lua` file is used for overriding the settings of plugins defined in *chadrc.lua* allows various *parsers* to be installed at startup, extend the functionality of *nvimtree*, and other customizations. + +The file used for our example is as follows: + +```lua +local M = {} + +M.treesitter = { + ensure_installed = { + "html", + "markdown", + "yaml", + "lua", + }, +} + +M.nvimtree = { + git = { + enable = true, + }, + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, + view = { + side = "right", + }, +} + +M.blankline = { + filetype_exclude = { + "help", + "terminal", + "alpha", + "packer", + "lspinfo", + "TelescopePrompt", + "TelescopeResults", + "nvchad_cheatsheet", + "lsp-installer", + "", + }, +} + +M.mason = { + ensure_installed = { + "lua-language-server", + "marksman", + "html-lsp", + "yaml-language-server", + }, +} + +return M +``` + +Let's go through the content, the first part checks, and if missing installs the *treesitter* parsers defined in the table, in our example we added only those useful for writing documents in Markdown, for a complete list of available parsers you can refer to [this page](https://github.com/nvim-treesitter/nvim-treesitter#supported-languages). + +![NvimTree Git](../images/nvimtree_git.png){ align=right } + +The second part enriches our file explorer (*nvimtree*) with decorations for the state of the files with respect to the *Git* repository and moves the view to the right. + +We then have a part that takes care of removing the lines that indicate nesting in the code and the last one that takes care of informing *Mason* which language servers are needed in the IDE, called by the `ensure_installed` function. + +The control and eventual installation of *parser* and *LSP* is very useful in managing one's customizations on multiple workstations. By saving the *custom* folder in a Git Repository, one has the ability to clone one's customization to any machine on which NvChad is installed, and any changes can be synchronized between all the machines on which one is working. + +Summarizing the *custom/override.lua* file is used to override parts of the default plugin configuration, customizations set in this file are taken into account only if the plugin is defined in *custom/chadrc.lua* in the *plugin override* section. + +```lua +M.plugins = { + user = require("custom.plugins"), + override = { + ["kyazdani42/nvim-tree.lua"] = override.nvimtree, + ["nvim-treesitter/nvim-treesitter"] = override.treesitter, + ["lukas-reineke/indent-blankline.nvim"] = override.blankline, + ["williamboman/mason.nvim"] = override.mason, +... +``` diff --git a/docs/books/nvchad/custom/plugins/.pages b/docs/books/nvchad/custom/plugins/.pages new file mode 100644 index 0000000000..87bd4d4b3f --- /dev/null +++ b/docs/books/nvchad/custom/plugins/.pages @@ -0,0 +1,4 @@ +--- +nav: + - ... | init_lua*.md + - ... | lspconfig_lua*.md diff --git a/docs/books/nvchad/custom/plugins/init_lua.md b/docs/books/nvchad/custom/plugins/init_lua.md new file mode 100644 index 0000000000..b411b4e281 --- /dev/null +++ b/docs/books/nvchad/custom/plugins/init_lua.md @@ -0,0 +1,44 @@ +--- +title: WIP - init.lua +tags: + - nvchad + - coding + - editor +--- + +# init.lua + +The file `custom/plugins/init.lua` closes the NvChad configuration, it is the last *init.lua* that is read and inserts our additional plugins into the configuration. Its configuration consists of inserting the plugins in the format: + +```lua + ["github_username/plugin_name"] = {}, +``` + +If the plugin does not need additional configurations, the configuration described above is sufficient, but if additional configurations are needed, they will be placed inside the curly brackets. + +Let us then take our example file: + +```lua +return { + ["neovim/nvim-lspconfig"] = { + config = function() + require "plugins.configs.lspconfig" + require "custom.plugins.lspconfig" + end, + }, + ["kdheepak/lazygit.nvim"] = {}, + ['folke/which-key.nvim'] = { disable = false }, +} +``` + +In this configuration we have included only the two necessary plugins *nvim-lspconfig* and *which-key* plus one that requires no additional configuration as an example. The two plugins are necessary since without their configuration we will not have support for LSPs (language servers) even if they are installed and the functionality of *which-key* since it is disabled by default. + +As we can see, the first plugin calls the configuration function and reads first the file `nvim/lua/plugins/configs/lspconfig.lua` and then our file `nvim/lua/custom/plugins/lspconfig.lua`. In this case an additional file is used for personal configurations, the choice depends on the amount of changes to be made. + +The second is an example of a plugin that needs no additional configuration allows once installed to access Git repository management directly from the editor with the command `:LazyGit`. For the installation of LazyGit you can refer to the [Additional Software](../../additional_software.md) page. + +The third is an example of putting configurations to be overwritten directly into the file, in this case the only change is the reactivation of the default disabled plugin. This plugin is enclosed by two single quotes that can replace double quotes; the two notations are equivalent. + +Once you have finished configuring the file and related configuration files, to activate the new plugins, it is recommended that you exit the editor, re-enter and perform a `:PackerSync` + +In short we can say that this file is the engine of all our personal plugins, this is where most of the additional functionality of our IDE are configured. diff --git a/docs/books/nvchad/custom/plugins/lspconfig_lua.md b/docs/books/nvchad/custom/plugins/lspconfig_lua.md new file mode 100644 index 0000000000..b84e838a65 --- /dev/null +++ b/docs/books/nvchad/custom/plugins/lspconfig_lua.md @@ -0,0 +1,44 @@ +--- +title: WIP - lspconfig.lua +tags: + - nvchad + - coding + - editor +--- + +# lspconfig.lua + +This configuration file assigns the functionality defined in `nvim/lua/plugins/configs/lspconfig.lua` to the language servers we have installed with `Mason`, the language servers should be placed in the local servers according to this format: + +```lua +local servers = { "html", "marksman", "yamlls"} +``` + +As pointed out earlier, there is no need to make explicit support for Lua as it is enabled by default by NvChad; however, the *lua-language-server* must be installed with *Mason* to be available in the IDE. + +Let us then look at our *lspconfig.lua* file: + +```lua +local on_attach = require("plugins.configs.lspconfig").on_attach +local capabilities = require("plugins.configs.lspconfig").capabilities + +local lspconfig = require "lspconfig" +local servers = { "html", "marksman", "yamlls"} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end +``` + +The first two instructions import the `on_attach` and `capabilities` features from NvChad's *lspconfig.lua* file, then follows the configuration of the language servers to which to provide the features, and finally the routine that associates the features with the LSPs set up. + +At the first configuration it is advisable to exit and re-enter the editor before running `:PackerSync`, subsequent language server entries to the configuration can be registered with `:LspRestart` without the need to reload the configuration. The next time a supported file is opened it will bring up an icon at the bottom with associated LSP and language server used, this gives us confirmation that the LSP is running properly. + +Summarizing the *lspconfig.lua* file configures the functionality of the servers we install, it is a file that after the first configuration will not need much editing as long as we write documentation in Markdown. For more information on the **L**anguage **S**erver **P**rotocol you can consult the [dedicated page](../lsp.md). + + + + diff --git a/docs/books/nvchad/images/e_tab_command.png b/docs/books/nvchad/images/e_tab_command.png new file mode 100644 index 0000000000..2d52978115 Binary files /dev/null and b/docs/books/nvchad/images/e_tab_command.png differ diff --git a/docs/books/nvchad/images/find_command.png b/docs/books/nvchad/images/find_command.png new file mode 100644 index 0000000000..99342580f6 Binary files /dev/null and b/docs/books/nvchad/images/find_command.png differ diff --git a/docs/books/nvchad/images/font_nerd_view.png b/docs/books/nvchad/images/font_nerd_view.png new file mode 100644 index 0000000000..44bd93b1c7 Binary files /dev/null and b/docs/books/nvchad/images/font_nerd_view.png differ diff --git a/docs/books/nvchad/images/help_visual_mode.png b/docs/books/nvchad/images/help_visual_mode.png new file mode 100644 index 0000000000..c3727d2295 Binary files /dev/null and b/docs/books/nvchad/images/help_visual_mode.png differ diff --git a/docs/books/nvchad/images/init_custom_plugins.png b/docs/books/nvchad/images/init_custom_plugins.png new file mode 100644 index 0000000000..50ea07f8d3 Binary files /dev/null and b/docs/books/nvchad/images/init_custom_plugins.png differ diff --git a/docs/books/nvchad/images/lazygit_menu.png b/docs/books/nvchad/images/lazygit_menu.png new file mode 100644 index 0000000000..ae1d647928 Binary files /dev/null and b/docs/books/nvchad/images/lazygit_menu.png differ diff --git a/docs/books/nvchad/images/lazygit_ui.png b/docs/books/nvchad/images/lazygit_ui.png new file mode 100644 index 0000000000..07a4f322ee Binary files /dev/null and b/docs/books/nvchad/images/lazygit_ui.png differ diff --git a/docs/books/nvchad/images/leader_ff.png b/docs/books/nvchad/images/leader_ff.png new file mode 100644 index 0000000000..e4afe84c5f Binary files /dev/null and b/docs/books/nvchad/images/leader_ff.png differ diff --git a/docs/books/nvchad/images/lspconfig_custom.png b/docs/books/nvchad/images/lspconfig_custom.png new file mode 100644 index 0000000000..fcc1cacfe0 Binary files /dev/null and b/docs/books/nvchad/images/lspconfig_custom.png differ diff --git a/docs/books/nvchad/images/lua-language-server.png b/docs/books/nvchad/images/lua-language-server.png new file mode 100644 index 0000000000..577cf38702 Binary files /dev/null and b/docs/books/nvchad/images/lua-language-server.png differ diff --git a/docs/books/nvchad/images/lua_diagnostic.png b/docs/books/nvchad/images/lua_diagnostic.png new file mode 100644 index 0000000000..3e745ca156 Binary files /dev/null and b/docs/books/nvchad/images/lua_diagnostic.png differ diff --git a/docs/books/nvchad/images/marksman_assistant.png b/docs/books/nvchad/images/marksman_assistant.png new file mode 100644 index 0000000000..18e9b8ad7d Binary files /dev/null and b/docs/books/nvchad/images/marksman_assistant.png differ diff --git a/docs/books/nvchad/images/marksman_diagnostic.png b/docs/books/nvchad/images/marksman_diagnostic.png new file mode 100644 index 0000000000..49b28c9a70 Binary files /dev/null and b/docs/books/nvchad/images/marksman_diagnostic.png differ diff --git a/docs/books/nvchad/images/marksman_enable.png b/docs/books/nvchad/images/marksman_enable.png new file mode 100644 index 0000000000..7d1c6fce68 Binary files /dev/null and b/docs/books/nvchad/images/marksman_enable.png differ diff --git a/docs/books/nvchad/images/marksman_server_info.png b/docs/books/nvchad/images/marksman_server_info.png new file mode 100644 index 0000000000..3e13562dfd Binary files /dev/null and b/docs/books/nvchad/images/marksman_server_info.png differ diff --git a/docs/books/nvchad/images/mason_help.png b/docs/books/nvchad/images/mason_help.png new file mode 100644 index 0000000000..cc65cc7b0b Binary files /dev/null and b/docs/books/nvchad/images/mason_help.png differ diff --git a/docs/books/nvchad/images/mason_installed.png b/docs/books/nvchad/images/mason_installed.png new file mode 100644 index 0000000000..11d059d6ac Binary files /dev/null and b/docs/books/nvchad/images/mason_installed.png differ diff --git a/docs/books/nvchad/images/mason_marksman.png b/docs/books/nvchad/images/mason_marksman.png new file mode 100644 index 0000000000..d5ce298c97 Binary files /dev/null and b/docs/books/nvchad/images/mason_marksman.png differ diff --git a/docs/books/nvchad/images/mason_ui.png b/docs/books/nvchad/images/mason_ui.png new file mode 100644 index 0000000000..a643a54d88 Binary files /dev/null and b/docs/books/nvchad/images/mason_ui.png differ diff --git a/docs/books/nvchad/images/neovim_tutor.png b/docs/books/nvchad/images/neovim_tutor.png new file mode 100644 index 0000000000..0c78f57d44 Binary files /dev/null and b/docs/books/nvchad/images/neovim_tutor.png differ diff --git a/docs/books/nvchad/images/nerd_fonts_site_small.png b/docs/books/nvchad/images/nerd_fonts_site_small.png new file mode 100644 index 0000000000..4a139623f5 Binary files /dev/null and b/docs/books/nvchad/images/nerd_fonts_site_small.png differ diff --git a/docs/books/nvchad/images/nvchad_init.png b/docs/books/nvchad/images/nvchad_init.png new file mode 100644 index 0000000000..0005d22e81 Binary files /dev/null and b/docs/books/nvchad/images/nvchad_init.png differ diff --git a/docs/books/nvchad/images/nvchad_rocky.png b/docs/books/nvchad/images/nvchad_rocky.png new file mode 100644 index 0000000000..3df72fc912 Binary files /dev/null and b/docs/books/nvchad/images/nvchad_rocky.png differ diff --git a/docs/books/nvchad/images/nvchad_th.png b/docs/books/nvchad/images/nvchad_th.png new file mode 100644 index 0000000000..15adf011c4 Binary files /dev/null and b/docs/books/nvchad/images/nvchad_th.png differ diff --git a/docs/books/nvchad/images/nvchad_ui.png b/docs/books/nvchad/images/nvchad_ui.png new file mode 100644 index 0000000000..cadb5ac30e Binary files /dev/null and b/docs/books/nvchad/images/nvchad_ui.png differ diff --git a/docs/books/nvchad/images/nvim_options.png b/docs/books/nvchad/images/nvim_options.png new file mode 100644 index 0000000000..c198cbfb39 Binary files /dev/null and b/docs/books/nvchad/images/nvim_options.png differ diff --git a/docs/books/nvchad/images/nvim_standard.png b/docs/books/nvchad/images/nvim_standard.png new file mode 100644 index 0000000000..3b0729f6d5 Binary files /dev/null and b/docs/books/nvchad/images/nvim_standard.png differ diff --git a/docs/books/nvchad/images/nvim_tree.png b/docs/books/nvchad/images/nvim_tree.png new file mode 100644 index 0000000000..4ebaa7d89b Binary files /dev/null and b/docs/books/nvchad/images/nvim_tree.png differ diff --git a/docs/books/nvchad/images/nvimtree_git.png b/docs/books/nvchad/images/nvimtree_git.png new file mode 100644 index 0000000000..bd345e697d Binary files /dev/null and b/docs/books/nvchad/images/nvimtree_git.png differ diff --git a/docs/books/nvchad/images/telescope_find_files.png b/docs/books/nvchad/images/telescope_find_files.png new file mode 100644 index 0000000000..01c778bba4 Binary files /dev/null and b/docs/books/nvchad/images/telescope_find_files.png differ diff --git a/docs/books/nvchad/images/ui_default.png b/docs/books/nvchad/images/ui_default.png new file mode 100644 index 0000000000..45fa92661b Binary files /dev/null and b/docs/books/nvchad/images/ui_default.png differ diff --git a/docs/books/nvchad/images/ui_default_light.png b/docs/books/nvchad/images/ui_default_light.png new file mode 100644 index 0000000000..562d84d753 Binary files /dev/null and b/docs/books/nvchad/images/ui_default_light.png differ diff --git a/docs/books/nvchad/images/ui_escape_key.png b/docs/books/nvchad/images/ui_escape_key.png new file mode 100644 index 0000000000..768ee9808d Binary files /dev/null and b/docs/books/nvchad/images/ui_escape_key.png differ diff --git a/docs/books/nvchad/images/ui_nvchad_split.png b/docs/books/nvchad/images/ui_nvchad_split.png new file mode 100644 index 0000000000..1e54c867a4 Binary files /dev/null and b/docs/books/nvchad/images/ui_nvchad_split.png differ diff --git a/docs/books/nvchad/images/ui_statusline.png b/docs/books/nvchad/images/ui_statusline.png new file mode 100644 index 0000000000..3177473fc5 Binary files /dev/null and b/docs/books/nvchad/images/ui_statusline.png differ diff --git a/docs/books/nvchad/images/ui_tabufline.png b/docs/books/nvchad/images/ui_tabufline.png new file mode 100644 index 0000000000..7921ca5aa2 Binary files /dev/null and b/docs/books/nvchad/images/ui_tabufline.png differ diff --git a/docs/books/nvchad/images/ui_wK_01.png b/docs/books/nvchad/images/ui_wK_01.png new file mode 100644 index 0000000000..05b73e2a9b Binary files /dev/null and b/docs/books/nvchad/images/ui_wK_01.png differ diff --git a/docs/books/nvchad/images/ui_wK_key.png b/docs/books/nvchad/images/ui_wK_key.png new file mode 100644 index 0000000000..c616ecb9dc Binary files /dev/null and b/docs/books/nvchad/images/ui_wK_key.png differ diff --git a/docs/books/nvchad/images/vsplit_open.png b/docs/books/nvchad/images/vsplit_open.png new file mode 100644 index 0000000000..7e6c0e8da9 Binary files /dev/null and b/docs/books/nvchad/images/vsplit_open.png differ diff --git a/docs/books/nvchad/images/which_key.png b/docs/books/nvchad/images/which_key.png new file mode 100644 index 0000000000..342e7f349d Binary files /dev/null and b/docs/books/nvchad/images/which_key.png differ diff --git a/docs/books/nvchad/images/yamlls_server.png b/docs/books/nvchad/images/yamlls_server.png new file mode 100644 index 0000000000..40f49ddd78 Binary files /dev/null and b/docs/books/nvchad/images/yamlls_server.png differ diff --git a/docs/books/nvchad/index.md b/docs/books/nvchad/index.md new file mode 100644 index 0000000000..f79e888607 --- /dev/null +++ b/docs/books/nvchad/index.md @@ -0,0 +1,124 @@ +--- +title: Overview +author: Franco Colussi +contributors: Steven Spencer +tested with: 9.0 +tags: + - nvchad + - coding + - editor +--- + +# Introduction + +Throughout this book, you will find ways to implement Neovim, along with NvChad, to create a fully functional **I**ntegrated **D**evelopment **E**nvironment (IDE). + +I say "ways" because there are many possibilities. The author focuses the chapters here on using these tools for writing markdown, but if markdown isn't your focus, don't worry simply read on. If you are unfamiliar with either of these tools (NvChad or Neovim), then this book will give you an introduction to both, and if you step through the chapters here, you'll soon realize that you can set up this environment to be a huge help for whatever your programming or script writing needs are. + +Want an IDE that will help in writing Ansible playbooks? You can get that! Want and IDE for Golang? That's available too. Simply want a good interface for writing BASH scripts? That's also available. + +Through the use of **L**anguage **S**erver **P**rotocols and linters, you can setup an environment that is customized just for you. The best part is that once you have the environment setup, it can quickly be updated when new changes are available through the use of Packer and Mason, both of which are covered here. + +Because Neovim is a fork of `vim`, the overall interface will be familiar to `vim` users. If you aren't a `vim` user, then you will pick up on the syntax of the commands quickly using this book. There's a lot of information covered here but it's easy to follow along, and once you've completed the chapters you'll know enough to build your own IDE for _your_ needs with these tools. + +## Using Neovim as an IDE + +The basic installation of Neovim provides an excellent editor for development, but it cannot yet be called an IDE; all the features even if already preset are not yet activated. To do this we need to pass the necessary configurations to Neovim, and this is where NvChad comes to our aid, which allows us to have a basic configuration out of the box with just one command! + +The configuration is written in Lua, a very fast programming language that allows NvChad to have startup and execution times for commands and keystrokes that are very fast as well. This is also made possible by the `Lazy loading` technique used for plugins that allows them to load only when required. + +The interface turns out to be very clean and pleasant. + +As the developers of NvChad are keen to point out, the project is only intended to be a base on which to build your own personal IDE. Subsequent customization is done through the use of plugins. + +![NvChad UI](images/nvchad_rocky.png) + +### Main Features + +- **Designed to be fast.** From the choice of programming language to techniques for loading components, everything is designed to minimize execution time. + +- **Attractive Interface.** Despite being a _cli_ application the interface looks modern and beautiful graphically, plus all the components fit the UI perfectly. + +- **Extremely Configurable.** Due to the modularity derived from the base used (NeoVim), the editor can be adapted perfectly to one's needs. Keep in mind, however, that when we talk about customization we are referring to functionality not to the appearance of the interface. + +- **Automatic update mechanism.** The editor comes with a mechanism (through the use of _git_) that allows updating with a simple `uu` command. + +- **Powered by Lua.** NvChad's configuration is written entirely in _lua_, which allows it to integrate seamlessly into Neovim's configuration by taking advantage of the full potential of the editor on which it is based. + +- **Numerous inbuilt themes.** The configuration already includes a large number of themes to use, always keeping in mind that we are talking about a _cli_ application, themes can be selected with the `th` key. + +![NvChad Themes](images/nvchad_th.png) + +## References + +### Lua + +#### What is Lua? + +Lua is a robust, lightweight, scripting language that supports a variety of programming methods. The name "Lua" comes from the Portuguese word meaning "moon." + +Lua was developed at the Catholic University of Rio de Janeiro by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. The development was necessary for them because until 1992 Brazil was subject to strict import regulations for hardware and software, so out of sheer necessity, these three programmers developed their own scripting language called Lua. + +Because Lua focuses primarily on scripts, it is rarely used as a stand-alone programming language. Instead, it is most often used as a scripting language that can be integrated (embedded) into other programs. + +Lua is used in the development of video games and game engines (Roblox, Warframe..), as a programming language in many network programs (Nmap, ModSecurity..), and as a programming language in industrial programs. Lua is also used as a library that developers can integrate into their programs to enable scripting functionality by acting solely as an integral part of the host application. + +#### How Lua works + +There are two main components of Lua: + +- The Lua interpreter +- The Lua virtual machine (VM) + +Lua is not interpreted directly through a Lua file like other languages, for example Python. Instead, it uses the Lua interpreter to compile a Lua file into bytecode. The Lua interpreter is highly portable and capable of running on a multitude of devices. + +#### Key Features + +- Speed: Lua is considered one of the fastest programming languages among interpreted scripting languages; it can perform very performance-heavy tasks faster than most other programming languages. + +- Size: Lua has a really small size compared to other programming languages. This small size is ideal for integrating Lua into multiple platforms, from embedded devices to game engines. + +- Portability and integration: The portability of Lua is almost unlimited. Any platform that supports the standard C compiler can run Lua without problems. Lua does not require complex rewrites to be compatible with other programming languages. + +- Simplicity: Lua has a simple design but provides powerful functionality. One of the main features of Lua are meta-mechanisms, which allow developers to implement their own functionality. The syntax is simple and in an easily understood format, so that anyone can easily learn Lua and use it in their own programs. + +- License: Lua is free and open-source software distributed under the MIT license. This allows anyone to use it for any purpose without paying any license or royalties. + +### Neovim + +Neovim is dealt with in detail on its [dedicated page](to be built) so we will just dwell on the main features, which are: + +- Performance: Very fast. + +- Customizable: Wide ecosystem of plugins and themes. + +- Syntax highlighting: Integration with Treesitter and LSP, (requires some additional configurations). + +- Multiplatform: Linux, Windows and macOS + +- License: Mit: A short and simple permissive license with conditions requiring only the preservation of copyright and license notices. + +### LSP + +What is the **L**anguage **S**erver **P**rotocol? + +A language server is a standardized language library that uses its own procedure (protocol) to provide support for functions such as autocomplete, goto definition, or mouseover definitions. + +The idea behind the Language Server Protocol (LSP) is to standardize the communication protocol between tools and servers, so that a single language server can be reused in multiple development tools. In this way, developers can simply integrate these libraries into their editors and reference existing language infrastructures, instead of customizing their code to include them. + +### tree-sitter + +[Tree-sitter](https://tree-sitter.github.io/tree-sitter/) basically consists of two components: a parser generator, and an incremental parsing library. It can build a syntactic tree of the source file and efficiently update it with each change. + +A parser is a component that decomposes data into smaller elements to facilitate its translation into another language, or as in our case, to be then passed to the parsing library. Once the source file has been decomposed, the parsing library parses the code and transforms it into a syntactic tree, allowing the structure of the code to be manipulated more intelligently. This makes it possible to improve (and speed up) + +- syntax highlighting +- code navigation +- refactoring +- text objects and movements + +!!! notes "LSP and tree-sitter complementarity." + + Although it may seem that the two services (LSP and tree-sitter) are redundant they are actually complementary in that LSP works at the project level while tree-sitter works only on the open source file. + +Now that we have explained a bit about the technologies used to create the IDE we can move on to the [Additional Software](additional_software.md) needed to configure our NvChad. diff --git a/docs/books/nvchad/install_nvchad.md b/docs/books/nvchad/install_nvchad.md new file mode 100644 index 0000000000..ac8655483b --- /dev/null +++ b/docs/books/nvchad/install_nvchad.md @@ -0,0 +1,157 @@ +--- +title: Install NvChad +author: Fanco Colussi +contributors: Steven Spencer +tested with: 9.0 +tags: + - nvchad + - coding +--- + +## Turning Neovim into an advanced IDE + +This is actually not a real installation but rather writing a custom Neovim configuration into our user configuration. + +!!! warning "Performing a Clean Installation" + + As specified in the requirements, installing this new configuration on top of a previous one can create unfixable problems. A clean installation is recommended. + +### Preliminary Operations + +If you have used the Neovim installation before, it will have created three folders in which to write your files, which are: + +```text +~/.config/nvim +~/.local/share/nvim +~/.cache/nvim +``` + +To perform a clean installation of the configuration, we need to back up the previous one first: + +```bash +mkdir ~/backup_nvim +cp -r ~/.config/nvim ~/backup_nvim +cp -r ~/.local/share/nvim ~/backup_nvim +cp -r ~/.cache/nvim ~/backup_nvim +``` + +And then we delete all previous configurations and files: + +```bash +rm -rf ~/.config/nvim +rm -rf ~/.local/share/nvim +rm -rf ~/.cache/nvim +``` + +Now that we have cleaned up, we can move on to installing NvChad. + +To do this, simply run the following command from any location within your _home directory_: + +```bash +git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 && nvim +``` + +The command runs a clone of the NvChad configuration hosted on GitHub in the user folder `~/.config/nvim`. + +Once the cloning process is finished, the plugins that are part of the default configuration will be installed and configured and when finished, you will have the IDE ready for editing. + +![NvChad Themes](images/nvchad_init.png) + +As can be seen from the screenshot below, the editor, thanks to the configuration changes made, has completely changed in appearance from the basic version of Neovim. It should be remembered, however, that although the configuration of NvChad completely transforms the editor, the base is, and remains Neovim. + +![NvChad Rockydocs](images/nvchad_ui.png) + +### Configuration Structure + +Let us now go on to analyze the structure that the configuration created, the structure is as follows: + +```text +nvim/ +├── examples +│   ├── chadrc.lua +│   └── init.lua +├── init.lua +├── LICENSE +├── lua +│   ├── core +│   │   ├── default_config.lua +│   │   ├── init.lua +│   │   ├── lazy_load.lua +│   │   ├── mappings.lua +│   │   ├── options.lua +│   │   ├── packer.lua +│   │   └── utils.lua +│   └── plugins +│   ├── configs +│   │   ├── alpha.lua +│   │   ├── cmp.lua +│   │   ├── lspconfig.lua +│   │   ├── mason.lua +│   │   ├── nvimtree.lua +│   │   ├── nvterm.lua +│   │   ├── others.lua +│   │   ├── telescope.lua +│   │   ├── treesitter.lua +│   │   └── whichkey.lua +│   └── init.lua +└── plugin + └── packer_compiled.lua +``` + +!!! note "Note" + + For the moment we will leave out the contents of the `examples` folder as it relates to the `custom` configuration, which we will address in later sections. + +The first file we encounter is the `init.lua` file which initializes the configuration by inserting into the _nvim_ tree the `lua/core`, `lua/plugins` and if present, the `lua/custom` folder. It also inserts the `lua/core/options.lua`, `lua/core/utils.lua`, and `lua/core/packer.lua` files. In particular, the `load_mappings` function is called for loading keyboard shortcuts and `bootstrap` for loading preconfigured plugins. + +```lua +require "core" +require "core.options" + +vim.defer_fn(function() + require("core.utils").load_mappings() +end, 0) + +-- setup packer + plugins +require("core.packer").bootstrap() +require "plugins" + +pcall(require, "custom") +``` + +Inclusion of the `core` folder also results in the inclusion of the _core/init.lua_ file, which overrides some Neovim interface configurations and prepares for buffer management. + +As we can see, each _init.lua_ file is included following a well-established order, and we can anticipate that the _init.lua_ file we are going to create in our customization will also be included in turn-last, of course. Broadly speaking, we can say that _init.lua_ files have the following functions: + +- load global options, autocmds, or anything else. +- override the default options in _core/options.lua_. + +Returning to the call for command mapping: + +```lua +`require("core.utils").load_mappings() +``` + +This sets four main keys from which, in association with other keys, commands can be launched. The main keys are: + +- C = CTRL +- leader = space +- A = ALT +- S = SHIFT + +The default mapping is contained in _core/mapping.lua_ but can be extended with other custom commands using its own _mappings.lua_. + +Some examples of the standard mapping are: + +```text +uu to update NvChad +th to change the theme + to open nvimtree + to open a terminal in a floating tab +``` + +The combinations set are really many, and cover all the use of NvChad. It is worth pausing to analyze the mapping before starting to use it. + +Continuing with the structure analysis we find the _lua/plugins_ folder, which contains the setup of the built-in plugins and their configurations. The main plugins in the configuration will be described in the next section. As we can see, the _core/plugins_ folder also contains an _init.lua_ file, which is used here for the installation and subsequent compilation of the plugins. + +To close we find the _nvim/plugin_ folder that contains an autogenerated file of the compiled plugins. diff --git a/docs/books/nvchad/install_nvim.md b/docs/books/nvchad/install_nvim.md new file mode 100644 index 0000000000..192013f829 --- /dev/null +++ b/docs/books/nvchad/install_nvim.md @@ -0,0 +1,192 @@ +--- +title: Install Neovim +author: Franco Colussi +contributors: Steven Spencer +tested with: 9.0 +tags: + - nvchad + - coding +--- + +## Introduction to Neovim + +Neovim is one of the best code editors due of its speed, ease of customization, and configuration. + +Neovim is a fork of the `Vim` editor. It was born in 2014, mainly due to the lack at the time of asynchronous support in Vim. Written in the Lua language with the goal of modularizing the code to make it more manageable, Neovim was designed with the modern user in mind. As the official website states, "Neovim is built for users who want the best parts of Vim, and more". + +The developers of Neovim chose Lua as it was perfect for embedding, using LuaJIT quickly, and with a simple, scripting-oriented syntax. + +From version 0.5 Neovim includes Treesitter (a parser generator tool) and supports Language Server Protocol (LSP). This reduces the number of plugins needed to achieve advanced editing functions. It improves the performance of operations such as code completion and linting. + +One of its strengths is its customization. All of its configuration is contained in a single file that can be distributed to the various installations through a version manager (Git or other) so that the various installations are always synchronized. + +### Community of developers + +Although Vim and Neovim are both open-source projects and hosted on GitHub, there is a significant difference between the modes of development. Neovim has a more open community development, while Vim's development is more tied to the choices of its creator. Neovim's user and developer base is quite small compared to Vim, but it is a continuously growing project. + +### Key Features + +- Performance: Very fast. +- Customizable: Wide ecosystem of plugins and themes +- Syntax highlighting: Integrated with Treesitter and LSP, but requires some configuration + +As with Vim, Neovim requires a basic knowledge of its commands and options. You can get an overview of its features through the `:Tutor` command that invokes a file where you can read, and practice using it. Learning takes longer than a fully graphical IDE, but once you learn the shortcuts to the commands and the included features, you will proceed very smoothly in editing documents. + +![Nvim Tutor](images/neovim_tutor.png) + +## Neovim Installation + +### Installation from EPEL + +Before moving on to the installation of NvChad, we need to make sure that we have an installation of Neovim available. If it is not already installed, you can install it from the EPEL Repository, even if the version provided does not meet the minimum requirements. + +To install the Neovim release provided by EPEL, we install if you have not already done so the repository. + +```bash +dnf install epel-release +``` + +And we type the following command to install the application: + +```bash +dnf install neovim +``` + +### Installation from Precompiled Package + +In order to meet the minimum requirements of NvChad, it is suggested that you install the precompiled package provided by Neovim instead. This solves the problem of the version provided by EPEL (currently 0.7.0.1), which does not meet the minimum requirement. + +In order to use all the features of the new version, we still have to satisfy the dependencies required by Neovim. If we decide to remove or not install the outdated version from EPEL at all, we have to provide _our_ `nvim` with the dependencies manually. The required packages can be installed with: + +```bash +dnf install compat-lua-libs libtermkey libtree-sitter libvterm luajit luajit2.1-luv msgpack unibilium xsel +``` + +Next, we download the compressed archive for our architecture (linux64) from this address: + +```text +https://github.com/neovim/neovim/releases +``` + +The file to be downloaded is `nvim-linux64.tar.gz`, to verify the integrity of the archive we also download the file `nvim-linux64.tar.gz.sha256sum`, once downloaded we need to verify its integrity and unpack it somewhere in our `home directory`. The proposed solution is to unpack it in `~/.local/share/`, assuming we downloaded it in _/home/user/downloads/_ we will need to run the following commands: + +```bash +sha256sum -c /home/user/downloads/nvim-linux64.tar.gz.sha256sum +nvim-linux64.tar.gz: OK + +tar xvzf /home/user/downloads/nvim-linux64.tar.gz +mv /home/user/downloads/nvim-linux64 ~/.local/share/nvim-linux64 +``` + +All that remains at this point is to create a symbolic link in `~/.local/bin/` for our _nvim_. + +```bash +cd ~/.local/bin/ +ln -sf ~/.local/share/nvim-linux64/bin/nvim nvim +``` + +To be shure, we check the version provided by the `nvim -v` command, which should now show: + +```txt +nvim -v +NVIM v0.7.2 +Build type: Release +LuaJIT 2.1.0-beta3 +Compiled by runner@fv-az164-457 + +Features: +acl +iconv +tui +See ":help feature-compile" + + system vimrc file: "$VIM/sysinit.vim" + fall-back for $VIM: "/share/nvim" + +Run :checkhealth for more info +``` + +### Installation from Source + +Installation from precompiled package provides an installation for only the user who runs it, in case you want to make Neovim available to all users of the system you will have to do an installation from source. Compiling Neovim is not particularly difficult and consists of the following steps. + +We first install the packages required for compilation: + +```bash +dnf install ninja-build libtool autoconf automake cmake gcc gcc-c++ make pkgconfig unzip patch gettext curl +``` + +Once we have installed the necessary packages we need to download the Neovim sources, sources that are distributed with *Git*. In our example we will have a folder already created for the purpose in `/home/user/lab/build`. Adapt your commands according to the structure you choose. + +The Neovim clone by default is synchronized with the Neovim development branch (currently the 8.0), to compile the stable version we will have to switch to the corresponding branch before cloning with: + +```bash +cd ~/lab/build +git checkout stable +``` + +And subsequently clone the repository: + +```bash +git clone https://github.com/neovim/neovim +``` + +Once the operation is finished we will have a folder named *neovim* containing all the necessary files, the next step is to configure and compile the sources, an operation that is done with the `make` command, we then go to the *neovim* folder and proceed with the configuration: + +```bash +cd ~/lab/build/neovim/ +make CMAKE_BUILD_TYPE=RelWithDebInfo +``` + +We chose the `RelWithDebInfo` type because it provides not only optimizations but also a useful debugging layer for later customizations, you could have also used the `Release` type if you want maximum performance. + +The process takes care of configuring and compiling the files that are to be put into our system, files that are saved in `neovim/build`, to install them we will still use the *make* command: + +```bash +make install +``` + +This command going to modify the filesystem needs superuser (sudo) privileges or to be run as the root user. + +Once the installation is finished, we can verify that everything went well by checking the path to Neovim: + +``` +whereis nvim +nvim: /usr/local/bin/nvim +``` + +And verifying the version: + +```bash +nvim --version +NVIM v0.8.0-dev-885-ga5ed89c97 +Build type: RelWithDebInfo +LuaJIT 2.1.0-beta3 +.... +``` + +As you can see from the command excerpt above, an installation of the development version was performed here. Both versions, stable and development, work perfectly with NvChad on Rocky Linux 9. + +#### Uninstall + +In case we need to remove the installation, for example to switch to another version, we will have to take ourselves back to the build folder and use the `target` cmake provided by Neovim itself, to perform the uninstallation, you need to execute the following command: + +```bash +cmake --build build/ --target uninstall +``` + +This command also requires superuser privileges or to be run as a *root* user. + +Alternatively, you can use the manual method by removing the executable and libraries with: + +```bash +rm /usr/local/bin/nvim +rm -r /usr/local/share/nvim/ +``` + +Always with administrator permissions. + +## Neovim Basic + +As you can see from the screenshot, a basic installation of Neovim provides an editor that cannot yet be compared to an IDE. + +![Neovim Standard](images/nvim_standard.png) + +Now that we have our basic editor, it is time to turn it into something more advanced thanks to the configuration provided by [NvChad](install_nvchad.md). diff --git a/docs/books/nvchad/nerd_fonts.md b/docs/books/nvchad/nerd_fonts.md new file mode 100644 index 0000000000..cc1cd76f75 --- /dev/null +++ b/docs/books/nvchad/nerd_fonts.md @@ -0,0 +1,56 @@ +--- +title: wip - Installing Nerd Fonts +author: Franco Colussi +contributors: Steven Spencer +tested: 9.0 +tags: + - nvchad + - coding + - fonts +--- + +# Nerd Fonts - Fonts for Developers + +![Nerd Fonts](images/nerd_fonts_site_small.png){ align=right } Nerd Fonts is a collection of modified fonts aimed at developers with a large number of glyphs (icons). In particular, "iconic fonts" such as Font Awesome, Devicons, Octicons etc. are used to add extra glyphs. + +Nerd Fonts takes the most popular programming fonts and modifies them by adding a group of glyphs. A font patcher is also available if the desired font has not already been edited. A convenient preview is available on the site, allowing you to see how the font should look in the editor. For more information, check the [site](https://www.nerdfonts.com/). + +## Download + +Fonts are available for download at: + +```text +https://www.nerdfonts.com/font-downloads +``` + +## Installation + +The procedure for installing fonts on Rocky Linux is to save the fonts you want to add somewhere and then install them with the `fc-cache` command; the procedure is not a true installation so much as a registration of the new fonts in the system. + +!!! important "Creation of compressed packages" + + The procedure described below is not a standard procedure as each developer has packaged fonts using a custom scheme. So once downloaded and extracted, the contents must be checked to choose the procedure for copying the fonts. + +For this guide we will use the `Sauce Code Pro Nerd` font. + +Download the package with: + +```bash +https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/SourceCodePro.zip +``` + +Next, unzip the contents of the folder and copy the fonts to `~/.local/share/fonts/` with: + +```bash +mkdir ~/.local/share/fonts +unzip SourceCodePro.zip -d ~/.local/share/fonts/ +fc-cache ~/.local/share/fonts +``` + +## Configuration + +At this point the _font nerd_ should be available for selection. To actually select it you must refer to the desktop you are using. + +![Font Manager](images/font_nerd_view.png) + +If you are using the default Rocky Linux desktop (Gnome), to change the font in the terminal emulator you will just need to open `gnome-terminal`, go to "Preferences", and set the Nerd Font for your profile. diff --git a/docs/books/nvchad/nvchad_ui/.pages b/docs/books/nvchad/nvchad_ui/.pages new file mode 100644 index 0000000000..49603fe8f7 --- /dev/null +++ b/docs/books/nvchad/nvchad_ui/.pages @@ -0,0 +1,5 @@ +--- +nav: + - ... | builtin_plugins*.md + - ... | nvchad_ui*.md + - ... | using_nvchad*.md diff --git a/docs/books/nvchad/nvchad_ui/builtin_plugins.md b/docs/books/nvchad/nvchad_ui/builtin_plugins.md new file mode 100644 index 0000000000..63de409b25 --- /dev/null +++ b/docs/books/nvchad/nvchad_ui/builtin_plugins.md @@ -0,0 +1,142 @@ +--- +title: Built-In Plugins +author: Franco Colussi +contributors: Steven Spencer +tags: + - nvchad + - coding + - plugins +--- + +## Basic configuration plugins + +!!! note "Plugin Naming Convention" + + In this chapter, the format `user_github/plugin_name` will be used to identify the plugin. This is to avoid possible errors with similarly named plugins and to introduce the format that is used for plugin entry by both NvChad, and the `custom` configuration. + +NvChad keeps the configuration of its plugins in the file `lua/plugins/init.lua`. We can see see an excerpt below: + +```lua +vim.cmd "packadd packer.nvim" + +local plugins = { + + ["nvim-lua/plenary.nvim"] = { module = "plenary" }, + ["wbthomason/packer.nvim"] = {}, + ["NvChad/extensions"] = { module = { "telescope", "nvchad" } }, + + ["NvChad/base46"] = { + config = function() + local ok, base46 = pcall(require, "base46") + + if ok then + base46.load_theme() + end + end, + }, +... +... +require("core.packer").run(plugins) +``` + +It is necessary to acknowledge the huge amount of work done by the NvChad developers, whose contributions have created an integrated environment among all plugins. Everything is perfectly adhered to the user interface making it very clean and professional. In addition, plugins that work *under the hood* allow advanced editing and other useful features. All of this allows ordinary users to have, in an instant, a basic IDE to start working with and an extensible configuration so that it can adapt to our needs. + +### Main Plugins + +The following is a brief analysis of the main plugins: + +- [nvim-lua/plenary.nvim](https://github.com/nvim-lua/plenary.nvim) Provides a library of commonly used lua functions that are used by the other plugins, for example *telescope* and *gitsigns*. + +- [wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim) Provides the functionality for managing plugins. It allows for the management of all operations on plugins through convenient commands. The commands provided are: + + - `:PackerCompile` + - `:PackerClean` + - `:PackerInstall` + - `:PackerUpdate` + - `:PackerSync` + - `:PackerLoad` + +- [NvChad/extensions](https://github.com/NvChad/extensions) The core utilities of NvChad. Here we find: + + - the *nvchad* folder containing the utilities, *change_theme*, *reload_config*, *reload_theme*, *update_nvchad*. + - the *telescope/extension* folder that provides the choice of theme directly from Telescope. + +- [NvChad/base46](https://github.com/NvChad/base46) Provides themes for the interface. + +- [NvChad/ui](https://github.com/NvChad/ui) Provides the actual interface. Thanks to this plugin we can have a *statusline* that gives us the information during editing and a *tabufline* that allows us to manage open buffers. + +- [NvChad/nvterm](https://github.com/NvChad/nvterm) Provides a terminal to our IDE where we can issue commands. The terminal can be opened within the buffer in various ways: + + - `` opens a terminal by dividing the buffer horizontally + - `` opens the terminal by dividing the buffer vertically + - `` opens a terminal in a floating tab + +- [kyazdani42/nvim-web-devicons](https://github.com/kyazdani42/nvim-web-devicons) Adds icons (requires a Font Nerd) to file types and folders in our IDE. This allows us to visually identify file types in our File Explorer by speeding up operations. + +- [lukas-reineke/indent-blankline.nvim](https://github.com/lukas-reineke/indent-blankline.nvim) Provides guides to better identify indentation in the document, allowing sub-routines and nested commands to be easily recognized. + +- [NvChad/nvim-colorizer.lua](https://github.com/NvChad/nvim-colorizer.lua) Another plugin written by the developers of NvChad. It is specifically a high-performance highlighter. + +- [nvim-treesitter/nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) Allows you to use the tree-sitter interface in Neovim, and provide some basic functionality, such as highlighting. + +- [lewis6991/gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim) Provides decoration for *git* with reports for added, removed, and changed lines-reports that are also integrated into the *statusline*. + +### LSP functionality + +Now let's move on to the plugins that provide the functionality to integrate LSPs (Language Server Protocols) into our projects. This is definitely one of the best features provided by NvChad. Thanks to LSPs we can be in control of what we write in real time. + +- [williamboman/mason.nvim](https://github.com/williamboman/mason.nvim) Allows simplified management of LSP (Language Server) installation through a convenient graphical interface. Its use is described in the [dedicated page for LSPs](../custom/lsp.md). The commands provided are: + + - `:Mason` + - `:MasonInstall` + - `:MasonUninstall` + - `:MasonUnistallAll` + - `:MasonLog` + +- [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) Provides the appropriate configurations for almost every language server available. It is a community collection, with the most relevant settings already set. The plugin takes care of receiving our configurations and putting them into the editor environment. It provides the commands: + + - `:LspInfo` + - `:LspStart` + - `:LspStop` + - `:LspRestart` + +### Lua Code + +Following LSP, come all the plugins that provide functionality in writing and executing Lua code such as snippets, lsp commands, buffers etc. We will not go into detail for these plugins, but they can be viewed in their respective projects on GitHub. + +The plugins are: + +- [rafamadriz/friendly-snippets](https://github.com/rafamadriz/friendly-snippets) +- [hrsh7th/nvim-cmp](https://github.com/hrsh7th/nvim-cmp) +- [L3MON4D3/LuaSnip](https://github.com/L3MON4D3/LuaSnip) +- [saadparwaiz1/cmp_luasnip](https://github.com/saadparwaiz1/cmp_luasnip) +- [hrsh7th/cmp-nvim-lua](https://github.com/hrsh7th/cmp-nvim-lua) +- [hrsh7th/cmp-nvim-lsp](https://github.com/hrsh7th/cmp-nvim-lsp) +- [hrsh7th/cmp-buffer](https://github.com/hrsh7th/cmp-buffer) +- [hrsh7th/cmp-path](https://github.com/hrsh7th/cmp-path) + +### Mixed Plugins + +- [windwp/nvim-autopairs](https://github.com/windwp/nvim-autopairs) Thanks to this plugin we have the functionality of automatic closing of parentheses and other characters. For example, by inserting a beginning parenthesis `(` completion will automatically insert the closing parenthesis `)` placing the cursor in the middle. + +- [goolord/alpha-nvim](https://github.com/goolord/alpha-nvim) Provides a home screen from which to access recent files, open the last session, find files, etc. + +- [numToStr/Comment.nvim](https://github.com/numToStr/Comment.nvim) Provides advanced functionality for code commenting. + +### File Management + +- [kyazdani42/nvim-tree.lua](https://github.com/kyazdani42/nvim-tree.lua) A File Explorer for Neovim that allows the most common operations on files (copy, paste, etc.), has an integration with Git, identifies files with different icons, and other features. Most importantly, it updates automatically (this is very useful when you work with Git repositories). + + ![Nvim Tree](../images/nvim_tree.png) + +- [nvim-telescope/telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) Provides advanced file search capabilities, is highly customizable, and for example, is used for selecting NvChad themes (command `:Telescope themes`). + + ![Telescope find_files](../images/telescope_find_files.png) + +- [folke/which-key.nvim](https://github.com/folke/which-key.nvim) Displays all possible autocompletions available for the entered partial command. + + ![Which Key](../images/which_key.png) + +- [lewis6991/impatient.nvim](https://github.com/lewis6991/impatient.nvim) Performs several operations at the start of the editor to make the loading of modules faster. + +Now having introduced the plugins that make up the basic configuration of NvChad we can move on to the description of the interface. diff --git a/docs/books/nvchad/nvchad_ui/nvchad_ui.md b/docs/books/nvchad/nvchad_ui/nvchad_ui.md new file mode 100644 index 0000000000..bb16828700 --- /dev/null +++ b/docs/books/nvchad/nvchad_ui/nvchad_ui.md @@ -0,0 +1,105 @@ +--- +title: NvChad UI +author: Franco Colussi +contributors: Steven Spencer +tested: 9.0 +tags: + - nvchad + - coding + - nvchad interface +--- + +# NvChad Interface + +Once Neovim is installed and the NvChad configuration is entered, our IDE should look like this: + +![NvChad Default](../images/ui_default.png) + +The interface already comes with some advanced functionality (such as indicating the status of the git repository) but can be further enhanced by using, for example, the [Language Servers](../custom/lsp.md) and customized by overriding some basic configurations. The basic modules that make it up are: + +## Tabufline + +![Tabufline](../images/ui_tabufline.png) + +The user interface presents a top bar called `Tabufline` where the open buffers are managed. The open buffer presents the file type icon, the file name and its status. Status is indicated with an icon. If as in the screenshot we have a red `x` it means that the file can be closed as it is already saved. If instead the icon is a green dot `.`, then the file needs to be saved, and a close command :q will produce a warning about saving to be done before the buffer is closed. + +To the right is the icon for setting the *dark* or *light* theme. By clicking on it with the mouse, we can select the chosen theme. + +![NvChad Light](../images/ui_default_light.png) + +On the right also we have the icon for closing our editor. + +## Middle Section - Open Buffers + +The central part of the editor is composed of the buffer active on the editor at that moment (*index.en.md*). To anticipate some additional functionality we can work simultaneously on two files in a split buffer by opening one more in the example (*index.it.md*). In the editor we will have the first buffer in the foreground and the second one listed in the Tabufline. Now if we split the first buffer with the `:vsplit` command and select the right buffer, clicking on the name of the second file (*index.it.md*) in the tabufline, this will be opened in the right buffer and we can work with the two files side by side. + +![NvChad Split](../images/ui_nvchad_split.png) + +## Statusline + +![Statusline](../images/ui_statusline.png) + +At the bottom we find the Statusline, which handles status information. On the right we find the editor status. We must not forget that we are using a text editor and that, in particular, it maintains the philosophy and operation of Vim. The possible states are: + +- **NORMAL** + +- **INSERT** + +- **COMMAND** + +- **VISUAL** + +Editing a document starts from the **NORMAL** state where you open the file, switch to **INSERT** mode for editing, and when finished exit with ESC and return to **NORMAL** mode. Now to save the file you switch to **COMMAND** mode by typing `:` in the statusline followed by `w` (*write*) to write it and with ESC you return to **NORMAL** mode. The status indication is very useful while learning how to use it, particularly if one is not very familiar with the Vim workflow. + +We then find the name of the open file, and if we are working on a git repository, we will have indications of the status of the repository. This is thanks to the *lewis6991/gitsigns.nvim* plugin. + +Turning to the right side we find the indication of the folder from which we opened the editor. In the case of the use of LSPs, this indicates the folder that is taken into account as `workspace`, and consequently evaluated during diagnostics, and to follow the position of the cursor within the file. + +## Integrated Help + +NvChad and Neovim provide some useful commands for displaying preset key combinations and available options. + +If the `` key alone is pressed it will provide a legend of associated commands as in the following screenshot: + +![Space Key](../images/ui_escape_key.png) + +To view all the commands included in the editor we can use the `wK` command, which will give the following result: + +![leader wK](../images/ui_wK_key.png) + +and by pressing d we can display the remaining commands: + +![leader wK d](../images/ui_wK_01.png) + +As we can see, almost all the commands refer to navigation within the document or buffer. No commands for opening the file are included. These are provided by the Neovim commands. + +To view all of Neovim's options, the `:options` command is available, which will present a tree of options indexed by category. + +![Nvim Options](../images/nvim_options.png) + +This gives us a way, through the built-in help, to learn the commands while using the editor, and also to delve into the available options. + +## NvimTree + +In order to work with our files we need a File Explorer, and this is provided by the *kyazdani42/nvim-tree.lua* plugin. With the combination CTRL n we can open NvimTree. + +![NvimTree](../images/nvim_tree.png) + +As we can see below, after NORMAL the open file is not shown but instead the buffer with NvimTree. In case we are not in the right buffer, we can use the leader e command provided by NvChad to switch the focus on NvimTree. + +Once positioned, we will have a series of commands for working on the file tree. The most common commands are: + +- > and < to navigate up and down the tree (mouse support for navigation is also active) +- Enter or o to open the file in the buffer, subsequent openings of other files will always be done on the same buffer in a new tab but placed in the backgroud, to change the default behavior you can use the following keys: + - CTRL v to open the new file in the vertically divided buffer + - CTRL x to open the new file in the horizontally split buffer + - CTRL t to open the new file in a new tab in a new buffer +- R to refresh files +- a to create a new file +- r to rename a file +- d to delete a file +- q to close the explorer + +All available commands can be viewed on [this page](https://github.com/kyazdani42/nvim-tree.lua/blob/master/doc/nvim-tree-lua.txt) of the NvimTree project in section *6. Mappings*. + +Now that we have explored the interface components we can move on to using NvChad. diff --git a/docs/books/nvchad/nvchad_ui/using_nvchad.md b/docs/books/nvchad/nvchad_ui/using_nvchad.md new file mode 100644 index 0000000000..699abbf3a1 --- /dev/null +++ b/docs/books/nvchad/nvchad_ui/using_nvchad.md @@ -0,0 +1,85 @@ +--- +title: Using NvChad +author: Franco Colussi +contributors: Steven Spencer +tested with: 8.6, 9.0 +tags: + - nvchad + - coding + - editor +--- + +# Editing with NvChad + +This chapter will introduce some NvChad-specific commands and some standard Neovim (vim) commands. NvChad commands are set in the `nvim/lua/core/mapping.lua` file and allow keys to be used to execute sometimes very long composite commands. All sequences are started with a primary key followed by an option. The four main keys are: + +- C = Ctrl +- leader = Space +- A = Alt +- S = shift + +## Open a file + +To open a file in our editor we can use various methods. We can simply start from the command line by indicating the file name with: + +```bash +nvim /path/to/the/file +``` + +or open the editor with the `nvim` command. + +If we use the latter method we have several possibilities. We can open the file in the buffer with the command `:e` (edit) followed by the path or by having the command followed by the Tab key. This will show us all the available files and folders starting from the root of the project. It is good to remember that when we use the Tab key in file opening commands, we can select the file from a convenient drop-down menu. Once this drop-down menu is open, we continue to navigate within it by repeated use of the Tab key. + +![Command :e + TAB](../images/e_tab_command.png) + +In case we just want to view the file without the ability to edit it we can use the `:view` command. This will open the file in read-only mode avoiding the possibility of making unwanted changes to critical files. We can also open a file side by side with the command ` :split ` or open it in a new *tab* with the command ` :tabedit `. + +![Vsplit Open](../images/vsplit_open.png) + +Thanks to the work done by the developers of NvChad we are provided with an additional way to open a file which is to use the *nvim-telescope/telescope.nvim* plugin. This plugin, when used in combination with *RipGrep*, allows us to search for the file to be opened in interactive mode. By typing the initial characters of the file we are looking for, the plugin will delete all non-matching files and present us with only those that match our search. This allows for a very smooth search and open process. + +![ff](../images/leader_ff.png) + +## Working with the Editor + +Once the file is open we can start editing it. To do this we need to switch to INSERT mode which is activated by pressing the i (insert) key. The mode indicator in the Statusline should change from NORMAL to INSERT, and the cursor placed in the buffer should also change from a colored rectangle to a `|` pipe. Now all the characters we type are inserted into the document starting from the position of the cursor. To move the cursor in INSERT mode the Nvchad developers have set up some convenient mappings which are: + +- Ctrl + b to go to the beginning of the line +- Ctrl + e to go to the end of the line +- Ctrl + h to move one character to the left +- Ctrl + l to move one character to the right +- Ctrl + j to go to the next line +- Ctrl + k to go to the previous line + +Learning all the combinations takes some time but once acquired they will make navigation very fast. For example, if we want to edit the end of the next line to where the cursor is positioned we can get to the end of the current line with Ctrl + e and then get to the next one with a Ctrl + j and already be in position to add the changes. + +Navigation in the document can also be done using the arrow keys on the keyboard, or the mouse. + +### Text Selection + +Text selection can also be done with the mouse and is very convenient, but for this chapter we will use the traditional method. + +To select text we need to enter the VISUAL mode. To do this we must first exit the insert mode and switch to normal mode, which is done with the ESC key. Once we place the cursor at the beginning of the part we want to select, we use the keys Ctrl + v to enter the V-BLOC (Visual Block) mode. Now moving with the cursor we will see that our selection will be highlighted. At this point we can work on the selected part. If we want to copy the selection to the clipboard we will use the y key. If we want to delete it the d key. Once the operation is done, the text will no longer be highlighted. For an overview of all the operations that can be performed in Visual Mode you can consult the help directly from the editor with `:help Visual-Mode`. + +![Help Visual Mode](../images/help_visual_mode.png) + +### Text search + +To search, the slash character / followed by the search key `/search_key` is used, which highlights all occurrences found. To move to the next one, the combination / + Enter is used. To move to the previous one ? + Enter. Once the changes are finished, the highlighting is removed with the command `:noh` (no highlight). + +![Find Command](../images/find_command.png) + +Searches can be even more complex than the one illustrated above; wildcards, counters, and other options can be used. The help `:help /` can be used to consult the options. + +## Saving the Document + +Once the file is created or modified it is saved with the command `:w` (write) which will save the file with the current name in the location it is in, in case you want to save the file with another name or in another location just have the command follow the save path: + +```text +:w /path/to/new/file_or_position +``` + +To save and simultaneously close the editor, the command `:wq` (write - quit) is used. + +In this chapter we have introduced you to the editor. There are many more advanced features than those described here. These features can be consulted on the [Neovim help](https://neovim.io/doc/user/) page or by typing in the editor `:help`. +