4.3 KiB
Initialization (init.lua)
-
Create
init.lua:touch ~/.config/nvim/init.luaThis command creates a new file named
init.luain your Neovim configuration directory, which will store your custom settings. -
Basic Settings in
init.lua:vim.o.number = true -- Enable line numbers vim.cmd('syntax enable') -- Enable syntax highlightingThese lines set basic Neovim options: enabling line numbers and syntax highlighting, which are essential for better readability and coding efficiency.
Modular Setup
-
Create Modules:
- Make Lua files like
keymaps.lua,plugins.luain~/.config/nvim/lua/. This modular approach allows you to organize your configuration efficiently. For example,keymaps.luacan hold all your keybindings, whileplugins.luacan manage your plugin configurations.
- Make Lua files like
-
Include Modules in
init.lua:require('keymaps') require('plugins')These lines in your
init.luafile load the modules you created. It keeps your main configuration file clean and your settings organized.
Plugin Management
-
Install Packer:
git clone --depth 1 https://github.com/wbthomason/packer.nvim\ ~/.local/share/nvim/site/pack/packer/start/packer.nvimPacker is a plugin manager for Neovim. This command installs Packer, allowing you to easily add, update, and manage your Neovim plugins.
-
Define Plugins in
plugins.lua:use {'neovim/nvim-lspconfig', config = function() require('lsp') end}Here, you're telling Packer to use the
nvim-lspconfigplugin. This plugin is used for configuring LSP (Language Server Protocol), which provides features like auto-completion, code navigation, and syntax checking.
Key Mappings (keymaps.lua)
-
Global Mappings Example:
vim.api.nvim_set_keymap('n', '<Leader>f', ':Telescope find_files<CR>', {noremap = true})This code maps
<Leader>ftoTelescope find_filesin normal mode, enabling you to quickly search for files. -
Mode-Specific Mappings Example:
vim.api.nvim_set_keymap('i', 'jj', '<Esc>', {noremap = true})This snippet maps
jjto<Esc>in insert mode, providing a quick way to exit insert mode.
LSP and Autocomplete (lsp.lua)
-
Configure LSP Client:
require'lspconfig'.pyright.setup{}This line sets up an LSP client for Python using
pyright. LSPs are crucial for advanced coding assistance like error detection and code suggestions. -
Setup Autocomplete:
- Use a plugin like
nvim-compefor autocomplete. This plugin offers intelligent code completion, which is a huge productivity boost.
- Use a plugin like
Tmux Configuration
Basic Configuration (tmux.conf)
-
Create/Edit
.tmux.conf:touch ~/.tmux.confThis creates or edits your Tmux configuration file, where you can customize Tmux to your liking.
-
Set Global Options in
.tmux.conf:set-option -g prefix C-a set -g status-right 'Battery: #{battery_percentage}'These commands change the default prefix key to
Ctrl-aand add a battery status indicator to the right side of the status line.
Lua Scripting for Tmux
- Write Lua Scripts to generate dynamic Tmux commands.
- Run Scripts to update your
.tmux.conf. For example, a Lua script can be written to adjust the status line based on time of day or system status.
Key Bindings and Session Management
- Add Key Bindings in
.tmux.conffor efficient navigation. For instance, binding keys for splitting panes or switching between them can significantly speed up your workflow. - Script Session Setups: Create scripts for predefined layouts and windows, enabling you to launch complex Tmux environments with a single command.
Status Line Customization
- Use Lua Scripts for dynamic status line updates in Tmux, like changing colors or displaying contextual information.
Performance and Testing
- Regularly Review your configurations for performance impacts. This includes monitoring load times and responsiveness.
- Test Config ChatGPT urations in a separate tmux session to ensure your changes work as expected without disrupting your current workflow.
Troubleshooting and FAQs
- Include a Section: Adding a troubleshooting section or an FAQ can help users resolve common issues they might encounter while configuring Neovim or Tmux.