79185807

Date: 2024-11-13 16:29:33
Score: 0.5
Natty:
Report link

I came to the conclusion that I don't often want a side or lower split pane, I often enough just end up switching between the cpp/hpp files within the same pane I'm already in. So here's my solution for switching between cpp/hpp or c/h (or any combination) of these files. Not exactly what I was looking for initially, but this is how I find it most useful. Just thought I'd share:

"function to be able to swap between hpp/cpp/h/c files
function! SwitchSourceHeader()
  if (expand ("%:e") == "cpp") || (expand ("%:e") == "c")
    if !empty(glob("./" . expand("%:t:r") . ".hpp"))
      find %:t:r.hpp
    else
      find %:t:r.h
    endif
  elseif (expand ("%:e") == "hpp") || (expand ("%:e") == "h")
    if !empty(glob("./" . expand("%:t:r") . ".cpp"))
      find %:t:r.cpp
    else
      find %:t:r.c
    endif
  else
    echo "Not a c/h/cpp/hpp file"
  endif
endfunction

"alias to call hpp/cpp swap using function
nnoremap <leader>sh :call SwitchSourceHeader()<CR>

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Slacker