~keving/dotfiles

91688797d8ee157fa1542b73eb328445df4a4187 — Kevin Guillaumond 7 months ago f5c6560
Add binding to toggle between header and source file in C and C++
1 files changed, 17 insertions(+), 0 deletions(-)

M .config/nvim/init.lua
M .config/nvim/init.lua => .config/nvim/init.lua +17 -0
@@ 339,6 339,23 @@ utils.map('n', '<leader>ts', ':TestSuite<CR>')
utils.map('n', '<leader>tl', ':TestLast<CR>')
utils.map('n', '<leader>tg', ':TestVisit<CR>')

-- Toggle between source file and header file in C and C++
utils.map('n', '<leader>gt', ':lua header_file_toggle()<CR>', {silent=true})
function header_file_toggle()
  -- For "/rnd/hello.c", file dir is "/rnd", file name is "hello" and ext is "c"
  local current_file_dir = vim.api.nvim_exec([[echo expand('%:h')]], true)
  local current_file_name = vim.api.nvim_exec([[echo expand('%:t:r')]], true)
  local current_file_ext = vim.api.nvim_exec([[echo expand('%:e')]], true)

  -- TODO don't open a blank buffer if the file doesn't exist
  if current_file_ext == 'c' or current_file_ext == 'cc' then
    vim.cmd('edit ' .. current_file_dir .. '/' .. current_file_name .. '.h')
  elseif current_file_ext == 'h' then
    -- TODO If .cc file doesn't exist, try .cpp and .c
    vim.cmd('edit ' .. current_file_dir .. '/' .. current_file_name .. '.cc')
  end
end


-- Spell checking
-- Toggle and untoggle spell checking