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

72 lines
2.3 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).
Use both `\` and `;` as leader key.
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
Jump advance:
- `CTRL-O`, `CTRL-I`: cursor position backward/forward
- : jump forward cursor position
- `(`, `)`: 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>")
vim.keymap.set("n", "<leader>rg", ":Rg<CR>")
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>")
vim.keymap.set("n", "<F2>", ":GoRename<CR>")
vim.keymap.set("n", "<leader>gf", ":GoFillStruct<CR>:w<CR>")
vim.keymap.set("n", "<leader>gat", ":GoAlternate<CR>")
vim.keymap.set("n", "<leader>gt", ":GoTest<CR>")
vim.keymap.set("n", "<leader>gr", ":GoReferrers<CR>")
vim.keymap.set("n", "<leader>gcv", ":GoCoverage<CR>")
vim.keymap.set("n", "<leader>gdd", ":GoDeclsDir<CR>")
```
- With [echasnovski/mini.nvim mini-comment](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-comment.md)
- `gcc`: comment/uncomment current line
- `gc`: comment/uncomment selected lines
- With [echasnovski/mini.nvim mini-bracketed](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-bracketed.md)
- `[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)
2023-06-15 19:06:11 +00:00
- With [airblade/vim-gitgutter](https://github.com/airblade/vim-gitgutter):
- `]c`, `[c`: next/previous git change
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)