Quantcast
Channel: Active questions tagged keymapping - Stack Overflow
Viewing all articles
Browse latest Browse all 80

How to use different mappings depending on file type?

$
0
0

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 80

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>