Comments (9)
deleted my comment on accident, but it said:
string.match(buffer.name:reverse(), "^(%a+)"):reverse()
should be
string.match(buffer.name:reverse(), "^([^./]+)"):reverse()
or it'll break on extensions with numbers
this is also equivalent:
string.match(vim.api.nvim_buf_get_name(0), "^.+[./](.+)$")
of course vim.fn.expand("%:e")
is easier than all of that, lol
from nvim-web-devicons.
Seems fair. I've actually encounter another compelling reason to map filetype and extension (when limiting search to files of the same file type), so I've created a separate plugin for this.
I guess this can be considered solved then. Thanks for the consideration nonetheless.
Best regards,
from nvim-web-devicons.
that's a good suggestion. Although it would probably slow down the plugin, because the filetype is given for a buffer and not for a file. I don't know if there is an existing vim function to get the filetype of a file.
from nvim-web-devicons.
🤔 Maybe we can have a mapping from extension to ft
for those cases. My usecase is to have the icon+highlight in the statusbar, so it's easier if I use the - already available - filetype. :)
from nvim-web-devicons.
@hkupty I currently use this in my statusline with
let extension = fnamemodify(bufname(), ':e')
To pass the extension in to the get_icon
function. If that helps 🤷🏿♂️ .
from nvim-web-devicons.
I use something similar for now:
local extension = string.match(buffer.name:reverse(), "^(%a+)"):reverse()
local ok, icon, hl = pcall(require("nvim-web-devicons").get_icon, buffer.name, extension)
The thing is, some files like bash scripts don't have extensions. Also, you can manually force a filetype with a modeline, so I guess it'd be more resilient if relying on the filetype instead.
from nvim-web-devicons.
this would slow down the whole process... i think most plugins use this small library to enhance the ui of their file display, which in most case, requires a good performance. Adding a layer for the filetype would probably make those plugin authors not really happy. You can map you filetypes on files withouth an extension to return an extension for your statusbar, and fall back to the file extension otherwise, which would help displaying the right icon !
like so:
local mapFtToExt = { sh = "sh", python = "py" }
local filetype = api.nvim_buf_get_option(0, "ft")
let extension = fnamemodify(bufname(), ':e')
require"nvim-web-devicons".get_icon(buffer.name, mapFtToExt[filetype] or extension)
from nvim-web-devicons.
or we could add definitions and you could pass extension or filetype
to the extension param.
from nvim-web-devicons.
Thanks for the heads up. That didn't cross my mind.
from nvim-web-devicons.
Related Issues (20)
- Add openscad icon HOT 1
- Rename `:NvimWebDeviconsHiTest` to anything else like `WebDeviconsHiTest` HOT 8
- Regression: `NvimWebDeviconsHiTest` crashes HOT 5
- Missing icon for Java HOT 2
- :help HOT 1
- Some icons not show correctly HOT 2
- Incorrect NF symbol shown for Rust HOT 5
- Create a category for icons from desktop environments and window managers HOT 2
- Cannot override some icons by filename HOT 7
- TeX icon incorrect HOT 1
- [QUESTION]: how to add custom icon to laravel blade files HOT 4
- Invalid highlight name HOT 15
- change only icon color HOT 1
- W18 invalid character in a group name HOT 2
- Default icon is not working correctly HOT 12
- FR: differentiate `.d.ts` from `.ts` files (typescript) HOT 3
- Add known issue to README
- Custom icons not working on latest nvim nightly HOT 7
- Gulpfile and Gruntfile incorrect icon HOT 12
- Add issue template HOT 6
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-web-devicons.