惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
B
Blog RSS Feed
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
L
LangChain Blog
IT之家
IT之家
F
Fortinet All Blogs
V
V2EX
C
Check Point Blog
The Cloudflare Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Override Default Options in Neovim
2022-12-02 · via jdhao's digital space

A very common confusion for new users of Neovim is that their option settings for a particular filetype does not work in init.vim (or init.lua).

For non-indent related option#

For non-indent related option, to make sure you option settings have the precedence over builtin. For filetype foo, you can create {NVIM_CONF_DIR}/after/ftplugin/foo.vim or (foo.lua) and write your setting their. For example,

setlocal expandtab
setlocal tabstop=2
setlocal shiftwidth=2
setlocal softtabstop=2

For indent related options#

Someone asked a question on stack overflow about php. The issue is that setting smartindent and indentexpr in ~/.config/nvim/after/ftplugin/php.lua does not work. After opening a php file, smartindent and indentexpr are still set by the php.vim under nvim runtimepath:

$VIMRUNTIME/runtime/indent/php.vim

This is because script under indent/ and syntax/ directory is sourced after script in ftplugin/. The source order is as follows:

" first wave
ftplugin/foo.vim
$VIMRUNTIME/ftplugin/foo.vim
after/ftplugin/foo.vim

" second wave
indent/foo.vim
$VIMRUNTIME/indent/foo.vim
after/indent/foo.vim

" third wave
syntax/foo.vim
$VIMRUNTIME/syntax/foo.vim
after/syntax/foo.vim

So in order for the user’s indent setting to take precedence, we need to put it under ~/.config/after/indent/.

Here is what works for me.

  • create the file ~/.config/nvim/after/indent/php.lua

  • add the settings there:

    vim.o.smartindent = true
    vim.o.indentexpr = ''