diff --git a/README.md b/README.md index 9119d4fc..419b8ca3 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,10 @@ Wallpapers: https://github.com/ryan4yin/wallpapers ![](./_img/i3_2023-07-29_1.webp) ![](./_img/i3_2023-07-29_2.webp) +## Neovim + +See [./home/base/desktop/neovim/README.md](./home/base/desktop/neovim/README.md) for details. + ## Hosts See [./hosts](./hosts) for details. diff --git a/home/base/desktop/neovim/README.md b/home/base/desktop/neovim/README.md index 76cebf40..7a129462 100644 --- a/home/base/desktop/neovim/README.md +++ b/home/base/desktop/neovim/README.md @@ -1,7 +1,170 @@ -# AstroNvim +# AstroNvim Configuration and Shortcuts My Neovim config based on [AstroNvim](https://github.com/AstroNvim/AstroNvim). +This document outlines the configuration and dependencies of AstroNvim, along with various shortcuts and commands for efficient usage. + ## Screenshots ![](/_img/astronvim_2023-07-13_00-39.webp) + +## Related Folders + +- Nvim's config: `~/.config/nvim` +- AstroNvim's user configuration: `$XDG_CONFIG_HOME/astronvim/lua/user` +- Plugins installation directory (by lazy.nvim): `~/.local/share/nvim/` + +For more details, visit the [AstroNvim website](https://astronvim.com/). + +## Visual Modes + +| Action | Shortcut | +| ------------------------ | ---------------------------------------- | +| Toggle visual mode | `v` | +| Toggle visual block mode | ` + v` (select a block vertically) | + +## Text Manipulation + +- Add at the end of multiple lines: `:normal A` + + - Execute `A` on each line + - `A` appends text at the end of each line + - Select lines using visual mode first + +- Add at the end of visual block: `:A` + - Append text at the end of each line in the selected block(visual block mode) + - If position exceeds line end, neovim adds spaces automatically + +## Commands & Shortcuts + +| Action | Shortcut | +| ----------------------------- | -------------- | +| Learn Neovim's Basics | `:Tutor` | +| Open file explorer | ` + e` | +| Focus Neotree to current file | ` + o` | +| Floating Terminal | ` + tf` | +| Horizontal Split Terminal | ` + th` | +| Vertical Split Terminal | ` + tv` | +| Open IPython REPL | ` + tp` | +| Toggle line wrap | ` + uw` | +| Show line diagnostics | `gl` | +| Show function/variable info | `K` | +| Go to definition | `gd` | +| References of a symbol | `gr` | + +## Window Navigation + +- Switch between windows: ` + h/j/k/l` +- Resize windows: ` + Up/Down/Left/Right` + - Note: On macOS, conflicts with system shortcuts + - Disable in System Preferences -> Keyboard -> Shortcuts -> Mission Control + +## Splitting and Buffers + +| Action | Shortcut | +| --------------------- | ------------- | --- | +| Horizontal Split | `\` | +| Vertical Split | ` | ` | +| Next Buffer (Tab) | `]b` | +| Previous Buffer (Tab) | `[b` | +| Close Buffer | ` + c` | + +## Editing and Formatting + +| Action | Shortcut | +| ----------------------------------------------------- | -------------- | +| Toggle buffer auto formatting | ` + uf` | +| Format Document | ` + lf` | +| Code Actions | ` + la` | +| Rename | ` + lr` | +| Opening LSP symbols | ` + lS` | +| Comment Line(support multiple lines) | ` + /` | +| Open filepath/URL at cursor(neovim's builtin command) | `gx` | +| Find files by name (fzf) | ` + ff` | +| Grep string in files (ripgrep) | ` + fw` | + +## Sessions + +| Action | Shortcut | +| ------------------------------ | -------------- | +| Save Session | ` + Ss` | +| Last Session | ` + Sl` | +| Delete Session | ` + Sd` | +| Search Session | ` + Sf` | +| Load Current Directory Session | ` + S.` | + +## Debugging + +Press ` + D` to view available bindings and options. + +## Find and Replace + +| Action | Command | +| ------------------------ | ----------------------------------- | +| Replace in selected area | `:s/old/new/g` | +| Replace in current line | Same as above | +| Replace in whole file | `:% s/old/new/g` | +| Replace with regex | `:% s@\vhttp://(\w+)@https://\1@gc` | + +1. `\v` means means that in the regex pattern after it can be used without backslash escaping(similar to python's raw string). +2. `\1` means the first matched group in the pattern. + +## Replace in the specific lines + +| Action | Command | +| ----------------------------------------- | -------------------------------------- | +| From the 10th line to the end of the file | `:10,$ s/old/new/g` or `:10,$ s@^@#@g` | +| From the 10th line to the 20th line | `:10,20 s/old/new/g` | + +The postfix(flags) in the above commands: + +1. `g` means replace all the matched strings in the current line/file. +2. `c` means ask for confirmation before replacing. +3. `i` means ignore case. + +## Search and Replace Globally + +| Description | Shortcut | +| ------------------------------------- | ---------------------------------------------------------------- | +| Open Spectre search and replace panel | ` + ss` | +| Search and replace in command line | `find -name "*.nix" \| sad '' '' \| delta` | + +## Surrounding Characters + +| Action | Shortcut | Description | +| ----------------------------- | -------- | ---------------------------------------------- | +| Add surrounding characters | `ysiw'` | Add `'` around the word under cursor | +| Delete surrounding characters | `ds'` | Delete `'` around the word under cursor | +| Change surrounding characters | `cs'"` | Change `'` to `"` around the word under cursor | + +## Text Manipulation + +| Action | | +| -------------------------------------- | ------------- | +| Join Selection of Lines With Space | `:join` | +| Join without spaces | `:join!` | +| Join with LSP intelligence(treesj) | ` + j` | +| Split Line into Multiple Lines(treesj) | ` + s` | + +## Convert Text Case + +| Action | | +| -------------------- | --- | +| Toggle text's case | `~` | +| Convert to uppercase | `U` | +| Convert to lowercase | `u` | + +## Miscellaneous + +| Action | | +| ---------------------------- | -------------------------------------------- | +| Save selected text to a file | `:w filename` (Will show `:'<,'>w filename`) | +| Show all Yank History | `: + yh` | +| Show undo history | `: + uh` | + +## Additional Resources + +For more detailed information and advanced usage, refer to: + +1. [AstroNvim walkthrough](https://astronvim.com/Basic%20Usage/walkthrough) +2. [./astronvim_user/mapping.lua`](./astronvim_user/mappings.lua) diff --git a/home/base/desktop/neovim/default.nix b/home/base/desktop/neovim/default.nix index 573426fb..4a7da5d6 100644 --- a/home/base/desktop/neovim/default.nix +++ b/home/base/desktop/neovim/default.nix @@ -5,112 +5,7 @@ }: ############################################################################### # -# AstroNvim's configuration and all its dependencies -# -# Related folders: -# nvim's config: `~/.config/nvim` -# astronvim's user configuration: `$XDG_CONFIG_HOME/astronvim/lua/user` -# all plugins will be installed into(by lazy.nvim): `~/.local/share/nvim/` -# -# For details: https://astronvim.com/ -# -# Toggle visual mode: `v` -# Toggle visual block mode: ` + v` (select a block(vertically) of text) -# -# Add at the end of Multiple line: `:normal A` -# Note that `:normal` execute `A` on each line. -# `A` means append text at the end of the line. -# You need to select the lines via visual mode first. -# -# Add at the end of the visual block: `:A` -# You need to select the block via visual block mode first. -# And then this command will append text at the end of the block on each line. -# If the position exceeds the end of the line, neovim will automatically add spaces -# -# Commands & shortcuts in AstroNvim -# Learn Neovim's Basics: `:Tutor` -# Opening file explorer: ` + e` -# Focus Neotree to current file: ` + o` -# Floating Terminal: ` + tf` -# Horizontal Split Terminal: ` + th` -# Vertical Split Terminal: ` + tv` -# Open IPython REPL: ` + tp` -# Toggle line wrap: ` + uw` -# Show line diagnostics: `gl` -# Show function/variable info: `K` -# Go to definition: `gd` -# References of a symbol: `gr` -# -# Switching between windows: ` + h/j/k/l` -# Resizing windows: ` + Up/Down/Left/Right` -# Note that on macOS, this is conflict with system's default shortcuts. -# You need disable them in System Preferences -> Keyboard -> Shortcuts -> Mission Control. -# Horizontal Split: `\` -# Vertical Split: `|` -# Next Buffer(Tab): `]b` -# Previous Buffer(Tab): `[b` -# Close Buffer: ` + c` -# -# Toggle buffer auto formatting: ` + uf` -# Format Document: ` + lf` -# Code Actions: ` + la` -# Rename: ` + lr` -# Opening LSP symbols: ` + lS` -# Comment Line: ` + /` -# Can be used in visual mode -# Open filepath/URL at cursor: `gx` -# This is a neovim builtin command -# Find files by name(fzf): ` + ff` -# Grep string in files(repgrep): ` + fw` -# -# Save Session: ` + Ss` -# Last Session: ` + Sl` -# Delete Session: ` + Sd` -# Search Session: ` + Sf` -# Load Current Directory Session:` + S.` -# -# Debugging: press ` + D` to see the available bindings and options. -# -# Replace in the selected area: `:s/old/new/g` (will show `:'<,'>s/old/new/g`) -# Replace in the current line: The same as above -# Replace in the whole file: `:% s/old/new/g` -# Replace with regex: `:% s@\vhttp://(\w+)@https://\1@gc` -# 1. `\v` means means that in the regex pattern after it can be used without backslash escaping(similar to python's raw string). -# 2. `\1` means the first matched group in the pattern. -# Replace in the specific lines: -# 1. From the 10th line to the end of the file: `:10,$ s/old/new/g` -# or `:10,$ s@^@#@g` -# 2. From the 10th line to the 20th line: `:10,20 s/old/new/g` -# -# The postfix(flgas) in the above commands: -# 1. `g` means replace all the matched strings in the current line/file. -# 2. `c` means ask for confirmation before replacing. -# 3. `i` means ignore case. -# -# Seach and replace globally: -# 1. Open Spectre search and replace panel: ` + ss` -# 2. search and replace in command line: `find -name "*.nix" | sad '' '' | delta` -# -# Add surrounding characters: `ysiw'` (will add `'` around the word under cursor) -# Delete surrounding characters: `ds'` (will delete `'` around the word under cursor) -# Change surrounding characters: `cs'"` (will change `'` to `"` around the word under cursor) -# -# Joining a Selection of Lines With Space: `:join` -# Joining without spaces: `:join!` -# Join with lsp intellegence(treesj): ` + j` -# Splitting a Line into Multiple Lines(treesj): ` + s` -# -# Toggle text's case: `~` -# Convert to uppercase: `U` -# Convert to lowercase: `u` -# -# Save the selected text to a file: `:w filename` (will show `:'<,'>w filename`) -# Show all Yank History: `: + yh` -# Show undo history: `: + uh` -# -# ...... -# See https://astronvim.com/Basic%20Usage/walkthrough -# And ./astronvim_user/mapping.lua +# AstroNvim's configuration and all its dependencies(lsp, formatter, etc.) # #e############################################################################# {