Gregory Leeman 2 months ago
parent
commit
57eeff5ab6
  1. 70
      ftplugin/cpp.vim
  2. 7
      ftplugin/javascript.vim
  3. 2
      vimrc

70
ftplugin/cpp.vim

@ -23,73 +23,3 @@ let b:ale_linters = {
\ ] \ ]
\ } \ }
function! FindProjectRoot()
let l:current_dir = expand('%:p:h')
while l:current_dir != "/"
if filereadable(l:current_dir . "/main.cpp")
return l:current_dir
endif
let l:current_dir = fnamemodify(l:current_dir, ':h')
endwhile
return ""
endfunction
function! CompileProject(debug)
let l:project_root = FindProjectRoot()
if l:project_root == ""
echo "main.cpp not found in any parent directory."
return
endif
let l:main_file = l:project_root . "/main.cpp"
let l:project_name = fnamemodify(l:project_root, ':t')
let l:output_file = l:project_root . "/" . l:project_name
let l:warning_flags = "-Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion"
let l:disable_extension_flags = "-pedantic-errors"
let l:debug_flags = a:debug ? "-ggdb" : "-O2 -DNDEBUG"
let l:standard_flag = "-std=c++20"
let l:compile_cmd =
\ "g++" . " " .
\ l:standard_flag . " " .
\ l:warning_flags . " " .
\ l:disable_extension_flags . " " .
\ l:debug_flags . " " .
\ l:main_file . " " .
\ "-o" . " " . l:output_file
" Run the compile command and capture the output
let l:output = system(l:compile_cmd)
" Check if the compilation was successful
if v:shell_error
echo "Compilation failed:"
echo l:output
else
echo "Compilation successful. Output: " . l:output_file
endif
endfunction
function! RunProject()
let l:project_root = FindProjectRoot()
if l:project_root == ""
echo "Project root not found."
return
endif
let l:project_name = fnamemodify(l:project_root, ':t')
let l:output_file = l:project_root . "/" . l:project_name
if !filereadable(l:output_file)
echo "Output file not found. Please compile the project first."
return
endif
let l:run_cmd = "!" . l:output_file
execute l:run_cmd
endfunction
command! -nargs=0 Compile call CompileProject(1)
command! -nargs=0 CompileRelease call CompileProject(0)
command! -nargs=0 Run call RunProject()

7
ftplugin/javascript.vim

@ -0,0 +1,7 @@
set formatoptions-=r
set formatoptions-=c
set formatoptions-=o
let b:ale_linters = {
\ 'javascript': ['eslint'],
\ }

2
vimrc

@ -3,7 +3,6 @@
" \ \ / / | '_ ` _ \| '__/ __| " \ \ / / | '_ ` _ \| '__/ __|
" \ V /| | | | | | | | | (__ " \ V /| | | | | | | | | (__
" \_/ |_|_| |_| |_|_| \___| " \_/ |_|_| |_| |_|_| \___|
syntax on syntax on
" theme " theme
@ -31,6 +30,7 @@ Plug 'ncm2/ncm2-path'
Plug 'ncm2/ncm2-jedi' Plug 'ncm2/ncm2-jedi'
Plug 'dense-analysis/ale' Plug 'dense-analysis/ale'
Plug 'dhruvasagar/vim-table-mode' Plug 'dhruvasagar/vim-table-mode'
Plug 'ap/vim-css-color'
call plug#end() call plug#end()

Loading…
Cancel
Save