Skip to content

Commit

Permalink
v.0.1
Browse files Browse the repository at this point in the history
1) Small refactoring of `init.vim` so that the lua part is in `lua/init.lua`.
2) <leader>mm for media search. Uses approximate previews.
3) LaTeX making and execute of media files (including pdf) is equivalent to open with
   default app.
  • Loading branch information
radoslav11 committed May 23, 2023
1 parent b47647c commit dfb4a5f
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 56 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ Check `init.vim` for more details.
# (Optional) Copilot
Follow the installation on https://github.com/github/copilot.vim, and add it ot `pack/`.
You will be prompted to login from a browser, or put a 6 digit code.

# Dependencies
After adding image and pdf support, I realised that it would be good to keep track of the
dependencies and useful packages. I'll probably create some installation script at some point.
The list is as follows:
- `poppler` for image / pdf tools.
- `ripgrep` for search.
- `fzf` for search.
- `astyle` for formatting C/C++/C#/Java.
- `black` for formatting python.
- `tlmgr` for installing LaTex packages.
- `chafa` for viewing image approximations in a terminal.
- `viu` like `chafa`, but it sends an actual image. Works with iTerm2.
86 changes: 30 additions & 56 deletions init.vim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set termguicolors

call plug#begin()
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'nvim-lualine/lualine.nvim'
Plug 'akinsho/bufferline.nvim', { 'tag': '*' }
Plug 'ycm-core/YouCompleteMe', {'do': './install.py --all' }

Plug 'tpope/vim-commentary'
Expand All @@ -18,19 +18,20 @@ Plug 'nvim-lua/plenary.nvim'
Plug 'BurntSushi/ripgrep'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-file-browser.nvim'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-telescope/telescope-media-files.nvim'

Plug 'tmhedberg/SimpylFold'
Plug 'jiangmiao/auto-pairs'

Plug 'searleser97/cpbooster.vim'
Plug 'dmdque/solidity.vim'
Plug 'rebelot/kanagawa.nvim'
Plug 'morhetz/gruvbox'
call plug#end()

set background=dark
syntax on
set mouse=nv
set mouse=a

set ts=4
set sts=4
Expand All @@ -46,6 +47,7 @@ set whichwrap+=<,>,[,]
let g:AutoPairsFlyMode=0

let c_no_curly_error=1

" Better visual mode selection
let g:gruvbox_invert_selection=0
let g:gruvbox_contrast_dark='hard'
Expand All @@ -55,13 +57,10 @@ colorscheme gruvbox
nmap <F1> <nop>
imap <F1> <nop>
" I sometimes use CMD-C to copy on MacOS.
" For this to work, I map CMD-C to M-] in iTerm2.
vmap <M-]> y
" Find files using Telescope command-line sugar.
let mapleader = "\<Space>"
nnoremap <leader>ff :Telescope find_files<cr>
nnoremap <leader>mm :Telescope media_files<cr>
nnoremap <leader>fg :Telescope live_grep<cr>
nnoremap <leader>fb :Telescope buffers<cr>
nnoremap <leader>fh :Telescope help_tags<cr>
Expand Down Expand Up @@ -98,16 +97,18 @@ tmap <C-`> <C-\><C-N>:NvimTreeToggle<CR>
set clipboard=unnamed

autocmd FileType c setlocal makeprg=gcc\ '%'\ -o\ '%:r'\ -std=gnu11
autocmd FileType cpp setlocal makeprg=g++\ '%'\ -o\ '%:r'\ -std=c++17\ -O3
autocmd FileType c setlocal makeprg=gcc-13\ '%'\ -o\ '%:r'\ -std=gnu11
autocmd FileType cpp setlocal makeprg=g++-13\ '%'\ -o\ '%:r'\ -std=c++17\ -O3
autocmd FileType haskell setlocal makeprg=ghc\ --make\ '%'
autocmd FileType java setlocal makeprg=javac\ '%'
autocmd FileType tex setlocal makeprg=xelatex\ -interaction\ nonstopmode\ -halt-on-error\ '%'

" Terminal commands
set splitright
command! -nargs=* VertTerm vsplit | T <args>
command! -nargs=* VertTerm vsplit | te <args>

" From cuklev
autocmd QuickFixCmdPost [^l]* nested cwindow
function! ExecuteIfNoErrors()
if len(getqflist()) == 0
call ExecuteFile()
Expand All @@ -129,12 +130,18 @@ function! ExecuteFile()
VertTerm node "%"
elseif &filetype == "c" || &filetype == "cpp" || &filetype == "haskell"
VertTerm "%:p:r"
elseif &filetype == "tex"
" Make more general, so that it doesn't require MacOS
:!open '%:r'.pdf
elseif &filetype == "pdf" || &filetype == "png" || &filetype == "jpg" || &filetype == "jpeg"
" Make more general, so that it doesn't require MacOS
:!open "%"
endif
endfunction

" Compile & Run
map <F9> <ESC>:w<CR>:make<CR><CR>:call ExecuteIfNoErrors()<CR>
imap <F9> <ESC>:w<CR>:make<CR><CR>:call ExecuteIfNoErrors()<CR>
map <F9> <ESC>:w<CR>:make<CR>:call ExecuteIfNoErrors()<CR>
imap <F9> <ESC>:w<CR>:make<CR>:call ExecuteIfNoErrors()<CR>
map <F10> <ESC>:w<CR>:call ExecuteFile()<CR>
imap <F10> <ESC>:w<CR>:call ExecuteFile()<CR>
Expand All @@ -156,26 +163,11 @@ let g:formatdef_custom_black = '"black -l 79 --preview"'
let g:formatters_py = ['custom_black']

nmap <Tab> :Autoformat<CR>
nmap <F5> :CocDiagnostics<CR>
" YCM
set completeopt-=preview
let g:ycm_confirm_extra_conf = 0
let g:ycm_global_ycm_extra_conf = '~/.config/nvim/ycm_extra_conf.py'

" It's annoying otherwise
source ~/.config/nvim/cyrilic.vim

" vim-airline
let g:airline_theme='gruvbox'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_close_button = 0
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#show_tab_nr = 0
let airline#extensions#tabline#tabs_label = ''
let airline#extensions#tabline#show_splits = 0
let airline#extensions#tabline#show_buffers = 0
au User AirlineAfterInit :let g:airline_section_z = airline#section#create(['%p%%%#__accent_bold#%{g:airline_symbols.linenr}%l%#__restore__#%#__accent_bold#/%L%#__accent_bold# C:%v%#__restore__#'])

" Hide default mode
set noshowmode

Expand All @@ -185,29 +177,11 @@ vmap <S-tab> <gv
set backspace=2

lua <<EOF
require("toggleterm").setup()
require("nvim-tree").setup()
require("telescope").setup()
require'nvim-treesitter.configs'.setup {
ensure_installed = {
"c", "cpp", "python", "lua", "typescript", "javascript", "vim", "vimdoc", "query", "haskell", "cuda", "bash", "java"
},
sync_install = false,
auto_install = false,

highlight = {
enable = true,
-- disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,

additional_vim_regex_highlighting = false,
},
}
EOF
" YCM actually works well
set completeopt-=preview
let g:ycm_confirm_extra_conf = 0
let g:ycm_global_ycm_extra_conf = '~/.config/nvim/ycm_extra_conf.py'

" Add lua specific settings
" They are available in lua/init.lua
lua require('init')
107 changes: 107 additions & 0 deletions lua/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.fillchars = { eob = " "}

require("toggleterm").setup()
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 34,
},
renderer = {
group_empty = true,
},
})
require("telescope").setup({
extensions = {
media_files = {
find_cmd = "rg"
}
},
defaults = {
file_sorter = require("telescope.sorters").get_fzy_sorter,
prompt_prefix = " >",
color_devicons = true,

file_previewer = require("telescope.previewers").vim_buffer_cat.new,
grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,

layout_strategy = "horizontal",
layout_config = {
horizontal = {
preview_width = 0.55,
results_width = 0.8,
},
vertical = {
preview_height = 0.5,
},
},
},
})

require("telescope").load_extension("media_files")
require('lualine').setup({
options = {
theme = 'gruvbox',
icons_enabled = true,
section_separators = {left='', right=''},
component_separators = {left='', right=''},
-- component_separators = { left = '', right = ''},
-- section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
})
require("bufferline").setup()
require"nvim-treesitter.configs".setup{
ensure_installed = {
"c", "cpp", "python", "lua", "typescript", "javascript", "vim", "vimdoc", "query", "haskell", "cuda", "bash", "java"
},
sync_install = false,
auto_install = false,

highlight = {
enable = true,
-- disable slow treesitter highlight for large files
disable = function(_, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,

additional_vim_regex_highlighting = false,
},
}

0 comments on commit dfb4a5f

Please sign in to comment.