Skip to content

Commit ad80474

Browse files
committed
Go to source/header mappings in C++
1 parent aba3dab commit ad80474

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/mappings.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ map('n', 'ss', require('substitute').line, '')
2626
map('n', 'S', require('substitute').eol, '')
2727
map('x', 's', require('substitute').visual, '')
2828

29+
-- Filetype mappings
30+
vim.api.nvim_create_autocmd('BufEnter', {
31+
group = vim.api.nvim_create_augroup('UserFileTypeMappings', {}),
32+
callback = function(e)
33+
local opts = { buffer = e.buf }
34+
local filetype = vim.bo.filetype
35+
36+
if filetype == 'cpp' then
37+
map('n', 'gh', '<CMD>e %:r.h<CR>', 'Go to header file', opts)
38+
map('n', 'gs', '<CMD>e %:r.cpp<CR>', 'Go to source file', opts)
39+
end
40+
end
41+
})
42+
2943
-- LSP mappings
3044
vim.api.nvim_create_autocmd('LspAttach', {
3145
group = vim.api.nvim_create_augroup('UserLspMappings', {}),

0 commit comments

Comments
 (0)