Quantcast
Viewing all articles
Browse latest Browse all 74

Neovim + Lua: how to use different mappings depending on file type?

I have the following lua function for mapping keys in neovim

local M = {}function M.map(mode, lhs, rhs, opts)    -- default options    local options = { noremap = true }    if opts then        options = vim.tbl_extend("force", options, opts)    end    vim.api.nvim_set_keymap(mode, lhs, rhs, options)endreturn M

And use it for key mapping like so:

map("", "<Leader>f", ":CocCommand prettier.forceFormatDocument<CR>") map("", "<Leader>f", ":RustFmt<CR>")

I want to use :RustFmt only for .rs files and :CocCommand prettier.forceFormatDocument for all the other files.

Is this possible to do with vim.api.nvim_set_keymap and if so how could I do it?


Viewing all articles
Browse latest Browse all 74

Trending Articles