# My neovim workflow ![nvim-000](https://raw.githubusercontent.com/haunt98/posts-images/main/nvim-000.jxl) All configs are in [my dotfiles](https://github.com/haunt98/dotfiles). ## Trick or treat Search current word: `*` Search multiple words: ```vim :/\vword1|word2|word3 ``` Replace word: ```vim :%s/word1/word2/g ``` Delete all lines contain word: ```vim :g/word/d ``` Delete all lines **not** contain word: ```vim :g!/word/d :v/word/d ``` Play macro `a` (after selecting lines): ```vim :norm! @a ``` Sort lines (after selecting lines): ```vim :sort -u ``` Reverse lines (after selcting lines): ```vim :!tail -r ``` Column-ize lines: ```vim :!column -t ``` ## Jumpo Basic: - `gg`: first line - `G`: last line - `0`: first character of line - `$`: last character of line - `w`, `b`: word forward/backward - `e`, `ge`: end of word current/before - `W`, `B`: WORD (word with special char) forward/backward - `E`, `gE`: end of WORD current/before - `f{char}`, `F{char}`: find forward/backward character - `%`: jump between matching pair of `()`, `[]`, `{}` Advance: - `CTRL-O`, `CTRL-I`: cursor position backward/forward - `{`, `}`: paragraph backward/forward - `H`: top of screen - `M`: middle of screen - `L`: bottom of screen - `CTRL-]`, `CTRL-T`: jump to tag/jump back from tag - Support jump to Go definition with [fatih/vim-go](https://github.com/fatih/vim-go). ## Keymap Use both `\` and `;` as leader key: ```lua vim.keymap.set("n", ";", "", { remap = true }) vim.keymap.set("n", "'", "", { remap = true }) ``` Ground rules: - `` prefix: prefer global keymap - `` prefix: prefer lsp keymap, for coding of course :D - Native neovim: - `gcc`: comment/uncomment current line - `gc`: comment/uncomment selected lines - `gx`: open file/url under cursor - `Q`, `@`: execute last macro - `]d`, `[d`: next/previous diagnostic - `K`: hover - Black hole register: - `d`: `d` without yank - `c`: `c` without yank - `x`: `x` without yank - With [ibhagwan/fzf-lua](https://github.com/ibhagwan/fzf-lua): - `f`: find files - `l`: find lines - `rg`: grep files - `g`: git status - With [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) helps: - `s`: list lsp symbols - `r`, `gr`: list references - `i`, `gi`: list implementation - `ca`: list code action - With [hrsh7th/nvim-cmp](https://github.com/hrsh7th/nvim-cmp): - ``: trigger completion - With [nvim-tree/nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua), inside nvim-tree: - ``: toggle - `n`: locate file - `a`: create - `d`: delete - `r`: rename - `x`: cut - `c`: copy - `p`: paste - `U`: toggle hidden - With [lewis6991/gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim): - `]c`, `[c`: next/previous git change - With [tpope/vim-projectionist](https://github.com/tpope/vim-projectionist) - `:A`: open alternate file - With [echasnovski/mini.nvim](https://github.com/echasnovski/mini.nvim) - With mini-surround - `sa`: add surround - `sd`: delete surround - `sr`: replace surround - With [stevearc/conform.nvim](https://github.com/stevearc/conform.nvim): - `f`: format code - With [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig): - `e`: current diagnostic - `lr`: restart lsp server - `gd`: go to definition - `k`, `gk`: hover - ``: rename - With [github/copilot.vim](https://github.com/github/copilot.vim): - ``: completion, replace `Tab` ## References / Thanks - vim docs: - [Seven habits of effective text editing 2.0](https://moolenaar.net/habits_2007.pdf) - neovim official docs: - [neovim Motion](https://neovim.io/doc/user/motion.html) - [neovim Tagsrch](http://neovim.io/doc/user/tagsrch.html) - [neovim Lua-guide](https://neovim.io/doc/user/lua-guide.html) - Hidden gem: - [Vim Tips (Revisited)](https://bluz71.github.io/2021/09/10/vim-tips-revisited.html) - [How do I reverse selected lines order in Vim?](https://superuser.com/a/189956) - [Use Vim macros to automate frequent tasks](https://www.redhat.com/sysadmin/use-vim-macros) - [3 Vim commands for blazingly fast navigation between brackets ⚡](https://dev.to/m4xshen/3-vim-commands-for-blazingly-fast-navigation-between-brackets-55kc)