This is a neovim configuration as a js/golang dev's daily driver.
~/.config/nvim
-
Install the latest Neovim (0.9+) and make sure
gitis available. -
Clone this repo into
~/.config/nvim. -
Open Neovim once; lazy.nvim bootstraps itself. Run
:Lazy syncto install/update plugins. -
You may need extra tooling: LSP servers (
gopls,tsserver,efm-language-server,rust-analyzer),eslint_d, Tree-sitter parsers, nerd fonts for icons,ctags, andbatfor fzf previews.
~/.local/share/nvim/plugged
Plugins are managed with lazy.nvim in lua/plugins/init.lua. Core options live in lua/config/* and everything else sits in lua/my-lua-configs/.
Common commands:
:Lazy sync- install or update plugins:Lazy clean- remove unused plugins:Lazy profile- inspect startup cost
After a long time usage of YouCompleteMe, I switched to coc.nvim. With the great async feature of neovim, it works like a charm especially when most mainstream languages have great language server protocol supports(Thank you Microsoft, sincerely).
I'm using nvim-cmp now, which works out nicely but as the author said, it's still in active development.
You might need to install additional go packages to use full feature of vim-go. Please refer to the instructions.
A few useful shortcuts I use every day:
* <F12>: Show definition in a float window
* <gd>: go to definition
* >>/<<: Go to next function
* :GoImports: make import a bit more straightforward
* :GoAddTags json bson: you will love this
In my work we use two spaces as indentation, so feel free to change it if you prefer other indentation.
Not all plugins I installed are required for JS development but I found it works for me.
Sometimes syntax highlighting has issues with complicated string templates.
The TS/JS LSP works like a charm, the only shortcuts I use in my daily development is
* <F12>: Show definition in a float window
* <gd>: go to definition
One hassle I find after switching to native lsp is linting on jsx, it seems to me that efm + eslint_d works alright, at least almost the same good as vscode.
I use <space> as leader key. The handy position makes it easy to reach and encourages me to use it more.
I map jj as <esc>. Not only because of the stupid touchbar (Apple gave it back now), but make normal mode more accessible for me, which I think is a good practice for every vimmer.
I use fzf as native app and install the fzf-vim plugin wrapping it by vim. Also I installed bat to provide file preview with syntax highlighting.
P.S. to use bat in ubuntu, because it's batcat in repo so you need to relink it somewhere and export it, what I did is like this:
ln -s /usr/bin/batcat ~/bin/batand append ~/bin to PATH
Text fuzzy search requires ripgrep
Functions:
1. <leader>f: text fuzzy search
Now I only use telescope for fuzzy global text search.
The new fav of the community, probaly one of the best plugins you can have for nvim. I use Telescope and Telescope-fzf-native to work together on sorting, which will make telescope supports fuzzy search on a lot of things. But not all of them. So I still keep fzf for text fuzzy search in a project.
Some useful ones I use daily
nnoremap <C-p> <cmd>Telescope find_files<cr>
nnoremap <C-g> <cmd>Telescope git_status<cr>
nnoremap <C-e> <cmd>Telescope buffers<cr>
nnoremap <C-t> <cmd>Telescope tags<cr>
Another one I'll use alongside with <leader>f is :Telescope live_grep which is precise search, like vscode one everyone likes.
For js/jsx/tsx development, sometimes I find it handy to do :Telescope diagnostics. It's nice to have it all at one single place and you can check.
I'm used to work with git in commandline. But I found it handy to access some git info/actions within the editor.
1. :GDiff - diff the current file (fugitive)
2. :GStatus - extended interactive ui of git status (fugitive)
3. ~~<leader>gm - show git message of the current line (git-messenger)~~ (UPDATE: I use `:GV`/`:GV!`/`:GV?` now)
4. <right><right>/<left><left> - next/previous git hunk (fugitive)
5. GBrowse/GBrowse! - it will open remote origin in your browser or copy the link to your clipboard
6. GBlame - time to blame your colleagues!
the status in gutter is provided by vim-gitgutter.
Since I use I use Telescope now for buffer, files etc., but this still works.fzf/fzf-vim for most of my navigation, the configuration is part of the fzf-vim.
1. <ctrl>-v: vertical split open from fzf/telescope window
2. <ctrl>-x: horizontal split open from fzf/telescope window
3. <ctrl>-t: open from fzf/telescope window in another tab
For navigation:
" tab move
nnoremap H gT
nnoremap L gt
" easier split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
And pane resize:
" easier split vertical resize
nnoremap <S-Up> <C-w>+
nnoremap <S-Down> <C-w>-
nnoremap <S-Right> <C-w>>
nnoremap <S-Left> <C-w><
Also I use nvim-tree as file explorer, I use NerdTree<ctrl>-n to toggle it and keep default key bindings.
Sometimes, just sometimes, I use terminal in neovim. <C-t> to toggle it. (P.S. :q will close the buffer and make the terminal not reusable)
Floaterm is simply better and faster. It's really good when you want to change code and run watcher at the same time, just like vscode built-in terminal.
I configured according to here: https://github.com/neovim/neovim/wiki/FAQ#how-to-use-the-windows-clipboard-from-wsl
Just use it! This is just how good nvim is, isn't it?
Since I'm using nvim-cmp so I just use the tabnine source provider for it. I also tried GitHub Copilot - it's really impressive but I don't like the lag. Sometimes I just want to tab indent and then it autocomplete a bunch code - tho the result is impressive but it's not really needed when I know what I'm gonna do. Tabnine is good enough.
I'm using Copilot now.
Lua is just faster. The config now runs fully from init.lua with lazy-loaded plugins managed by lazy.nvim.
MIT