Last active
April 2, 2023 22:12
-
-
Save ominusliticus/cf13ae0e440f675d2778076909cbbfed to your computer and use it in GitHub Desktop.
Neovim and Bashrc configurations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias vim='nvim' | |
alias tpython='time python3 -W"ignore"' | |
. "$HOME/.cargo/env" | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
export PS1="\[\e]0;\u@\h: \e[01;32m\]\u\e[00m-\e[01;31m\]OL\[\e[00m\]\e[00;33m\]\$(parse_git_branch) \[\e[00;34m\]\w \[\e[00m\n$ " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('kevin/telescope') | |
require('kevin/lightline') | |
require('kevin/gitsigns') | |
require('kevin/lsp') | |
require('kevin/treesitter') | |
-- Add to file gitsigns.lua | |
require('gitsigns').setup { | |
-- config-signs | |
current_line_blame = true, | |
current_line_blame_opts = { | |
virt_text_pos = 'right_align' | |
} | |
} | |
-- Add to file telescope.lua | |
ocal telescope = require('telescope') | |
telescope.setup {} | |
telescope.load_extension('fzf') | |
-- Add to file ligline.lua | |
vim.g.lightline = { | |
active = { | |
left = { | |
{ 'mode', 'past' }, | |
{ 'gitbranch', 'filename', 'modified' } | |
} | |
}, | |
component_function = { | |
gitbranch = 'fugitivie#head' | |
} | |
} | |
-- Add to file lsp.lua | |
local lspconfig = require('lspconfig') | |
-- require("lsp-format").setup {} | |
local servers = { 'clangd', 'pylsp', 'cmake', 'texlab'} -- , 'pyright' } | |
-- Seems that clangd is the superior lsp | |
-- lspconfig.ccls.setup { | |
-- init_options = { | |
-- cache = { | |
-- directory = ".ccls-cache"; | |
-- }; | |
-- } | |
-- } | |
local on_attach = function(client, bufnr) | |
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
local opts = { noremap=true, silent=true } | |
-- require("lsp-format").on_attach(client) | |
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
end | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) | |
for _, lsp in ipairs(servers) do | |
lspconfig[lsp].setup { | |
capabilities = capabilities, | |
on_attach = on_attach, | |
} | |
end | |
-- lspconfig.gopls.setup { on_attach = on_attach } | |
local nvim_lsp = require'lspconfig' | |
local opts = { | |
tools = { -- rust-tools options | |
autoSetHints = true, | |
hover_with_actions = true, | |
inlay_hints = { | |
show_parameter_hints = false, | |
parameter_hints_prefix = "", | |
other_hints_prefix = "", | |
}, | |
}, | |
-- all the opts to send to nvim-lspconfig | |
-- these override the defaults set by rust-tools.nvim | |
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer | |
server = { | |
-- on_attach is a callback called when the language server attachs to the buffer | |
on_attach = on_attach, | |
settings = { | |
-- to enable rust-analyzer settings visit: | |
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc | |
["rust-analyzer"] = { | |
-- enable clippy on save | |
checkOnSave = { | |
command = "clippy" | |
}, | |
} | |
} | |
}, | |
} | |
require('rust-tools').setup(opts) | |
local cmp = require('cmp') | |
local lspkind = require('lspkind') | |
local luasnip = require('luasnip') | |
luasnip.config.set_config { | |
history = false | |
} | |
-- better autompletion experience | |
vim.o.completeopt = 'menu,menuone,noselect' | |
cmp.setup { | |
-- fromat auto complete menu | |
formatting = { | |
format = lspkind.cmp_format() | |
}, | |
mapping = { | |
-- Use <Tab> and <Shift>-<Tab> to naviage auto complete menu | |
['<Tab>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_jumpable() then | |
luasnip.expand_or_jump() | |
else | |
fallback() | |
end | |
end, { "i", "s" }), | |
['<S-Tab>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, { "i", "s" }), | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
['<C-Space>>'] = cmp.mapping.complete(), | |
}, | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
sources = cmp.config.sources({ | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
{ name = 'path' }, | |
{ name = 'buffer' }, | |
}) | |
} | |
luasnip.add_snippets(nil, { | |
all = { | |
luasnip.snippet({ | |
trig = "research_cr_py", | |
name = "Research Copyright", | |
dscr = "MIT License" | |
}, { | |
luasnip.text_node({ | |
"# Copyright 2021-2022 Kevin Ingles", | |
"#", | |
"# Permission is hereby granted, free of charge, to any person obtaining", | |
"# a copy of this software and associated documentation files (the", | |
"# \"Software\"), to deal in the Software without restriction, including", | |
"# without limitation the right to use, copy, modify, merge, publish,", | |
"# distribute, sublicense, and/or sell copies of the Software, and to", | |
"# permit persons to whom the Sofware is furnished to do so, subject to", | |
"# the following conditions:", | |
"#", | |
"# The above copyright notice and this permission notice shall be", | |
"# included in all copies or substantial poritions of the Software.", | |
"#", | |
"# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,", | |
"# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF", | |
"# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.", | |
"# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY", | |
"# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,", | |
"# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE", | |
"# SOFTWARE OR THE USE OF OTHER DEALINGS IN THE SOFTWARE" | |
}) | |
}), | |
luasnip.snippet({ | |
trig = "research_cr_cpp", | |
name = "Research Copyright", | |
dscr = "MIT License" | |
}, { | |
luasnip.text_node({ | |
"// Copyright 2021-2022 Kevin Ingles", | |
"//", | |
"// Permission is hereby granted, free of charge, to any person obtaining", | |
"// a copy of this software and associated documentation files (the", | |
"// \"Software\"), to deal in the Software without restriction, including", | |
"// without limitation the right to use, copy, modify, merge, publish,", | |
"// distribute, sublicense, and/or sell copies of the Software, and to", | |
"// permit persons to whom the Sofware is furnished to do so, subject to", | |
"// the following conditions:", | |
"//", | |
"// The above copyright notice and this permission notice shall be", | |
"// included in all copies or substantial poritions of the Software.", | |
"//", | |
"// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,", | |
"// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF", | |
"// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.", | |
"// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY", | |
"// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,", | |
"// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE", | |
"// SOFTWARE OR THE USE OF OTHER DEALINGS IN THE SOFTWARE" | |
}) | |
}) | |
} | |
}) | |
-- Add to file treesitter.lua | |
local treesitter = require('nvim-treesitter.configs') | |
treesitter.setup { | |
ensure_intsalled = "all", | |
highlight = { | |
enable = true, | |
additional_vim_regex_highlighting = true, | |
}, | |
indent = { | |
enable = true, | |
} | |
} | |
-- Add to file vimtex.lua | |
require('vimtex').setup {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Enble syntax highlight | |
syntax on | |
" Better colors | |
set termguicolors | |
" Number of spaces | |
set tabstop=4 | |
set softtabstop=4 | |
set expandtab | |
" auto-indent | |
filetype plugin indent on | |
filetype indent on | |
set cindent | |
set autoindent | |
set smartindent | |
" number of spaces used for autoindent | |
set shiftwidth=4 | |
" add line numbers | |
set number relativenumber | |
set numberwidth=4 | |
" highlight search patterns | |
set incsearch | |
set nohlsearch | |
" open splits intuitively | |
set splitbelow | |
set splitright | |
" navigate buffers without saving work | |
set hidden | |
" start scrolling before bottom of buffer | |
set scrolloff=8 | |
" save undo history | |
set undofile | |
" enable mouse support | |
set mouse=a | |
" case insensitive search used unless caps is provided | |
set ignorecase | |
set smartcase | |
" Hide code editing mode | |
set noshowmode | |
" Show issues on right | |
" set signcolumn=number | |
" Cutoff column | |
au BufRead,BufNewFile *.py set colorcolumn=79 | |
au BufRead,BufNewFile *.cpp set colorcolumn=99 | |
au BufRead,BufNewFile *.hpp set colorcolumn=99 | |
au BufRead,BufNewFile *.h set colorcolumn=99 | |
au BufRead,BufNewFile *.tex set colorcolumn=89 | |
hi ColorColumn ctermbg=lightgrey guibg=lightgrey | |
" Call and install plugins | |
call plug#begin('~/.config/nvim/plugged') | |
Plug 'gruvbox-community/gruvbox' " Color themes | |
Plug 'nvim-lua/plenary.nvim' " For telescope | |
Plug 'nvim-lua/lsp_extensions.nvim' " For rust type hints | |
Plug 'nvim-telescope/telescope.nvim' " Main Telescop plugin file browser | |
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' } " Recommend for Telescope | |
Plug 'itchyny/lightline.vim' " Lightline | |
Plug 'itchyny/vim-gitbranch' | |
" Plug 'tpope/vim-fugitive' " vim-fugitive | |
Plug 'lewis6991/gitsigns.nvim' " git commit messages in line | |
Plug 'neovim/nvim-lspconfig' " language server | |
Plug 'hrsh7th/nvim-cmp' " for auto completion | |
Plug 'hrsh7th/cmp-nvim-lsp' " for auto completion | |
" Plug 'hrsh7th/cmp-vsnip' " for auto-completion | |
" Plug 'hrsh7th/vim-vsnip' " for auto- | |
Plug 'L3MON4D3/LuaSnip' " for auto completion | |
Plug 'saadparwaiz1/cmp_luasnip' " for auto completion | |
Plug 'onsails/lspkind-nvim' " for auto completion | |
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' } " Improve syntax highlighting | |
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } " TeX autocomplete | |
Plug 'lervag/vimtex' " LaTeX plugin | |
Plug 'rhysd/vim-clang-format' | |
" Seems to mess with vim language client | |
Plug 'cespare/vim-toml', { 'branch': 'main'} | |
Plug 'rust-lang/rust.vim' " For rust auto formatting and more | |
Plug 'godlygeek/tabular' " automatic alignment based on regex | |
" For more: http://vimcasts.org/episodes/aligning-text-with-tabular-vim/ | |
Plug 'kyazdani42/nvim-web-devicons' " Uses fancy icons | |
Plug 'folke/trouble.nvim' " Display diagnostic information in screen | |
Plug 'simrat39/rust-tools.nvim' " To enable more rust analyzer features | |
Plug 'makerj/vim-pdf' | |
Plug 'lukas-reineke/lsp-format.nvim' " Autoformatting using LSPs | |
Plug 'psf/black', { 'branch': 'stable' } " Python formatter | |
call plug#end() | |
colorscheme gruvbox | |
colorscheme gruvbox | |
set background=dark | |
set completeopt=menuone,noinsert,noselect | |
call deoplete#custom#var('omni', 'input_patterns', { | |
\ 'tex': g:vimtex#re#deoplete | |
\}) | |
let g:tex_flavor = 'latex' | |
lua require('kevin') | |
" set spelllang=en spell | |
" set modelines | |
nnoremap <C-j> <Esc> | |
inoremap <C-j> <Esc> | |
vnoremap <C-j> <Esc> | |
snoremap <C-j> <Esc> | |
xnoremap <C-j> <Esc> | |
cnoremap <C-j> <C-c> | |
onoremap <C-j> <Esc> | |
lnoremap <C-j> <Esc> | |
tnoremap <C-j> <Esc> | |
nnoremap <C-h> <Esc> | |
inoremap <C-h> <Esc> | |
vnoremap <C-h> <Esc> | |
snoremap <C-h> <Esc> | |
xnoremap <C-h> <Esc> | |
cnoremap <C-h> <C-c> | |
onoremap <C-h> <Esc> | |
lnoremap <C-h> <Esc> | |
tnoremap <C-h> <Esc> | |
" inoremap " ""<left> | |
" inoremap ' ''<left> | |
" inoremap ( ()<left> | |
" inoremap [ []<left> | |
" inoremap { {}<left> | |
inoremap {<CR> {<CR>}<ESC>O | |
inoremap {;<CR> {<CR>};<ESC>O | |
let mapleader = ' ' | |
xnoremap <leader>p "_dP | |
nnoremap <leader>h :wincmd h<Cr> | |
nnoremap <leader>j :wincmd j<Cr> | |
nnoremap <leader>k :wincmd k<Cr> | |
nnoremap <leader>l :wincmd l<Cr> | |
nnoremap <C-p> :Telescope find_files<Cr> | |
nnoremap <C-b> :Telescope buffers<Cr> | |
nnoremap <C-S-s> :Telescope live_grep<Cr> | |
nnoremap <C-S> :Telescope grep_string<Cr> | |
nnoremap <C-c> :VimtexCompile<Cr> | |
nnoremap <C-S-c> :Telescope commands<Cr> | |
nnoremap <C-q> :Telescope quickfix<Cr> | |
nnoremap <leader>f :Telescope current_buffer_fuzzy_find<Cr> | |
nnoremap <leader>gr :Telescope lsp_references<Cr> | |
nnoremap <leader>gi :Telescope lsp_implementations<Cr> | |
nnoremap <leader>ds :Telescope lsp_document_symbols<Cr> | |
nnoremap <leader>ts :Telescope treesitter<Cr> | |
nnoremap <leader>ws :Telescope lsp_workspace_symbols<Cr> | |
" Insert newline character before letter | |
nnoremap <C-i> i<Cr><Esc> | |
" Format using clang format | |
" map <C-K> :pyf /home/kevin/Documents/LanguageServers/ClangLLVM/tools/share/clang/clang-format.py<Cr> | |
" imap <C-K> <c-o>:pyf /home/kevin/Documents/LanguageServers/ClangLLVM/tools/share/clang/clang-format.py<CR> | |
" Automatically format when saving file | |
let g:clang_format#detect_style_file = 1 | |
let g:clang_format#auto_format = 1 | |
let g:rustfmt_autosave = 1 | |
" Python formatting configurations | |
let g:black_linelength = 79 | |
" Remove white space at end of line for python files | |
au BufWritePre *.py :%s/\s\+$//e | |
" For nvim-qt set up | |
source /home/kevin/.config/nvim-qt/ginit.vim | |
nnoremap <leader>= :GuiFont CaskaydiaCove Nerd Font Mono:h12<Cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment