posts-go/posts/2023-05-03-neovim.md

95 lines
2.7 KiB
Markdown
Raw Normal View History

2023-05-02 17:42:11 +00:00
# My neovim workflow
2023-06-10 04:57:15 +00:00
![nvim-000](https://raw.githubusercontent.com/haunt98/posts-images/main/nvim-000.png)
2023-06-10 03:50:39 +00:00
All configs are in [my dotfiles](https://github.com/haunt98/dotfiles).
2023-06-29 10:29:18 +00:00
Use both `\` and `;` as leader key:
```lua
vim.keymap.set("n", ";", "<leader>", { remap = true })
2023-07-03 07:07:16 +00:00
vim.keymap.set("n", "'", "<leader>", { remap = true })
2023-06-29 10:29:18 +00:00
```
2023-06-10 03:50:39 +00:00
2023-05-02 17:42:11 +00:00
Search multiple words:
2023-06-10 03:50:39 +00:00
```vim
2023-05-02 17:42:11 +00:00
:/\vword1|word2|word3
```
2023-06-10 03:50:39 +00:00
Replace word:
```vim
:%s/word1/word2/g
```
Jump basic:
- `gg`: first line
- `G`: last line
- `0`: first character of line
- `$`: last character of line
- `w`, `b`: word forward/backward
2023-06-15 19:17:40 +00:00
- `e`, `ge`: end of word current/before
- `W`, `B`: WORD (word with special char) forward/backward
- `E`, `gE`: end of WORD current/before
2023-06-24 17:18:07 +00:00
- `f{char}`, `F{char}`: find forward/backward character
2023-06-10 03:50:39 +00:00
Jump advance:
- `CTRL-O`, `CTRL-I`: cursor position backward/forward
- `(`, `)`: sentence 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
2023-06-10 07:15:38 +00:00
- Support jump to Go definition with [fatih/vim-go](https://github.com/fatih/vim-go).
2023-06-10 03:50:39 +00:00
Keymap for plugin (sync with dotfiles):
```lua
vim.keymap.set("n", "<leader>f", ":FZF<CR>")
2023-06-23 07:40:04 +00:00
vim.keymap.set("n", "<leader>rg", ":FZFRg<CR>")
vim.keymap.set("n", "<leader>cm", ":FZFCommands<CR>")
2023-06-10 03:50:39 +00:00
vim.keymap.set("n", "<C-n>", ":NvimTreeToggle<CR>")
vim.keymap.set("n", "<leader>n", ":NvimTreeFindFile<CR>")
vim.keymap.set("n", "<leader>tr", ":lua MiniTrailspace.trim()<CR>")
```
2023-06-23 07:40:04 +00:00
- With [nvim-tree/nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua), inside nvim-tree:
2023-06-24 14:57:22 +00:00
- `a`: create
2023-06-23 07:40:04 +00:00
- `d`: delete
- `r`: rename
- `x`: cut
- `c`: copy
- `p`: paste
2023-06-24 15:24:39 +00:00
- `U`: toggle hidden
2023-06-23 07:40:04 +00:00
- With [lewis6991/gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim):
2023-06-15 19:06:11 +00:00
- `]c`, `[c`: next/previous git change
2023-06-23 07:40:04 +00:00
- With [echasnovski/mini.nvim](https://github.com/echasnovski/mini.nvim)
- With mini-bracketed
- `[b`, `]b`: buffer backward/forward
- `[T`, `]T`, `[t`, `]t`: tree-sitter backward/forward
- Support more languages with [nvim-treesitter/nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
- With mini-comment
- `gcc`: comment/uncomment current line
- `gc`: comment/uncomment selected lines
- With mini-surround
- `sa`: add surround
- `sd`: delete surround
- `sr`: replace surround
2023-06-29 10:29:18 +00:00
- With [neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig)
- `gd`: go to definition
- `gr`: go to references
- `K`: hover
- `<F2>`: rename
2023-06-30 17:28:45 +00:00
- `<space>f`: format
- `<space>ca`: code action
2023-06-10 03:50:39 +00:00
## Reference
- [neovim Motion](https://neovim.io/doc/user/motion.html)
- [neovim Tagsrch](http://neovim.io/doc/user/tagsrch.html)
2023-07-01 09:06:30 +00:00
- [neovim Lua-guide](https://neovim.io/doc/user/lua-guide.html)