aboutsummaryrefslogtreecommitdiff
path: root/vim/.vim/vimrc
blob: bb271c439036997a7dbe144d0d8543a56dd9247c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
" You want Vim, not vi. When Vim finds a vimrc, 'nocompatible' is set anyway.
let g:disable_bg = 1  
let mapleader = " "

set nocompatible

filetype plugin indent on  " Load plugins according to detected filetype.
syntax on                  " Enable syntax highlighting.

set autoindent             " Indent according to previous line.
set expandtab              " Use spaces instead of tabs.
set softtabstop =2         " Tab key indents by 4 spaces.
set shiftwidth  =2         " >> indents by 4 spaces.
set shiftround             " >> indents to next multiple of 'shiftwidth'.

set backspace   =indent,eol,start  " Make backspace work as you would expect.
set hidden                 " Switch between buffers without having to save first.
set laststatus  =2         " Always show statusline.
set display     =lastline  " Show as much as possible of the last line.
set number
set relativenumber

set showmode               " Show current mode in command-line.
set showcmd                " Show already typed keys when more are expected.

set incsearch              " Highlight while searching with / or ?.
set ignorecase             " Case-insensitive search...
set smartcase              " ...unless uppercase used
set hlsearch               " Highlight matches

set backspace=indent,eol,start " Sane backspace behaviour

set ttyfast                " Faster redrawing.
set lazyredraw             " Only redraw when necessary.

set splitbelow             " Open new windows below the current window.
set splitright             " Open new windows right of the current window.

set wrapscan               " Searches wrap around end-of-file.
set report      =0         " Always report changed lines.
set synmaxcol   =200       " Only highlight the first 200 columns.
set clipboard=unnamedplus

cnoreabbrev W! w!
cnoreabbrev Q! q!
cnoreabbrev W  w
cnoreabbrev Wq wq
cnoreabbrev WQ wq
cnoreabbrev wQ wq
cnoreabbrev qw wq

" Basic UI settings
syntax on
set background=dark
colorscheme gruvbox

" Recommended settings for better appearance
set cursorline          " Highlight current line
set termguicolors       " Enable true color support (if terminal supports it)


function! GitBranch()
  let l:git_dir = finddir('.git', expand('%:p:h') . ';')
  if empty(l:git_dir)
    return ''
  endif
  let l:branch = system('git -C ' . fnameescape(expand('%:p:h')) . ' rev-parse --abbrev-ref HEAD 2> /dev/null')
  return substitute(l:branch, '\n', '', '')
endfunction

set laststatus=2
set statusline=%f
set statusline+=%h%m%r%w
set statusline+=\ %{GitBranch()}
set statusline+=\ [%{&ff}]
set statusline+=\ [%{&fileencoding}]
set statusline+=\ [%Y]
set statusline+=\ %=
set statusline+=Ln\ %l/%L
set statusline+=\ Col\ %c
set statusline+=\ [%p%%]


" The fish shell is not very compatible to other shells and unexpectedly
" breaks things that use 'shell'.
if &shell =~# 'fish$'
  set shell=/bin/bash
endif

function! CompileAndRun()
  let l:filename = expand('%:p')
  let l:output = expand('%:r')
  if empty(l:filename) || empty(l:output)
    echoerr "❌ File has not been saved. Save it before compiling."
    return
  endif

  let l:current_winnr = winnr()
  
  " Check if the compile output buffer already exists
  let l:compile_bufnr = bufnr('__COMPILE_OUTPUT__')
  let l:compile_winnr = bufwinnr(l:compile_bufnr)
  
  if l:compile_winnr == -1
    " Buffer doesn't exist in any window, create new vsplit
    vsplit
    enew
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
    " Give the buffer a name for easy identification
    file __COMPILE_OUTPUT__
  else
    " Buffer exists in a window, switch to it
    execute l:compile_winnr . 'wincmd w'
    " Clear the buffer content
    %delete _
  endif
  
  let l:compile_cmd = 'gcc -Wall ' . shellescape(l:filename) . ' -o ' . shellescape(l:output)
  let l:result = system(l:compile_cmd)
  if v:shell_error
    call append(0, split(l:result, "\n"))
  else
    call append(0, ['✅ Compiled successfully.', '', '--- Running output: ---', ''])
    let l:run_output = system('./' . l:output)
    call append(line('$'), split(l:run_output, "\n"))
  endif
  
  " Remove the empty line at the top
  if line('$') > 1 && getline(1) == ''
    1delete _
  endif

    execute l:current_winnr . 'wincmd w'
endfunction


command! Compile call CompileAndRun()
nnoremap <leader>c :Compile<CR>