mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
49 Commits
v0.7.2
...
497f93d6c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
497f93d6c7 | ||
|
|
cfe2e0611d | ||
|
|
9de08d0afe | ||
|
|
d5b7584e68 | ||
|
|
64a7a23309 | ||
|
|
c1efc0bad6 | ||
|
|
b3b69f21f4 | ||
|
|
f491e26676 | ||
|
|
e7e4892c22 | ||
|
|
a52a362b02 | ||
|
|
2880d7bce3 | ||
|
|
7e6dd23d37 | ||
|
|
fcbd7d3a0d | ||
|
|
97f302084f | ||
|
|
9d29544d72 | ||
|
|
cad9f5a214 | ||
|
|
ecde08941b | ||
|
|
ab88c112ff | ||
|
|
4c96243a4c | ||
|
|
fdc158272b | ||
|
|
b331cddc73 | ||
|
|
b11c57e36f | ||
|
|
84d73660fa | ||
|
|
a9cc10b2ef | ||
|
|
cad6112cc2 | ||
|
|
4d7fd6580a | ||
|
|
f492a94db6 | ||
|
|
0c92d9a018 | ||
|
|
369687b047 | ||
|
|
54908dfe9f | ||
|
|
2e5f5c5991 | ||
|
|
8291b15599 | ||
|
|
3de31f7d0a | ||
|
|
6b59c268f9 | ||
|
|
dd550dc3d0 | ||
|
|
3aae07df56 | ||
|
|
ed5ddf60cc | ||
|
|
bcdc8d3f66 | ||
|
|
5498a05bf7 | ||
|
|
644f8b6e2d | ||
|
|
3af7dd51b8 | ||
|
|
e0fc068f2e | ||
|
|
58ed71f870 | ||
|
|
aae9a7b7a7 | ||
|
|
33270f3257 | ||
|
|
99d5a0343b | ||
|
|
3678da1b3c | ||
|
|
a8fdbf3573 | ||
|
|
351ba5fc63 |
6
.stylua.toml
Normal file
6
.stylua.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
# config for stylua, ref: https://github.com/JohnnyMorganz/StyLua
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
quote_style = "AutoPreferDouble"
|
||||
no_call_parentheses = true
|
||||
87
README.md
87
README.md
@@ -36,7 +36,7 @@
|
||||
# Introduction
|
||||
|
||||
This repo hosts my Nvim configuration for Linux, macOS, and Windows.
|
||||
`init.vim` is the config entry point for terminal Nvim,
|
||||
`init.lua` is the config entry point for terminal Nvim,
|
||||
and `ginit.vim` is the additional config file for [GUI client of Nvim](https://github.com/neovim/neovim/wiki/Related-projects#gui).
|
||||
|
||||
My configurations are heavily documented to make it as clear as possible.
|
||||
@@ -88,16 +88,16 @@ and how to set up on different platforms (Linux, macOS, and Windows).
|
||||
|
||||
For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).
|
||||
|
||||
## Start screen with alpha-nvim
|
||||
## Start screen with dashboard-nvim
|
||||
|
||||
<p align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16662357/139459989-0537ded4-c119-4749-99bf-b551ca1ba118.jpg" width="800">
|
||||
<img src="https://user-images.githubusercontent.com/16662357/183256752-fb23b215-a6b8-4646-beed-9999f52d53f1.png" width="800">
|
||||
</p>
|
||||
|
||||
## fuzzy finding using LeaderF
|
||||
## File fuzzy finding using LeaderF
|
||||
|
||||
<p align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16662357/139462025-7bce98c5-d2d5-413f-9659-20545865cdca.gif" width="800">
|
||||
<img src="https://user-images.githubusercontent.com/16662357/183257017-2d9d7605-3c4b-4e1d-8955-30998f9b6f28.gif" width="800">
|
||||
</p>
|
||||
|
||||
## Code autocompletion with nvim-cmp
|
||||
@@ -142,43 +142,46 @@ Go to a string starting with `se`
|
||||
|
||||
Some of the shortcuts I use frequently are listed here. In the following shortcuts, `<leader>` represents ASCII character `,`.
|
||||
|
||||
| Shortcut | Mode | platform | Description |
|
||||
|-------------------|---------------|-----------------|------------------------------------------------------------------|
|
||||
| `<leader>ff` | Normal | Linux/macOS/Win | Fuzzy file searching in a floating window |
|
||||
| `<leader>fh` | Normal | Linux/macOS/Win | Fuzzy help file grepping in a floating window |
|
||||
| `<leader>fg` | Normal | Linux/macOS/Win | Fuzzy project-wide grepping in a floating window |
|
||||
| `<leader>ft` | Normal | Linux/macOS/Win | Fuzzy buffer tag searching in a floating window |
|
||||
| `<leader>fb` | Normal | Linux/macOS/Win | Fuzzy buffer switching in a floating window |
|
||||
| `<leader><Space>` | Normal | Linux/macOS/Win | Remove trailing white spaces |
|
||||
| `<leader>v` | Normal | Linux/macOS/Win | Reselect last pasted text |
|
||||
| `<leader>ev` | Normal | Linux/macOS/Win | Edit Nvim config in a new tabpage |
|
||||
| `<leader>sv` | Normal | Linux/macOS/Win | Reload Nvim config |
|
||||
| `<leader>st` | Normal | Linux/macOS/Win | Show highlight group for cursor text |
|
||||
| `<leader>q` | Normal | Linux/macOS/Win | Quit current window |
|
||||
| `<leader>Q` | Normal | Linux/macOS/Win | Quit all window and close Nvim |
|
||||
| `<leader>w` | Normal | Linux/macOS/Win | Save current buffer content |
|
||||
| `<leader>y` | Normal | Linux/macOS/Win | Copy the content of entire buffer to default register |
|
||||
| `<leader>cl` | Normal | Linux/macOS/Win | Toggle cursor column |
|
||||
| `<leader>cd` | Normal | Linux/macOS/Win | Change current working directory to to the dir of current buffer |
|
||||
| `<space>t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) |
|
||||
| `<leader>gs` | Normal | Linux/macOS/Win | Show Git status result |
|
||||
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
|
||||
| `<leader>gd` | Normal | Linux/macOS/Win | Run git diff for current file |
|
||||
| `<leader>gc` | Normal | Linux/macOS/Win | Run git commit |
|
||||
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
|
||||
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
|
||||
| `<F9>` | Normal | Linux/macOS/Win | Run current source file (for Python, C++) |
|
||||
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
|
||||
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
|
||||
| `\x` | Normal | Linux/macOS/Win | Close location or quickfix window |
|
||||
| `\d` | Normal | Linux/macOS/Win | Close current buffer and go to previous buffer |
|
||||
| `{count}gb` | Normal | Linux/macOS/Win | Go to buffer {count} or next buffer in the buffer list. |
|
||||
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
||||
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
|
||||
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
|
||||
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
|
||||
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
||||
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
||||
| Shortcut | Mode | platform | Description |
|
||||
|-------------------|---------------|-----------------|--------------------------------------------------------------------------|
|
||||
| `<leader>ff` | Normal | Linux/macOS/Win | Fuzzy file searching in a floating window |
|
||||
| `<leader>fh` | Normal | Linux/macOS/Win | Fuzzy help file grepping in a floating window |
|
||||
| `<leader>fg` | Normal | Linux/macOS/Win | Fuzzy project-wide grepping in a floating window |
|
||||
| `<leader>ft` | Normal | Linux/macOS/Win | Fuzzy buffer tag searching in a floating window |
|
||||
| `<leader>fb` | Normal | Linux/macOS/Win | Fuzzy buffer switching in a floating window |
|
||||
| `<leader><Space>` | Normal | Linux/macOS/Win | Remove trailing white spaces |
|
||||
| `<leader>v` | Normal | Linux/macOS/Win | Reselect last pasted text |
|
||||
| `<leader>ev` | Normal | Linux/macOS/Win | Edit Nvim config in a new tabpage |
|
||||
| `<leader>sv` | Normal | Linux/macOS/Win | Reload Nvim config |
|
||||
| `<leader>st` | Normal | Linux/macOS/Win | Show highlight group for cursor text |
|
||||
| `<leader>q` | Normal | Linux/macOS/Win | Quit current window |
|
||||
| `<leader>Q` | Normal | Linux/macOS/Win | Quit all window and close Nvim |
|
||||
| `<leader>w` | Normal | Linux/macOS/Win | Save current buffer content |
|
||||
| `<leader>y` | Normal | Linux/macOS/Win | Copy the content of entire buffer to default register |
|
||||
| `<leader>cl` | Normal | Linux/macOS/Win | Toggle cursor column |
|
||||
| `<leader>cd` | Normal | Linux/macOS/Win | Change current working directory to to the dir of current buffer |
|
||||
| `<space>t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) |
|
||||
| `<leader>gs` | Normal | Linux/macOS/Win | Show Git status result |
|
||||
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
|
||||
| `<leader>gd` | Normal | Linux/macOS/Win | Run git diff for current file |
|
||||
| `<leader>gc` | Normal | Linux/macOS/Win | Run git commit |
|
||||
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
|
||||
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
|
||||
| `<F9>` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) |
|
||||
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
|
||||
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
|
||||
| `\x` | Normal | Linux/macOS/Win | Close location or quickfix window |
|
||||
| `\d` | Normal | Linux/macOS/Win | Close current buffer and go to previous buffer |
|
||||
| `{count}gb` | Normal | Linux/macOS/Win | Go to buffer `{count}` or next buffer in the buffer list. |
|
||||
| `{operator}iB` | Normal | Linux/macOS/Win | Operate in the whole buffer, `{operator}` can be `v`, `y`, `c`, `d` etc. |
|
||||
| `Alt-k` | Normal | Linux/macOS/Win | Move current line or selected lines up |
|
||||
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
|
||||
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
||||
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
|
||||
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
|
||||
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
|
||||
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
||||
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
||||
|
||||
# Custom commands
|
||||
|
||||
|
||||
8
after/ftplugin/javascript.vim
Normal file
8
after/ftplugin/javascript.vim
Normal file
@@ -0,0 +1,8 @@
|
||||
" Disable inserting comment leader after hitting o or O or <Enter>
|
||||
set formatoptions-=o
|
||||
set formatoptions-=r
|
||||
|
||||
set tabstop=2 " number of visual spaces per TAB
|
||||
set softtabstop=2 " number of spaces in tab when editing
|
||||
set shiftwidth=2 " number of spaces to use for autoindent
|
||||
set expandtab " expand tab to spaces so that tabs are spaces
|
||||
@@ -131,9 +131,11 @@ function! utils#Get_titlestr() abort
|
||||
if g:is_linux
|
||||
let l:title_str = hostname() . ' '
|
||||
endif
|
||||
let l:title_str = l:title_str . expand('%:p:~') . ' '
|
||||
if &buflisted
|
||||
let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M',getftime(expand('%')))
|
||||
|
||||
let l:buf_path = expand('%:p:~')
|
||||
let l:title_str = l:title_str . l:buf_path . ' '
|
||||
if &buflisted && l:buf_path != ""
|
||||
let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M:%S%z', getftime(expand('%')))
|
||||
endif
|
||||
|
||||
return l:title_str
|
||||
|
||||
@@ -135,3 +135,23 @@ augroup auto_create_dir
|
||||
autocmd!
|
||||
autocmd BufWritePre * lua require('utils').may_create_dir()
|
||||
augroup END
|
||||
|
||||
" ref: https://vi.stackexchange.com/a/169/15292
|
||||
function! s:handle_large_file() abort
|
||||
let g:large_file = 10485760 " 10MB
|
||||
let f = expand("<afile>")
|
||||
|
||||
if getfsize(f) > g:large_file || getfsize(f) == -2
|
||||
set eventignore+=all
|
||||
" turning off relative number helps a lot
|
||||
set norelativenumber
|
||||
setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1
|
||||
else
|
||||
set eventignore-=all relativenumber
|
||||
endif
|
||||
endfunction
|
||||
|
||||
augroup LargeFile
|
||||
autocmd!
|
||||
autocmd BufReadPre * call s:handle_large_file()
|
||||
augroup END
|
||||
|
||||
@@ -37,7 +37,9 @@ let g:mapleader = ','
|
||||
let g:vimsyn_embed = 'l'
|
||||
|
||||
" Use English as main language
|
||||
language en_US.utf-8
|
||||
if !g:is_mac
|
||||
language en_US.utf-8
|
||||
endif
|
||||
|
||||
" use filetype.lua instead of filetype.vim
|
||||
let g:do_filetype_lua = 1
|
||||
|
||||
@@ -87,7 +87,7 @@ xnoremap > >gv
|
||||
inoremap <expr> <tab> pumvisible() ? "\<c-n>" : "\<tab>"
|
||||
inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
|
||||
|
||||
" Edit and reload init.vim quickly
|
||||
" Edit and reload nvim config file quickly
|
||||
nnoremap <silent> <leader>ev :<C-U>tabnew $MYVIMRC <bar> tcd %:h<cr>
|
||||
nnoremap <silent> <leader>sv :<C-U>silent update $MYVIMRC <bar> source $MYVIMRC <bar>
|
||||
\ call v:lua.vim.notify("Nvim config successfully reloaded!", 'info', {'title': 'nvim-config'})<cr>
|
||||
@@ -101,10 +101,6 @@ nnoremap / /\v
|
||||
" Search in selected region
|
||||
xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
|
||||
|
||||
" Find and replace (like Sublime Text 3)
|
||||
nnoremap <C-H> :%s/
|
||||
xnoremap <C-H> :s/
|
||||
|
||||
" Change current working directory locally and print cwd after that,
|
||||
" see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
|
||||
nnoremap <silent> <leader>cd :<C-U>lcd %:p:h<CR>:pwd<CR>
|
||||
@@ -171,6 +167,7 @@ onoremap <silent> iB :<C-U>call text_obj#Buffer()<CR>
|
||||
|
||||
" Do not move my cursor when joining lines.
|
||||
nnoremap J mzJ`z
|
||||
nnoremap gJ mzgJ`z
|
||||
|
||||
" Break inserted text into smaller undo units.
|
||||
for ch in [',', '.', '!', '?', ';', ':']
|
||||
|
||||
@@ -112,6 +112,9 @@ set shortmess+=c
|
||||
" choice, IMHO.
|
||||
set shortmess+=S
|
||||
|
||||
" Disable showing intro message (:intro)
|
||||
set shortmess+=I
|
||||
|
||||
" Completion behaviour
|
||||
" set completeopt+=noinsert " Auto select the first completion entry
|
||||
set completeopt+=menuone " Show menu even if there is only one item
|
||||
@@ -120,7 +123,7 @@ set completeopt-=preview " Disable the preview window
|
||||
set pumheight=10 " Maximum number of items to show in popup menu
|
||||
set pumblend=10 " pseudo transparency for completion menu
|
||||
|
||||
set winblend=5 " pseudo transparency for floating window
|
||||
set winblend=0 " pseudo transparency for floating window
|
||||
|
||||
" Insert mode key word completion setting
|
||||
set complete+=kspell complete-=w complete-=b complete-=u complete-=t
|
||||
|
||||
@@ -371,9 +371,16 @@ if exists('g:started_by_firenvim') && g:started_by_firenvim
|
||||
\ }
|
||||
\ }
|
||||
|
||||
function! s:setup_firenvim() abort
|
||||
set noruler noshowcmd
|
||||
set laststatus=0 showtabline=0
|
||||
endfunction
|
||||
|
||||
augroup firenvim
|
||||
autocmd!
|
||||
autocmd BufEnter *.txt setlocal filetype=markdown laststatus=0 nonumber noshowcmd noruler showtabline=1
|
||||
autocmd FileType text call s:setup_firenvim()
|
||||
autocmd BufNewFile github.com_*.txt set filetype=markdown
|
||||
autocmd BufNewFile stackoverflow.com_*.txt set filetype=markdown
|
||||
augroup END
|
||||
endif
|
||||
|
||||
@@ -425,3 +432,6 @@ function! s:wilder_init() abort
|
||||
echohl Error |echomsg "Wilder.nvim missing: run :PackerSync to fix."|echohl None
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
|
||||
let g:auto_save = 1 " enable AutoSave on Vim startup
|
||||
|
||||
@@ -54,6 +54,13 @@ function! s:theme_setup_dict.kanagawa() dict abort
|
||||
colorscheme kanagawa
|
||||
endfunction
|
||||
|
||||
function! s:theme_setup_dict.catppuccin() dict abort
|
||||
let g:catppuccin_flavour = "frappe" " latte, frappe, macchiato, mocha
|
||||
|
||||
lua require("catppuccin").setup()
|
||||
colorscheme catppuccin
|
||||
endfunction
|
||||
|
||||
" Theme to directory name mapping, because theme repo name is not necessarily
|
||||
" the same as the theme name itself.
|
||||
let s:theme2dir = {
|
||||
@@ -67,6 +74,7 @@ let s:theme2dir = {
|
||||
\ 'everforest' :'everforest',
|
||||
\ 'nightfox': 'nightfox.nvim',
|
||||
\ 'kanagawa': 'kanagawa.nvim',
|
||||
\ 'catppuccin': 'catppuccin'
|
||||
\ }
|
||||
|
||||
let s:theme = utils#RandElement(keys(s:theme2dir))
|
||||
@@ -85,7 +93,7 @@ if !s:status
|
||||
endif
|
||||
|
||||
execute 'call ' . s:colorscheme_func
|
||||
if g:logging_level == 'info'
|
||||
if g:logging_level == 'debug'
|
||||
let s:msg1 = "Colorscheme: " . s:theme
|
||||
call v:lua.vim.notify(s:msg1, 'info', {'title': 'nvim-config'})
|
||||
endif
|
||||
|
||||
100
docs/README.md
100
docs/README.md
@@ -2,9 +2,44 @@ This doc summarizes how to install and use this configuration in detail.
|
||||
|
||||
# Pre-requisite
|
||||
|
||||
## Terminal emulators
|
||||
|
||||
Which [terminal emulator](https://en.wikipedia.org/wiki/Terminal_emulator) we choose to use greatly affects the appearance and features of Nvim.
|
||||
Since Nvim supports true colors, terminals that support true colors are preferred.
|
||||
For a list of terminals that support true colors, see [here](https://github.com/termstandard/colors).
|
||||
|
||||
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
|
||||
|
||||
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
|
||||
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
|
||||
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
|
||||
|
||||
## Patched Fonts
|
||||
|
||||
Since statusline or file explorer plugins often use Unicode symbols not available in normal font,
|
||||
we need to install a patched font from the [nerd-fonts](https://github.com/ryanoasis/nerd-fonts) project.
|
||||
|
||||
# Automatic installation
|
||||
|
||||
## Automatic Installation for Linux
|
||||
|
||||
To set up a workable Nvim environment on Linux,
|
||||
I use [a bash script](nvim_setup_linux.sh) to automatically install necessary dependencies, Nvim itself and configs.
|
||||
|
||||
Note that the variable `PYTHON_INSTALLED`, `SYSTEM_PYTHON` and `ADD_TO_SYSTEM_PATH` in the script
|
||||
should be set properly based on your environment.
|
||||
|
||||
## Automatic installation for Windows
|
||||
|
||||
Run script [nvim_setup_windows.ps1](nvim_setup_windows.ps1) under PowerShell.
|
||||
|
||||
# Manual install
|
||||
|
||||
There are a few dependencies if we want to use Nvim for efficient editing and development work.
|
||||
|
||||
## Python
|
||||
## Dependencies
|
||||
|
||||
### Python
|
||||
|
||||
A lot of Nvim plugins are mainly written in Python, so we must install Python 3.
|
||||
The easiest way to install is via [Anaconda](https://docs.anaconda.com/anaconda/install/index.html) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html).
|
||||
@@ -12,7 +47,7 @@ The easiest way to install is via [Anaconda](https://docs.anaconda.com/anaconda/
|
||||
After installation, make sure that you can run `python --version`,
|
||||
and that the output should be Python 3.x.
|
||||
|
||||
## Pynvim
|
||||
### Pynvim
|
||||
|
||||
Nvim relies on [pynvim](https://github.com/neovim/pynvim) to communicate with plugins that utilize its Python binding.
|
||||
Pynvim is required by plugins such as [wilder.nvim](https://github.com/gelguy/wilder.nvim).
|
||||
@@ -21,7 +56,7 @@ Pynvim is required by plugins such as [wilder.nvim](https://github.com/gelguy/wi
|
||||
pip install -U pynvim
|
||||
```
|
||||
|
||||
## python-lsp-server
|
||||
### python-lsp-server
|
||||
|
||||
[python-lsp-server (pylsp)](https://github.com/python-lsp/python-lsp-server) is a Python [Language Server](https://microsoft.github.io/language-server-protocol/) for completion, linting, go to definition, etc.
|
||||
|
||||
@@ -33,7 +68,7 @@ Note the executable for pylsp is also named `pylsp`. You need to set its PATH co
|
||||
If you use pip from Anaconda, the executable path may be something like `$CONDA_ROOT/bin/pylsp`.
|
||||
For native python, the path for pylsp may be like `$HOME/.local/bin/pylsp`
|
||||
|
||||
## Node
|
||||
### Node
|
||||
|
||||
We need to install node.js from [here](https://nodejs.org/en/download/).
|
||||
For Linux, you can use the following script:
|
||||
@@ -60,7 +95,7 @@ source ~/.bash_profile
|
||||
# source ~/.zshrc
|
||||
```
|
||||
|
||||
## vim-language-server
|
||||
### vim-language-server
|
||||
|
||||
[vim-language-server](https://github.com/iamcco/vim-language-server) provides completion for vim script. We can install vim-language-server globally:
|
||||
|
||||
@@ -70,7 +105,7 @@ npm install -g vim-language-server
|
||||
|
||||
vim-language-server is installed in the same directory as the node executable.
|
||||
|
||||
## Git
|
||||
### Git
|
||||
|
||||
Git is required by plugin manager [packer.nvim](https://github.com/wbthomason/packer.nvim) and other git-related plugins.
|
||||
|
||||
@@ -79,7 +114,7 @@ The version of Git on the Linux system may be too old so that plugins may break.
|
||||
Check [here](https://jdhao.github.io/2021/03/27/upgrade_git_on_linux/) on how to install and set up the latest version of Git.
|
||||
For Windows, install [Git for Windows](https://git-scm.com/download/win) and make sure you can run `git` from command line.
|
||||
|
||||
## ctags
|
||||
### ctags
|
||||
|
||||
In order to use tags related plugins such as [vista.vim](https://github.com/liuchengxu/vista.vim), we need to install a ctags distribution.
|
||||
Universal-ctags is preferred.
|
||||
@@ -102,7 +137,7 @@ choco install universal-ctags
|
||||
|
||||
Set its PATH properly and make sure you can run `ctags` from command line.
|
||||
|
||||
## Ripgrep
|
||||
### Ripgrep
|
||||
|
||||
[Ripgrep](https://github.com/BurntSushi/ripgrep), aka, `rg`, is a fast grepping tool available for both Linux, Windows and macOS.
|
||||
It is used by several searching plugins.
|
||||
@@ -112,7 +147,7 @@ For Linux, we can download the [binary release](https://github.com/BurntSushi/ri
|
||||
|
||||
Set its PATH properly and make sure you can run `rg` from command line.
|
||||
|
||||
## Linters
|
||||
### Linters
|
||||
|
||||
A linter is a tool to check the source code for possible style and syntax issues.
|
||||
Based on the programming languages we use, we may need to install various linters.
|
||||
@@ -122,35 +157,18 @@ Based on the programming languages we use, we may need to install various linter
|
||||
|
||||
Set their PATH properly and make sure you can run `pylint`, `flake8` and `vint` from command line.
|
||||
|
||||
## Terminal emulators
|
||||
|
||||
Which [terminal emulator](https://en.wikipedia.org/wiki/Terminal_emulator) we choose to use greatly affects the appearance and features of Nvim.
|
||||
Since Nvim supports true colors, terminals that support true colors are preferred.
|
||||
For a list of terminals that support true colors, see [here](https://github.com/termstandard/colors).
|
||||
|
||||
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
|
||||
|
||||
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
|
||||
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
|
||||
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
|
||||
|
||||
## Patched Fonts
|
||||
|
||||
Since statusline or file explorer plugins often use Unicode symbols not available in normal font,
|
||||
we need to install a patched font from the [nerd-fonts](https://github.com/ryanoasis/nerd-fonts) project.
|
||||
|
||||
# Install Nvim
|
||||
## Install Nvim
|
||||
|
||||
There are various ways to install Nvim depending on your system.
|
||||
This config is only maintained for [the latest nvim stable release](https://github.com/neovim/neovim/releases/tag/stable).
|
||||
|
||||
## Linux
|
||||
### Linux
|
||||
|
||||
You can directly download the binary release from [here](https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz).
|
||||
You can also use the system package manager to install nvim,
|
||||
but that is not reliable since the latest version may not be available.
|
||||
|
||||
## Windows
|
||||
### Windows
|
||||
|
||||
You may download from [nvim release](https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip) from GitHub and manually extract it.
|
||||
|
||||
@@ -164,7 +182,7 @@ choco install neovim
|
||||
# scoop install neovim
|
||||
```
|
||||
|
||||
## macOS
|
||||
### macOS
|
||||
|
||||
It is recommended to install neovim via [Homebrew](https://brew.sh/) on macOS. Simply run the following command:
|
||||
|
||||
@@ -175,9 +193,11 @@ brew install neovim
|
||||
After installing Nvim, we need to set the path to nvim correctly.
|
||||
**Make sure that you can run `nvim` from the command line after all these setups**.
|
||||
|
||||
# Setting up Nvim
|
||||
## Setting up Nvim
|
||||
|
||||
## Install plugin manager packer.nvim
|
||||
After installing nvim and all the dependencies, we will install plugin managers and set up this config.
|
||||
|
||||
### Install plugin manager packer.nvim
|
||||
|
||||
I use packer.nvim to manage my plugins. We need to install packer.nvim on our system first.
|
||||
|
||||
@@ -193,7 +213,7 @@ For macOS and Linux, run the following command:
|
||||
git clone --depth=1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/opt/packer.nvim
|
||||
```
|
||||
|
||||
## How to install this configuration
|
||||
### How to install this configuration
|
||||
|
||||
On Linux and macOS, the directory is `~/.config/nvim`.
|
||||
On Windows, the config directory is `$HOME/AppData/Local/nvim`[^1].
|
||||
@@ -207,18 +227,4 @@ git clone --depth=1 https://github.com/jdhao/nvim-config.git .
|
||||
After that, when we first open nvim, run command `:PackerSync` to install all the plugins.
|
||||
Since I use quite a lot of plugins (more than 60), it may take some time to install all of them.
|
||||
|
||||
# Automatic installation
|
||||
|
||||
## Automatic Installation for Linux #
|
||||
|
||||
To set up a workable Nvim environment on Linux,
|
||||
I use [a bash script](nvim_setup_linux.sh) to automatically install necessary dependencies, Nvim itself and configs.
|
||||
|
||||
Note that the variable `PYTHON_INSTALLED`, `SYSTEM_PYTHON` and `ADD_TO_SYSTEM_PATH` in the script
|
||||
should be set properly based on your environment.
|
||||
|
||||
## Automatic installation for Windows
|
||||
|
||||
Run script [nvim_setup_windows.ps1](nvim_setup_windows.ps1) under PowerShell.
|
||||
|
||||
[^1]: Use `echo %userprofile%` to see where your `$HOME` is.
|
||||
|
||||
@@ -120,6 +120,35 @@ fi
|
||||
# Install bash-language-server
|
||||
"$NODE_DIR/bin/npm" install -g bash-language-server
|
||||
|
||||
#######################################################################
|
||||
# lua-language-server #
|
||||
#######################################################################
|
||||
SUMNEKO_LUA_DIR=$HOME/tools/lua-language-server
|
||||
SUMNEKO_LUA_SRC_NAME=$HOME/packages/lua-language-server.tar.gz
|
||||
SUMNEKO_LUA_LINK="https://github.com/sumneko/lua-language-server/releases/download/3.5.3/lua-language-server-3.5.3-linux-x64.tar.gz"
|
||||
|
||||
if [[ -z "$(command -v lua-language-server)" ]] && [[ ! -f "$SUMNEKO_LUA_DIR/bin/lua-language-server" ]]; then
|
||||
echo 'Install lua-language-server'
|
||||
if [[ ! -f $SUMNEKO_LUA_SRC_NAME ]]; then
|
||||
echo "Downloading lua-language-server and renaming"
|
||||
wget $SUMNEKO_LUA_LINK -O "$SUMNEKO_LUA_SRC_NAME"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$SUMNEKO_LUA_DIR" ]]; then
|
||||
echo "Creating lua-language-server directory under tools directory"
|
||||
mkdir -p "$SUMNEKO_LUA_DIR"
|
||||
echo "Extracting to directory $SUMNEKO_LUA_DIR"
|
||||
|
||||
tar zxvf "$SUMNEKO_LUA_SRC_NAME" -C "$SUMNEKO_LUA_DIR"
|
||||
fi
|
||||
|
||||
if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then
|
||||
echo "export PATH=\"$SUMNEKO_LUA_DIR/bin:\$PATH\"" >> "$HOME/.bash_profile"
|
||||
fi
|
||||
else
|
||||
echo "lua-language-server is already installed. Skip installing it."
|
||||
fi
|
||||
|
||||
#######################################################################
|
||||
# Ripgrep part #
|
||||
#######################################################################
|
||||
@@ -145,8 +174,8 @@ if [[ -z "$(command -v rg)" ]] && [[ ! -f "$RIPGREP_DIR/rg" ]]; then
|
||||
fi
|
||||
|
||||
# set up manpath and zsh completion for ripgrep
|
||||
mkdir -p $HOME/tools/ripgrep/doc/man/man1
|
||||
mv $HOME/tools/ripgrep/doc/rg.1 $HOME/tools/ripgrep/doc/man/man1
|
||||
mkdir -p "$HOME/tools/ripgrep/doc/man/man1"
|
||||
mv "$HOME/tools/ripgrep/doc/rg.1" "$HOME/tools/ripgrep/doc/man/man1"
|
||||
|
||||
if [[ "$USE_BASH_SHELL" = true ]]; then
|
||||
echo 'export MANPATH=$HOME/tools/ripgrep/doc/man:$MANPATH' >> "$HOME/.bash_profile"
|
||||
|
||||
37
init.lua
Normal file
37
init.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
-- This is my personal Nvim configuration supporting Mac, Linux and Windows, with various plugins configured.
|
||||
-- This configuration evolves as I learn more about Nvim and become more proficient in using Nvim.
|
||||
-- Since it is very long (more than 1000 lines!), you should read it carefully and take only the settings that suit you.
|
||||
-- I would not recommend cloning this repo and replace your own config. Good configurations are personal,
|
||||
-- built over time with a lot of polish.
|
||||
--
|
||||
-- Author: Jie-dong Hao
|
||||
-- Email: jdhao@hotmail.com
|
||||
-- Blog: https://jdhao.github.io/
|
||||
|
||||
-- check if we have the latest stable version of nvim
|
||||
local expected_ver = "0.7.2"
|
||||
|
||||
local utils = require "utils"
|
||||
local nvim_ver = utils.get_nvim_version()
|
||||
|
||||
if nvim_ver ~= expected_ver then
|
||||
local msg = string.format("Unsupported nvim version: expect %s, but got %s instead!", expected_ver, nvim_ver)
|
||||
vim.api.nvim_echo({ { msg, "ErrorMsg" } }, false, {})
|
||||
return
|
||||
end
|
||||
|
||||
local core_conf_files = {
|
||||
"globals.vim",
|
||||
"options.vim",
|
||||
"autocommands.vim",
|
||||
"mappings.vim",
|
||||
"plugins.vim",
|
||||
"themes.vim",
|
||||
}
|
||||
|
||||
-- source all the core config files
|
||||
for _, name in ipairs(core_conf_files) do
|
||||
local path = string.format("%s/core/%s", vim.fn.stdpath('config'), name)
|
||||
local source_cmd = "source " .. path
|
||||
vim.cmd(source_cmd)
|
||||
end
|
||||
31
init.vim
31
init.vim
@@ -1,31 +0,0 @@
|
||||
" This is my personal Nvim configuration supporting Mac, Linux and Windows, with various plugins configured.
|
||||
" This configuration evolves as I learn more about Nvim and become more proficient in using Nvim.
|
||||
" Since it is very long (more than 1000 lines!), you should read it carefully and take only the settings that suit you.
|
||||
" I would not recommend cloning this repo and replace your own config. Good configurations are personal,
|
||||
" built over time with a lot of polish.
|
||||
"
|
||||
" Author: Jie-dong Hao
|
||||
" Email: jdhao@hotmail.com
|
||||
" Blog: https://jdhao.github.io/
|
||||
|
||||
" check if we have the lastest stable version of nvim
|
||||
let s:expect_ver = printf('nvim-%s', '0.7.2')
|
||||
let s:actual_ver = matchstr(execute('version'), 'NVIM v\zs[^\n]*')
|
||||
|
||||
if !has(s:expect_ver)
|
||||
echohl Error | echomsg printf("%s required, but got nvim %s!", s:expect_ver, s:actual_ver) | echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:core_conf_files = [
|
||||
\ 'globals.vim',
|
||||
\ 'options.vim',
|
||||
\ 'autocommands.vim',
|
||||
\ 'mappings.vim',
|
||||
\ 'plugins.vim',
|
||||
\ 'themes.vim'
|
||||
\ ]
|
||||
|
||||
for s:fname in s:core_conf_files
|
||||
execute printf('source %s/core/%s', stdpath('config'), s:fname)
|
||||
endfor
|
||||
@@ -1,32 +0,0 @@
|
||||
local alpha = require("alpha")
|
||||
local dashboard = require("alpha.themes.dashboard")
|
||||
|
||||
-- Set header
|
||||
dashboard.section.header.val = {
|
||||
" ",
|
||||
" ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ",
|
||||
" ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ",
|
||||
" ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ",
|
||||
" ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ",
|
||||
" ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ",
|
||||
" ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ",
|
||||
" ",
|
||||
}
|
||||
|
||||
-- Set menu
|
||||
dashboard.section.buttons.val = {
|
||||
dashboard.button( "Leader f f", " > Find file", ":Leaderf file --popup<CR>"),
|
||||
dashboard.button( "Leader f r", " > Recent files" , ":Leaderf mru --popup<CR>"),
|
||||
dashboard.button( "Leader f g", " > Project grep" , ":Leaderf rg --popup<CR>"),
|
||||
dashboard.button( "u", " > Update plugins" , ":PackerSync<CR>"),
|
||||
dashboard.button( "e", " > New file" , ":enew <CR>"),
|
||||
dashboard.button( "q", " > Quit NVIM", ":qa<CR>"),
|
||||
}
|
||||
|
||||
local fortune = require("alpha.fortune")
|
||||
dashboard.section.footer.val = fortune()
|
||||
|
||||
alpha.setup(dashboard.opts)
|
||||
|
||||
-- Send config to alpha
|
||||
alpha.setup(dashboard.opts)
|
||||
@@ -1,15 +0,0 @@
|
||||
require("autosave").setup({
|
||||
enabled = true,
|
||||
execution_message = "Autosaved at " .. vim.fn.strftime("%H:%M:%S"),
|
||||
events = { "InsertLeave", "TextChanged" },
|
||||
conditions = {
|
||||
exists = true,
|
||||
filename_is_not = {"plugins.lua"},
|
||||
filetype_is_not = {},
|
||||
modifiable = true,
|
||||
},
|
||||
write_all_buffers = false,
|
||||
on_off_commands = true,
|
||||
clean_command_line_interval = 1000,
|
||||
debounce_delay = 135,
|
||||
})
|
||||
65
lua/config/dashboard-nvim.lua
Normal file
65
lua/config/dashboard-nvim.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
local dashboard = require("dashboard")
|
||||
|
||||
dashboard.custom_header = {
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗",
|
||||
" ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║",
|
||||
" ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║",
|
||||
" ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║",
|
||||
" ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║",
|
||||
" ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
}
|
||||
|
||||
dashboard.custom_center = {
|
||||
{
|
||||
icon = " ",
|
||||
desc = "Find File ",
|
||||
action = "Leaderf file --popup",
|
||||
shortcut = "<Leader> f f",
|
||||
},
|
||||
{
|
||||
icon = " ",
|
||||
desc = "Recently opened files ",
|
||||
action = "Leaderf mru --popup",
|
||||
shortcut = "<Leader> f r",
|
||||
},
|
||||
{
|
||||
icon = " ",
|
||||
desc = "Project grep ",
|
||||
action = "Leaderf rg --popup",
|
||||
shortcut = "<Leader> f g",
|
||||
},
|
||||
{
|
||||
icon = " ",
|
||||
desc = "Open Nvim config ",
|
||||
action = "tabnew $MYVIMRC | tcd %:p:h",
|
||||
shortcut = "<Leader> e v",
|
||||
},
|
||||
{
|
||||
icon = " ",
|
||||
desc = "New file ",
|
||||
action = "enew",
|
||||
shortcut = "e ",
|
||||
},
|
||||
{
|
||||
icon = " ",
|
||||
desc = "Quit Nvim ",
|
||||
-- desc = "Quit Nvim ",
|
||||
action = "qa",
|
||||
shortcut = "q "
|
||||
}
|
||||
}
|
||||
|
||||
vim.cmd([[
|
||||
augroup dashboard_enter
|
||||
au!
|
||||
autocmd FileType dashboard nnoremap <buffer> q :qa<CR>
|
||||
autocmd FileType dashboard nnoremap <buffer> e :enew<CR>
|
||||
augroup END
|
||||
]])
|
||||
1
lua/config/fidget-nvim.lua
Normal file
1
lua/config/fidget-nvim.lua
Normal file
@@ -0,0 +1 @@
|
||||
require"fidget".setup{}
|
||||
@@ -13,7 +13,7 @@ local custom_attach = function(client, bufnr)
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
||||
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
|
||||
vim.keymap.set("n", "<space>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts)
|
||||
vim.keymap.set("n", "<space>wl", function() inspect(vim.lsp.buf.list_workspace_folders()) end, opts)
|
||||
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
@@ -21,10 +21,10 @@ local custom_attach = function(client, bufnr)
|
||||
vim.keymap.set("n", "<space>q", function() vim.diagnostic.setqflist({open = true}) end, opts)
|
||||
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts)
|
||||
|
||||
vim.api.nvim_create_autocmd("CursorHold", {
|
||||
api.nvim_create_autocmd("CursorHold", {
|
||||
buffer=bufnr,
|
||||
callback = function()
|
||||
local opts = {
|
||||
local float_opts = {
|
||||
focusable = false,
|
||||
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
||||
border = 'rounded',
|
||||
@@ -36,11 +36,11 @@ local custom_attach = function(client, bufnr)
|
||||
vim.b.diagnostics_pos = { nil, nil }
|
||||
end
|
||||
|
||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||
local cursor_pos = api.nvim_win_get_cursor(0)
|
||||
if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) and
|
||||
#vim.diagnostic.get() > 0
|
||||
then
|
||||
vim.diagnostic.open_float(nil, opts)
|
||||
vim.diagnostic.open_float(nil, float_opts)
|
||||
end
|
||||
|
||||
vim.b.diagnostics_pos = cursor_pos
|
||||
@@ -148,36 +148,30 @@ if utils.executable('bash-language-server') then
|
||||
})
|
||||
end
|
||||
|
||||
local sumneko_binary_path = fn.exepath("lua-language-server")
|
||||
if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then
|
||||
local sumneko_root_path = fn.fnamemodify(sumneko_binary_path, ":h:h:h")
|
||||
|
||||
local runtime_path = vim.split(package.path, ";")
|
||||
table.insert(runtime_path, "lua/?.lua")
|
||||
table.insert(runtime_path, "lua/?/init.lua")
|
||||
|
||||
if utils.executable("lua-language-server") then
|
||||
-- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings .
|
||||
lspconfig.sumneko_lua.setup({
|
||||
on_attach = custom_attach,
|
||||
cmd = { sumneko_binary_path, "-E", sumneko_root_path .. "/main.lua" },
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = "LuaJIT",
|
||||
-- Setup your lua path
|
||||
path = runtime_path,
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = api.nvim_get_runtime_file("", true),
|
||||
},
|
||||
-- Do not send telemetry data containing a randomized but unique identifier
|
||||
telemetry = {
|
||||
enable = false,
|
||||
-- Make the server aware of Neovim runtime files,
|
||||
-- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace .
|
||||
-- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua .
|
||||
library = {
|
||||
fn.stdpath('data') .. "/site/pack/packer/opt/emmylua-nvim",
|
||||
fn.stdpath('config'),
|
||||
},
|
||||
maxPreload = 2000,
|
||||
preloadFileSize = 50000,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -33,7 +33,6 @@ cmp.setup({
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' }, -- For nvim-lsp
|
||||
{ name = 'ultisnips' }, -- For ultisnips user.
|
||||
{ name = 'nvim_lua' }, -- for nvim lua function
|
||||
{ name = 'path' }, -- for path completion
|
||||
{ name = 'buffer', keyword_length = 4 }, -- for buffer word completion
|
||||
{ name = 'omni' },
|
||||
|
||||
@@ -21,20 +21,36 @@ local function ime_state()
|
||||
end
|
||||
|
||||
local function trailing_space()
|
||||
-- Get the positions of trailing whitespaces from plugin 'jdhao/whitespace.nvim'.
|
||||
local trailing_space_pos = vim.b.trailing_whitespace_pos
|
||||
if not vim.o.modifiable then
|
||||
return ""
|
||||
end
|
||||
|
||||
local line_num = nil
|
||||
|
||||
for i=1, fn.line('$') do
|
||||
local linetext = fn.getline(i)
|
||||
-- To prevent invalid escape error, we wrap the regex string with `[[]]`.
|
||||
local idx = fn.match(linetext, [[\v\s+$]])
|
||||
|
||||
if idx ~= -1 then
|
||||
line_num = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local msg = ""
|
||||
if #trailing_space_pos > 0 then
|
||||
-- Note that lua index is 1-based, not zero based!!!
|
||||
local line = trailing_space_pos[1][1]
|
||||
msg = string.format("[%d]trailing", line)
|
||||
if line_num ~= nil then
|
||||
msg = string.format("[%d]trailing", line_num)
|
||||
end
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
local function mixed_indent()
|
||||
if not vim.o.modifiable then
|
||||
return ""
|
||||
end
|
||||
|
||||
local space_pat = [[\v^ +]]
|
||||
local tab_pat = [[\v^\t+]]
|
||||
local space_indent = fn.search(space_pat, 'nwc')
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
local keymap = vim.keymap
|
||||
|
||||
-- Go to the begining and end of current line in insert mode quickly
|
||||
-- Go to the beginning and end of current line in insert mode quickly
|
||||
keymap.set('i', '<C-A>', '<HOME>')
|
||||
keymap.set('i', '<C-E>', '<END>')
|
||||
|
||||
-- Go to beginning of command in command-line mode
|
||||
keymap.set('c', '<C-A>', '<HOME>')
|
||||
|
||||
-- Delete the character to the right of the cursor
|
||||
keymap.set('i', '<C-D>', '<DEL>')
|
||||
|
||||
@@ -1,23 +1,34 @@
|
||||
local utils = require("utils")
|
||||
local fn = vim.fn
|
||||
|
||||
vim.g.package_home = fn.stdpath("data") .. "/site/pack/packer/"
|
||||
local packer_install_dir = vim.g.package_home .. "/opt/packer.nvim"
|
||||
-- The root dir to install all plugins. Plugins are under opt/ or start/ sub-directory.
|
||||
vim.g.plugin_home = fn.stdpath("data") .. "/site/pack/packer"
|
||||
|
||||
local packer_repo = "https://github.com/wbthomason/packer.nvim"
|
||||
local install_cmd = string.format("10split |term git clone --depth=1 %s %s", packer_repo, packer_install_dir)
|
||||
-- Where to install packer.nvim -- the package manager (we make it opt)
|
||||
local packer_dir = vim.g.plugin_home .. "/opt/packer.nvim"
|
||||
|
||||
-- Whether this is a fresh install, i.e., packer itself and plugins have not been installed.
|
||||
local fresh_install = false
|
||||
|
||||
-- Auto-install packer in case it hasn't been installed.
|
||||
if fn.glob(packer_install_dir) == "" then
|
||||
if fn.glob(packer_dir) == "" then
|
||||
fresh_install = true
|
||||
|
||||
-- Now we need to install packer.nvim first.
|
||||
local packer_repo = "https://github.com/wbthomason/packer.nvim"
|
||||
local install_cmd = string.format("!git clone --depth=1 %s %s", packer_repo, packer_dir)
|
||||
|
||||
vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {})
|
||||
vim.cmd(install_cmd)
|
||||
end
|
||||
|
||||
-- Load packer.nvim
|
||||
vim.cmd("packadd packer.nvim")
|
||||
local util = require('packer.util')
|
||||
|
||||
require("packer").startup({
|
||||
local packer = require("packer")
|
||||
local packer_util = require('packer.util')
|
||||
|
||||
packer.startup({
|
||||
function(use)
|
||||
-- it is recommened to put impatient.nvim before any other plugins
|
||||
use {'lewis6991/impatient.nvim', config = [[require('impatient')]]}
|
||||
@@ -30,7 +41,7 @@ require("packer").startup({
|
||||
|
||||
-- nvim-cmp completion sources
|
||||
use {"hrsh7th/cmp-nvim-lsp", after = "nvim-cmp"}
|
||||
use {"hrsh7th/cmp-nvim-lua", after = "nvim-cmp"}
|
||||
-- use {"hrsh7th/cmp-nvim-lua", after = "nvim-cmp"}
|
||||
use {"hrsh7th/cmp-path", after = "nvim-cmp"}
|
||||
use {"hrsh7th/cmp-buffer", after = "nvim-cmp"}
|
||||
use { "hrsh7th/cmp-omni", after = "nvim-cmp" }
|
||||
@@ -119,6 +130,7 @@ require("packer").startup({
|
||||
use({"sainnhe/everforest", opt = true})
|
||||
use({"EdenEast/nightfox.nvim", opt = true})
|
||||
use({"rebelot/kanagawa.nvim", opt = true})
|
||||
use({"catppuccin/nvim", as = "catppuccin", opt = true})
|
||||
|
||||
-- Show git change (change, delete, add) signs in vim sign column
|
||||
use({"mhinz/vim-signify", event = 'BufEnter'})
|
||||
@@ -136,7 +148,7 @@ require("packer").startup({
|
||||
use({ "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] })
|
||||
|
||||
-- fancy start screen
|
||||
-- use { 'goolord/alpha-nvim', event = 'VimEnter', config = [[require('config.alpha-nvim')]] }
|
||||
use { 'glepnir/dashboard-nvim', event = "VimEnter", config = [[require('config.dashboard-nvim')]] }
|
||||
|
||||
use({
|
||||
"lukas-reineke/indent-blankline.nvim",
|
||||
@@ -183,13 +195,7 @@ require("packer").startup({
|
||||
-- use 'mg979/vim-visual-multi'
|
||||
|
||||
-- Autosave files on certain events
|
||||
use({
|
||||
"Pocco81/AutoSave.nvim",
|
||||
event = "VimEnter",
|
||||
config = function()
|
||||
vim.defer_fn(function() require('config.autosave') end, 1500)
|
||||
end
|
||||
})
|
||||
use({"907th/vim-auto-save", event = "InsertEnter"})
|
||||
|
||||
-- Show undo history visually
|
||||
use({"simnalamburt/vim-mundo", cmd = {"MundoToggle", "MundoShow"}})
|
||||
@@ -356,14 +362,25 @@ require("packer").startup({
|
||||
requires = { 'kyazdani42/nvim-web-devicons' },
|
||||
config = [[require('config.nvim-tree')]]
|
||||
}
|
||||
|
||||
use { 'ii14/emmylua-nvim', ft = 'lua' }
|
||||
|
||||
use { 'j-hui/fidget.nvim', after = 'nvim-lspconfig', config = [[require('config.fidget-nvim')]]}
|
||||
end,
|
||||
config = {
|
||||
max_jobs = 16,
|
||||
compile_path = util.join_paths(fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'),
|
||||
compile_path = packer_util.join_paths(fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'),
|
||||
},
|
||||
})
|
||||
|
||||
local status, _ = pcall(require, 'packer_compiled')
|
||||
if not status then
|
||||
-- For fresh install, we need to install plugins. Otherwise, we just need to require `packer_compiled.lua`.
|
||||
if fresh_install then
|
||||
-- We can command `PackerSync` here, because only after packer.startup, we can know what plugins to install.
|
||||
-- So plugin install should be done after the startup process.
|
||||
vim.cmd("PackerSync")
|
||||
else
|
||||
local status, _ = pcall(require, 'packer_compiled')
|
||||
if not status then
|
||||
vim.notify("Error requiring packer_compiled.lua: run PackerSync to fix!")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local fn = vim.fn
|
||||
|
||||
-- inspect something
|
||||
function inspect(item)
|
||||
function _G.inspect(item)
|
||||
vim.pretty_print(item)
|
||||
end
|
||||
|
||||
@@ -25,4 +25,11 @@ function M.may_create_dir()
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_nvim_version()
|
||||
local actual_ver = vim.version()
|
||||
|
||||
local nvim_ver_str = string.format("%d.%d.%d", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
||||
return nvim_ver_str
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -8,3 +8,40 @@ call utils#Cabbrev('man', 'Man')
|
||||
|
||||
" show current date and time in human readable format
|
||||
command! -nargs=? Datetime echo utils#iso_time(<q-args>)
|
||||
|
||||
" Convert Markdown file to PDF
|
||||
command! ToPDF call s:md_to_pdf()
|
||||
|
||||
function! s:md_to_pdf() abort
|
||||
" check if pandoc is installed
|
||||
if executable('pandoc') != 1
|
||||
echoerr "pandoc not found"
|
||||
return
|
||||
endif
|
||||
|
||||
let l:md_path = expand("%:p")
|
||||
let l:pdf_path = fnamemodify(l:md_path, ":r") .. ".pdf"
|
||||
|
||||
let l:header_path = stdpath('config') . '/resources/head.tex'
|
||||
|
||||
let l:cmd = "pandoc --pdf-engine=xelatex --highlight-style=zenburn --table-of-content " .
|
||||
\ "--include-in-header=" . l:header_path . " -V fontsize=10pt -V colorlinks -V toccolor=NavyBlue " .
|
||||
\ "-V linkcolor=red -V urlcolor=teal -V filecolor=magenta -s " .
|
||||
\ l:md_path . " -o " . l:pdf_path
|
||||
|
||||
if g:is_mac
|
||||
let l:cmd = l:cmd . '&& open ' . l:pdf_path
|
||||
endif
|
||||
|
||||
if g:is_win
|
||||
let l:cmd = l:cmd . '&& start ' . l:pdf_path
|
||||
endif
|
||||
|
||||
" echomsg l:cmd
|
||||
|
||||
let l:id = jobstart(l:cmd)
|
||||
|
||||
if l:id == 0 || l:id == -1
|
||||
echoerr "Error running command"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
78
resources/head.tex
Normal file
78
resources/head.tex
Normal file
@@ -0,0 +1,78 @@
|
||||
\usepackage{fancyvrb,newverbs}
|
||||
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
|
||||
|
||||
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
|
||||
\usepackage{hyperref}
|
||||
|
||||
% begin a new page for each section (first level header),
|
||||
% we need to combine this with `-V subparagraph` when invoking pandc
|
||||
% \usepackage{titlesec}
|
||||
% \newcommand{\sectionbreak}{\clearpage}
|
||||
|
||||
% change background color for inline code in markdown files.
|
||||
% The following code does not work well for long text, because the text will exceed the page boundary.
|
||||
\definecolor{bgcolor}{HTML}{DADADA}
|
||||
\let\oldtexttt\texttt
|
||||
|
||||
\renewcommand{\texttt}[1]{
|
||||
\colorbox{bgcolor}{\oldtexttt{#1}}
|
||||
}
|
||||
|
||||
% change style of quote, see also https://tex.stackexchange.com/a/436253/114857
|
||||
\usepackage[most]{tcolorbox}
|
||||
|
||||
\definecolor{linequote}{RGB}{224,215,188}
|
||||
\definecolor{backquote}{RGB}{249,245,233}
|
||||
\definecolor{bordercolor}{RGB}{221,221,221}
|
||||
|
||||
% change left border: https://tex.stackexchange.com/a/475716/114857
|
||||
% change left margin: https://tex.stackexchange.com/a/457936/114857
|
||||
\newtcolorbox{myquote}[1][]{%
|
||||
enhanced,
|
||||
breakable,
|
||||
size=minimal,
|
||||
left=10pt,
|
||||
top=5pt,
|
||||
bottom=5pt,
|
||||
frame hidden,
|
||||
boxrule=0pt,
|
||||
sharp corners=all,
|
||||
colback=backquote,
|
||||
borderline west={2pt}{0pt}{bordercolor},
|
||||
#1
|
||||
}
|
||||
|
||||
% redefine quote environment to use the myquote environment, see https://tex.stackexchange.com/a/337587/114857
|
||||
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
|
||||
|
||||
% start a new page after toc, we need to save the old command before defining
|
||||
% new one to avoid recursive command calls,
|
||||
% see https://tex.stackexchange.com/questions/47351/can-i-redefine-a-command-to-contain-itself
|
||||
\let\oldtoc\tableofcontents
|
||||
\renewcommand{\tableofcontents}{\oldtoc\newpage}
|
||||
|
||||
% fix header level issue
|
||||
\usepackage{enumitem}
|
||||
\setlistdepth{9}
|
||||
|
||||
\setlist[itemize,1]{label=$\bullet$}
|
||||
\setlist[itemize,2]{label=$\bullet$}
|
||||
\setlist[itemize,3]{label=$\bullet$}
|
||||
\setlist[itemize,4]{label=$\bullet$}
|
||||
\setlist[itemize,5]{label=$\bullet$}
|
||||
\setlist[itemize,6]{label=$\bullet$}
|
||||
\setlist[itemize,7]{label=$\bullet$}
|
||||
\setlist[itemize,8]{label=$\bullet$}
|
||||
\setlist[itemize,9]{label=$\bullet$}
|
||||
\renewlist{itemize}{itemize}{9}
|
||||
|
||||
\setlist[enumerate,1]{label=$\arabic*.$}
|
||||
\setlist[enumerate,2]{label=$\alph*.$}
|
||||
\setlist[enumerate,3]{label=$\roman*.$}
|
||||
\setlist[enumerate,4]{label=$\arabic*.$}
|
||||
\setlist[enumerate,5]{label=$\alpha*$}
|
||||
\setlist[enumerate,6]{label=$\roman*.$}
|
||||
\setlist[enumerate,7]{label=$\arabic*.$}
|
||||
\setlist[enumerate,8]{label=$\alph*.$}
|
||||
\setlist[enumerate,9]{label=$\roman*.$}
|
||||
\renewlist{enumerate}{enumerate}{9}
|
||||
Reference in New Issue
Block a user