Comments (15)
Interestingly also using the other 2 methods ie with :lua print(vim.inspect(
filetype))
and :lua print(vim.inspect(vim.api.nvim_buf_get_option(
filetype`) dont return a result.
Maybe I am doing stuff completely wrong, but I also tried without vim.inspect
and was not successful. Do you have any idea what is wrong?
from nvim-lua-guide.
and they are undocumented (dead links).
If I understand correctly, I think there's a slight misunderstanding here: these are not links but different tags that point to the same section
Using the metaaccessor
filetype
does not work, but it works withvimscript
:
I'm not sure the problem is related to Lua, it's hard to tell what's happening since I don't know where this code is being called. Is this from an autocommand?
And there's a meaningful difference between the two snippets: expand('%:e')
gets the file extension while vim.bo.filetype
gets the filetype option (which, in my understanding, is not available in all contexts)
from nvim-lua-guide.
Is this written in the neovim manual or in this guide that certain options are not available in all contexts?
So there is neovim lua equivalent of expand('%:e')
and one needs to use regex?
from nvim-lua-guide.
I'm not sure the problem is related to Lua, it's hard to tell what's happening since I don't know where this code is being called. Is this from an autocommand?
No, I wanted to conditionally set options depending on the filetype/file extension in lua.
from nvim-lua-guide.
Is this written in the neovim manual or in this guide that certain options are not available in all contexts?
I don't remember if it's documented in the manual off the top of my head, this is something I inferred from runtime/filetype.vim: the filetype for a buffer is set when the BufRead
or BufNewFile
events are fired. If you try to get the filetype before the autocommand is triggered, you get an empty string instead.
No, I wanted to conditionally set options depending on the filetype/file extension in lua.
I think for your particular use case it's better to create an ftplugin/cpp.lua
file in your config folder and put this code in it:
vim.opt_local.shiftwidth = 4
vim.opt_local.tabstop = 4
from nvim-lua-guide.
I think for your particular use case it's better to create an ftplugin/cpp.lua file in your config folder and put this code in it:
[user@pc nvim]$ cat ftplugin/cpp.lua
vim.opt_local.shiftwidth = 4
vim.opt_local.tabstop = 4
did not work. Changing to
vim.bo.shiftwidth
and vim.bo.tabstop
int ftplugin did neither work.
When gets the folder ftplugin
executed?
from nvim-lua-guide.
When gets the folder
ftplugin
executed?
When you set the filetype for a buffer IIRC. So opening a *.cpp
file or running :setfiletype cpp
should work.
Note that to do this in Lua, you have to be using the latest nightly as support for Lua runtime files was merged recently
from nvim-lua-guide.
@matu3ba Have you found a solution to your problem? I created a ~/.config/nvim/ftplugin/cpp.lua
file with various options and they're all set correctly when I open a *.cpp
file.
from nvim-lua-guide.
I forgot to set symlinks for my dotfiles. -.-.
Where would it make sense to document this behavior?
Near the folders
colors/
compiler/
ftplugin/
ftdetect/
indent/
plugin/
syntax/
and how they work with the order of how neovim sets up things (load order of stuff)?
Or would this stuff belong into the advanced guide?
from nvim-lua-guide.
I forgot to set symlinks for my dotfiles. -.-.
Honest mistake :P
Where would it make sense to document this behavior?
Hmm, I'm not sure I understand, what behavior specifically? If you mean runtime files, they're already well documented under :help 'runtimepath'
from nvim-lua-guide.
Hmm, I'm not sure I understand, what behavior specifically?
when vim.bo.filetype
is set or available in neovim with comparison if the same holds for vimscript filetype
.
from nvim-lua-guide.
This is the closest Vimscript equivalent to the Lua snippet you posted I could come up with:
if &l:filetype ==# 'cpp'
let &l:shiftwidth = 4
else
let &l:shiftwidth = 2
endif
if &l:filetype ==# 'cpp'
let &l:tabstop = 4
else
let &l:tabstop = 2
endif
This should behave the same as your original Lua code so I'm not sure the behavior you describe is Lua-specific (unless I misunderstood)
You're setting these options in your init.vim
/init.lua
, right? The 'filetype'
option is set after loading your init
file, which is why you get an empty string.
The usual mechanism for per-filetype configuration is either an autocommand (autocmd FileType cpp setlocal shiftwidth=4
) or an ftplugin (ftplugin/cpp.lua
)
from nvim-lua-guide.
The usual mechanism for per-filetype configuration is either an autocommand (autocmd FileType cpp setlocal shiftwidth=4) or an ftplugin (ftplugin/cpp.lua)
Ok, I understand. Since this is not lua specific, but for per-project configurations a shortcoming: Closing.
from nvim-lua-guide.
You're setting these options in your init.vim/init.lua, right? The 'filetype' option is set after loading your init file, which is why you get an empty string.
:h filetype
does not document this behavior. Or where can I read this in the manual?
The usual mechanism for per-filetype configuration is either an autocommand (autocmd FileType cpp setlocal shiftwidth=4) or an ftplugin (ftplugin/cpp.lua)
Is there a collection of "rough edges in neovim" that collects these kind of things?
from nvim-lua-guide.
:h filetype
does not document this behavior. Or where can I read this in the manual?
:help startup
documents the order of all the different startup scripts. Section 5 mentions filetype and indent plugins, which are sourced after the init
file mentioned in section 4.
The user-manual contains a lot of useful information as well. :help usr_43.txt
deals with filetype plugins
from nvim-lua-guide.
Related Issues (20)
- neovim autocommands got merged, describe them in guide HOT 4
- threading support for lua via libuv got merged, link to good tutorial on usage
- suggestions on how to reload keymaps and options
- How to get &ft from lua HOT 4
- Describe how to create user commands that support ranges
- explain that `vim.api.nvim_set_keymap(mode, ..)` is first char of `:lua print(vim.api.nvim_get_mode().mode)` and hint that there is a minor mode HOT 2
- FFI Library: calling native C function
- Remove problematic flags emoji
- Can we use this guide in Neovim? HOT 3
- Add a Table of content HOT 1
- add protected call for make sure the first run will work properlly
- add recommended formatter setup for lua and nvim lua plugin template
- Question: lua replacement for `executable()`? HOT 2
- how to read the command arguments `:command arg1 arg2` with lua HOT 2
- vim.api.nvim_exec() example gives error HOT 1
- lua user commands pr landed, so describe them in guide HOT 1
- Improper handling of relative paths with spaces HOT 2
- How to let `vim.cmd` accept the range from visual selection HOT 1
- Create keymap to open new file adjacent to current file HOT 6
- DEPRECATED replaced by mode option HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-lua-guide.