Last active
January 25, 2024 20:38
-
-
Save mikhdm/30b5e85413ed081e00e5eb3ebbb3f61c to your computer and use it in GitHub Desktop.
.vimrc
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
set nocompatible | |
filetype off | |
call plug#begin('~/.vim/plugged') | |
Plug 'nvim-tree/nvim-web-devicons' "NvimTree icons | |
Plug 'tpope/vim-surround' "Surround everything | |
Plug 'tpope/vim-commentary' "Commenting lines and blocks | |
Plug 'majutsushi/tagbar' "Class/module browser | |
Plug 'EdenEast/nightfox.nvim' "Colortheme | |
Plug 'chr4/nginx.vim' "Nginx config highlighting | |
Plug 'ekalinin/Dockerfile.vim' "Dockerfile syntax coloring | |
Plug 'stephpy/vim-yaml' "Yaml syntax hightlighting | |
Plug 'neovim/nvim-lspconfig' "Nvim LSP support plugin | |
Plug 'Pocco81/auto-save.nvim' "Auto saver | |
Plug 'nvim-treesitter/nvim-treesitter' "Enhanced syntax highlighting | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf' } | |
Plug 'junegunn/fzf.vim' " Fuzzy finder | |
call plug#end() | |
" General | |
filetype plugin on | |
filetype indent on | |
function! Tab4Mode() | |
set tabstop=4 " Size of a hard tabstop (ts). | |
set shiftwidth=4 " Size of an indentation (sw). | |
set expandtab " Always uses spaces instead of tab characters (noet). | |
set smarttab " Inserts blanks on a <Tab> key (as per sw, ts and sts). | |
set autoindent " Copy indent from current line when starting a new line (ai). | |
echo "4 tabs mode enabled" | |
endfunction | |
function! Space2Mode() | |
set tabstop=2 " Size of a hard tabstop (ts). | |
set shiftwidth=2 " Size of an indentation (sw). | |
set expandtab " Always uses spaces instead of tab characters (et). | |
set softtabstop=0 " Number of spaces a <Tab> counts for. When 0, featuer is off (sts). | |
set autoindent " Copy indent from current line when starting a new line. | |
set smarttab " Inserts blanks on a <Tab> key (as per sw, ts and sts). | |
echo "2 spaces mode enabled" | |
endfunction | |
function! IToggle() | |
if &tabstop == 4 | |
call Space2Mode() | |
else | |
call Tab4Mode() | |
endif | |
endfunction | |
autocmd FileType python call Tab4Mode() | |
autocmd FileType cpp call Space2Mode() | |
nmap <F9> mz:execute IToggle() <CR> | |
set regexpengine=1 | |
set cursorline | |
set lazyredraw "buffer screen updates | |
set ttyfast "smooth scroll | |
syntax on | |
set encoding=utf-8 "default encoding setting | |
set number "line numbering | |
set incsearch "incrementable search | |
set hlsearch "highlight search results | |
set backspace=indent,eol,start "backspace behavior | |
set scrolloff=5 "5 strings per scroll at a time | |
set ls=2 "status bar always on | |
set mouse=a "enable mouse | |
" TextEdit might fail if hidden is not set. | |
set hidden | |
set background=dark | |
" Some servers have issues with backup files, see #649. | |
set nobackup | |
set nowritebackup | |
" Having longer updatetime (default is 4000ms = 4s) leads to noticeable | |
" delays and poor user experience. | |
set updatetime=300 | |
" Don't pass messages to |ins-completion-menu|. | |
set shortmess+=c | |
let g:python3_host_prog = '/usr/local/bin/python3' | |
"mapping Save to F2 | |
inoremap <F2> <Esc>:update<CR> | |
nnoremap <F2> :update<CR> | |
vnoremap <F2> <Esc>:update<CR> | |
"mapping to move between windows a little easier | |
map <C-h> <C-w>h | |
map <C-j> <C-w>j | |
map <C-k> <C-w>k | |
map <C-l> <C-w>l | |
"color settings | |
set t_Co=256 | |
if &term =~# '^screen' " :h xterm-true-colors | |
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" | |
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" | |
endif | |
if (has("termguicolors")) | |
set termguicolors | |
endif | |
colorscheme nightfox | |
set pastetoggle=<F5> | |
set nofixeol | |
"TagBar settings | |
map <F4> :TagbarToggle<CR> | |
"Airline | |
let g:airline_section_c = '%F' "full path in airline statusline | |
ino <silent><expr> <Esc> pumvisible() ? "\<C-e><Esc>" : "\<Esc>" | |
ino <silent><expr> <C-c> pumvisible() ? "\<C-e><C-c>" : "\<C-c>" | |
ino <silent><expr> <BS> pumvisible() ? "\<C-e><BS>" : "\<BS>" | |
ino <silent><expr> <CR> pumvisible() ? (complete_info().selected == -1 ? "\<C-e><CR>" : "\<C-y>") : "\<CR>" | |
"nvim-lspconfig | |
:lua << EOF | |
local conf = require("lspconfig") | |
local autosave = require("auto-save") | |
local treesitter = require("nvim-treesitter.configs") | |
local on_attach = function(client, bufnr) | |
local buf_set_keymap = function(...) | |
vim.api.nvim_buf_set_keymap(bufnr, ...) | |
end | |
local buf_set_option = function(...) | |
vim.api.nvim_buf_set_option(bufnr, ...) | |
end | |
-- Enable completion triggered by <c-x><c-o> | |
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") | |
-- Mappings | |
local opts = { noremap=true, silent=true } | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
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-m>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
buf_set_keymap('n', 'ge', '<cmd>lua vim.diagnostic.open_float({"line"})<CR>', opts) | |
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | |
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | |
end | |
servers = {"pyright", "clangd"}; | |
for _, lsp in ipairs(servers) do | |
conf[lsp].setup {on_attach = on_attach} | |
end | |
autosave.setup { | |
enabled = true, | |
execution_message = { | |
message = function() -- message to print on save | |
return (vim.fn.expand('%:p') .. " saved at " .. vim.fn.strftime("%H:%M:%S")) | |
end, | |
dim = 0.1, | |
cleaning_interval = 1000 | |
} | |
} | |
treesitter.setup { | |
highlight = { | |
enable = true, | |
-- Setting this to true will run `:h syntax` and tree-sitter at the same time. | |
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). | |
-- Using this option may slow down your editor, and you may see some duplicate highlights. | |
-- Instead of true it can also be a list of languages | |
additional_vim_regex_highlighting = false, | |
}, | |
} | |
-- less verbose diagnostic messages | |
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | |
vim.lsp.diagnostic.on_publish_diagnostics, { | |
underline = true, | |
virtual_text = false, | |
signs = false, | |
update_in_insert = true, | |
} | |
) | |
EOF | |
set completeopt=menuone,noselect,noinsert | |
inoremap <S-Tab> <C-x><C-o> | |
nnoremap <S-f> :Rg<CR> | |
hi NonText cterm=NONE ctermfg=NONE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment