Hi, it's Takuya here.
As you may know, I mainly use Neovim to code my app called Inkdrop, a cross-platform Markdown note-taking app.
It's built with Electron for desktop and React Native for mobile platforms.
It's been 1 year since I last posted my Neovim setup.
Neovim and its plugins have been evolved so well.
So, I'd like to share my latest setup for coding React and TypeScript based apps.
The main difference is that the config files are now written in Lua.
I switched from vim-plug to Packer.
I also made a tutorial video on how to set up Neovim from scratch on a new M2 MacBook Air.
If you have your own dotfiles already, you can cherry-pick my config.
I hope you enjoy it!
iTerm2 is a fast terminal emulator for macOS.
Install one of Nerd Fonts for displaying fancy glyphs on your terminal.
My current choice is Hack.
And use it on your terminal app. For example, on iTerm2:
Install Neovim via Homebrew
brew install neovim
Directory structure
Neovim conforms XDG Base Directory structure. Here is my config file structure:
Then, make ./.config/nvim/lua/plugins.lua like so:
localstatus,packer=pcall(require,"packer")if(notstatus)thenprint("Packer is not installed")returnendvim.cmd[[packadd packer.nvim]]packer.startup(function(use)use'wbthomason/packer.nvim'-- Your plugins go hereend)
Neovim has a built-in LSP support.
You can easily configure it by using neovim/nvim-lspconfig.
For example, to enable typescript language server on Neovim:
localstatus,nvim_lsp=pcall(require,"lspconfig")if(notstatus)thenreturnendlocalprotocol=require('vim.lsp.protocol')localon_attach=function(client,bufnr)-- format on saveifclient.server_capabilities.documentFormattingProviderthenvim.api.nvim_create_autocmd("BufWritePre",{group=vim.api.nvim_create_augroup("Format",{clear=true}),buffer=bufnr,callback=function()vim.lsp.buf.formatting_seq_sync()end})endend-- TypeScriptnvim_lsp.tsserver.setup{on_attach=on_attach,filetypes={"typescript","typescriptreact","typescript.tsx"},cmd={"typescript-language-server","--stdio"}}
Don't forget to install typescript language server itself:
npm i -g typescript-language-server
Auto-completion: Lspkind and cmp
To get LSP-aware auto-completion feature with fancy pictograms, I use the following plugins:
localstatus,cmp=pcall(require,"cmp")if(notstatus)thenreturnendlocallspkind=require'lspkind'cmp.setup({snippet={expand=function(args)require('luasnip').lsp_expand(args.body)end,},mapping=cmp.mapping.preset.insert({['<C-d>']=cmp.mapping.scroll_docs(-4),['<C-f>']=cmp.mapping.scroll_docs(4),['<C-Space>']=cmp.mapping.complete(),['<C-e>']=cmp.mapping.close(),['<CR>']=cmp.mapping.confirm({behavior=cmp.ConfirmBehavior.Replace,select=true}),}),sources=cmp.config.sources({{name='nvim_lsp'},{name='buffer'},}),formatting={format=lspkind.cmp_format({with_text=false,maxwidth=50})}})vim.cmd[[
set completeopt=menuone,noinsert,noselect
highlight! default link CmpItemKind CmpItemMenuDefault
]]
Syntax highlightings: Treesitter
Treesitter is a popular language parser for syntax highlightings.
First, install it:
It’s so useful because you can search files while viewing the content of the files without actually opening them. It supports various sources like Vim, files, Git, LSP, and Treesitter. Check out the showcase of Telescope.
telescope.setup{defaults={mappings={n={["q"]=actions.close},},},extensions={file_browser={theme="dropdown",-- disables netrw and use telescope-file-browser in its placehijack_netrw=true,mappings={-- your custom insert mode mappings["i"]={["<C-w>"]=function()vim.cmd('normal vbd')end,},["n"]={-- your custom normal mode mappings["N"]=fb_actions.create,["h"]=fb_actions.goto_parent_dir,["/"]=function()vim.cmd('startinsert')end},},},},}telescope.load_extension("file_browser")vim.keymap.set("n","sf",function()telescope.extensions.file_browser.file_browser({path="%:p:h",cwd=telescope_buffer_dir(),respect_gitignore=false,hidden=true,grouped=true,previewer=false,initial_mode="normal",layout_config={height=40}})end)
Tabs: Bufferline
I use akinsho/nvim-bufferline.lua to get better looking of tabs.
Make some customizations to make it look better with Solarized theme:
glepnir/lspsaga.nvim is one of my favorite LSP plugins.
It provides beautiful UIs for various LSP-related features like hover doc, definition preview, and rename actions.
My configuration is simple:
lewis6991/gitsigns.nvim provides git decorations for current buffers.
It helps you know which lines are currently changed.
It works out of the box.
require('gitsigns').setup{}
git
I often view the code on GitHub. dinhhuy258/git.nvim helps open GitHub right from Neovim, and provides git blame view in split view, which are super handy.
localstatus,git=pcall(require,"git")if(notstatus)thenreturnendgit.setup({keymaps={-- Open blame windowblame="<Leader>gb",-- Open file/folder in git repositorybrowse="<Leader>go",}})