Last active
January 11, 2024 07:31
-
-
Save PolyMMA/c5ed775a66ebb82f70e2c9f4faedacdf to your computer and use it in GitHub Desktop.
My .vimrc configuration
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
" plugins | |
let need_to_install_plugins = 0 | |
if empty(glob('~/.vim/autoload/plug.vim')) | |
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
let need_to_install_plugins = 1 | |
endif | |
call plug#begin() | |
Plug 'tpope/vim-sensible' | |
Plug 'itchyny/lightline.vim' | |
Plug 'joshdick/onedark.vim' | |
Plug 'ap/vim-buftabline' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'preservim/nerdtree' | |
Plug 'jistr/vim-nerdtree-tabs' | |
Plug 'Xuyuanp/nerdtree-git-plugin' | |
Plug 'jiangmiao/auto-pairs' | |
Plug 'dense-analysis/ale' | |
Plug 'majutsushi/tagbar' | |
Plug 'vim-scripts/indentpython.vim' | |
Plug 'lepture/vim-jinja' | |
Plug 'pangloss/vim-javascript' | |
Plug 'alvan/vim-closetag' | |
Plug 'maxmellon/vim-jsx-pretty' | |
" Syntax correction related | |
" Plug 'SynTax/syntastic' | |
Plug 'tarekbecker/vim-yaml-formatter' | |
Plug 'mfukar/robotframework-vim' | |
Plug 'ambv/black' | |
" ORG mode related | |
Plug 'tpope/vim-speeddating' | |
" wondow | |
Plug 'itspriddle/ZoomWin' | |
call plug#end() | |
filetype plugin indent on | |
syntax on | |
if need_to_install_plugins == 1 | |
echo "Installing plugins..." | |
silent! PlugInstall | |
echo "Done!" | |
q | |
endif | |
" remap leader to , | |
let mapleader="," | |
let maplocalleader="m" | |
" always show the status bar | |
set laststatus=2 | |
" enable 256 colors | |
set t_Co=256 | |
set t_ut= | |
" turn on line numbering | |
set number | |
set relativenumber | |
" turn on cursor line mark | |
set cursorline | |
set cursorcolumn | |
" sane text files | |
set fileformat=unix | |
set encoding=utf-8 | |
set fileencoding=utf-8 | |
" sane editing | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 | |
set colorcolumn=100 | |
set expandtab | |
set viminfo='25,\"50,n~/.viminfo | |
autocmd FileType html setlocal tabstop=2 shiftwidth=2 softtabstop=2 | |
autocmd FileType css setlocal tabstop=2 shiftwidth=2 softtabstop=2 | |
autocmd FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2 | |
" auto-pairs | |
au FileType python let b:AutoPairs = AutoPairsDefine({"f'" : "'", "r'" : "'", "b'" : "'"}) | |
" word movement | |
imap <S-Left> <Esc>bi | |
nmap <S-Left> b | |
imap <S-Right> <Esc><Right>wi | |
nmap <S-Right> w | |
" indent/unindent with tab/shift-tab | |
nmap <Tab> >> | |
nmap <S-tab> << | |
imap <S-Tab> <Esc><<i | |
vmap <Tab> >gv | |
vmap <S-Tab> <gv | |
" mouse | |
set mouse=a | |
let g:is_mouse_enabled = 1 | |
noremap <silent> <Leader>m :call ToggleMouse()<CR> | |
function ToggleMouse() | |
if g:is_mouse_enabled == 1 | |
echo "Mouse OFF" | |
set mouse= | |
let g:is_mouse_enabled = 0 | |
else | |
echo "Mouse ON" | |
set mouse=a | |
let g:is_mouse_enabled = 1 | |
endif | |
endfunction | |
" color scheme | |
syntax on | |
colorscheme onedark | |
filetype on | |
filetype plugin indent on | |
" lightline | |
set noshowmode | |
let g:lightline = { 'colorscheme': 'onedark' } | |
" code folding | |
set foldmethod=indent | |
set foldlevel=99 | |
" wrap toggle | |
setlocal nowrap | |
noremap <silent> <Leader>w :call ToggleWrap()<CR> | |
function ToggleWrap() | |
if &wrap | |
echo "Wrap OFF" | |
setlocal nowrap | |
set virtualedit=all | |
silent! nunmap <buffer> <Up> | |
silent! nunmap <buffer> <Down> | |
silent! nunmap <buffer> <Home> | |
silent! nunmap <buffer> <End> | |
silent! iunmap <buffer> <Up> | |
silent! iunmap <buffer> <Down> | |
silent! iunmap <buffer> <Home> | |
silent! iunmap <buffer> <End> | |
else | |
echo "Wrap ON" | |
setlocal wrap linebreak nolist | |
set virtualedit= | |
setlocal display+=lastline | |
noremap <buffer> <silent> <Up> gk | |
noremap <buffer> <silent> <Down> gj | |
noremap <buffer> <silent> <Home> g<Home> | |
noremap <buffer> <silent> <End> g<End> | |
inoremap <buffer> <silent> <Up> <C-o>gk | |
inoremap <buffer> <silent> <Down> <C-o>gj | |
inoremap <buffer> <silent> <Home> <C-o>g<Home> | |
inoremap <buffer> <silent> <End> <C-o>g<End> | |
endif | |
endfunction | |
" Vertical jump to non-whitespace characer in same column | |
nnoremap <silent><leader>j :<C-u>call search('\%' . virtcol('.') . 'v\S', 'W')<CR> | |
nnoremap <silent><leader>k :<C-u>call search('\%' . virtcol('.') . 'v\S', 'bW')<CR> | |
" move through split windows | |
nmap <leader><Up> :wincmd k<CR> | |
nmap <leader><Down> :wincmd j<CR> | |
nmap <leader><Left> :wincmd h<CR> | |
nmap <leader><Right> :wincmd l<CR> | |
" move through buffers | |
nmap <leader>[ :bp!<CR> | |
nmap <leader>] :bn!<CR> | |
nmap <leader>x :bp<bar>bd#<CR> | |
" Map Ctrl+[hjkl] to navigate windows vim style | |
nnoremap <silent> <C-h> <C-w>h | |
nnoremap <silent> <C-j> <C-w>j | |
nnoremap <silent> <C-k> <C-w>k | |
nnoremap <silent> <C-l> <C-w>l | |
" restore place in file from previous session | |
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
" file browser | |
let NERDTreeIgnore = ['\.pyc$', '__pycache__'] | |
let NERDTreeMinimalUI = 1 | |
let g:nerdtree_open = 0 | |
map <leader>n :NERDTreeFind<CR> | |
map <leader>N :call NERDTreeToggle()<CR> | |
function NERDTreeToggle() | |
NERDTreeTabsToggle | |
if g:nerdtree_open == 1 | |
let g:nerdtree_open = 0 | |
else | |
let g:nerdtree_open = 1 | |
wincmd p | |
endif | |
endfunction | |
function! StartUp() | |
if 0 == argc() | |
NERDTree | |
end | |
endfunction | |
" enable line numbers | |
let NERDTreeShowLineNumbers=1 | |
" make sure relative line numbers are used | |
autocmd FileType nerdtree setlocal relativenumber | |
autocmd VimEnter * call StartUp() | |
" ale | |
map <C-e> <Plug>(ale_next_wrap) | |
map <C-r> <Plug>(ale_previous_wrap) | |
" tags | |
map <leader>t :TagbarToggle<CR> | |
" copy, cut and paste | |
vmap <C-c> "+y | |
vmap <C-x> "+c | |
vmap <C-v> c<ESC>"+p | |
imap <C-v> <ESC>"+pa | |
" search for thing under visual selection by marking and tying // | |
vnoremap // y/<C-R>=escape(@",'/\')<CR><CR> | |
" disable autoindent when pasting text | |
" source: https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode | |
let &t_SI .= "\<Esc>[?2004h" | |
let &t_EI .= "\<Esc>[?2004l" | |
function! XTermPasteBegin() | |
set pastetoggle=<Esc>[201~ | |
set paste | |
return "" | |
endfunction | |
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() | |
" Function to automatically remove all trailing whitespaces. Does not remove | |
" newline though! | |
fun! TrimWhitespace() | |
let l:save = winsaveview() | |
keeppatterns %s/\s\+$//e | |
call winrestview(l:save) | |
endfun | |
command! TrimWhitespace call TrimWhitespace() | |
" Spelling setting | |
set spell spelllang=en_us | |
" tab-completion | |
set wildmode=longest,list,full | |
set wildmenu |
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
" Forked from https://gist.github.com/chris-marsh/a482db63f8fdb42a05d5966b494d15dc | |
set nocompatible | |
filetype off | |
set shell=/bin/bash | |
set hidden " opening new file hides current instead of closing | |
set nowrap " switch off line wrapping | |
set tabstop=4 " Set tabs to 4 characaters wide | |
set shiftwidth=4 " Set indentation width to match tab | |
set expandtab " Use spaces instead of actual hard tabs | |
set softtabstop=4 " Set the soft tab to match the hard tab width | |
set backspace=indent,eol,start " Make bs work across line breaks etc | |
set autoindent " Enable basic auto indentation | |
set copyindent " Preserve manual indentation | |
set number | |
set relativenumber | |
set shiftround | |
set showmatch | |
set ignorecase | |
set smartcase | |
set smarttab | |
set hlsearch | |
set incsearch | |
set history=1000 | |
set undolevels=1000 | |
set wildmenu | |
set wildcharm=<Tab> " Needed to open the wildmenu from shortcuts | |
"set clipboard=unnamed " Use system clipboard, bonus copy/paste between local & SSH | |
set wildignore=*.swp,*.bak,*.pyc,*.class,*.o | |
set title | |
set ruler | |
set novisualbell | |
set noerrorbells | |
set lazyredraw | |
set laststatus=2 | |
set cursorline | |
set colorcolumn=100 | |
set background=dark | |
set encoding=utf-8 | |
" setup undo | |
if empty(glob('~/.vim/undo')) | |
silent !mkdir -p ~/.vim/undo | |
endif | |
set undodir=~/.vim/undo// | |
" setup backup | |
if empty(glob('~/.vim/backup')) | |
silent !mkdir -p ~/.vim/backup | |
endif | |
set backupdir=~/.vim/backup// | |
" setup swp | |
if empty(glob('~/.vim/swp')) | |
silent !mkdir -p ~/.vim/swp | |
endif | |
set directory=~/.vim/swp// | |
set swapfile backup undofile | |
" netrw file browser settings | |
let g:netrw_banner=0 " Hide the directory banner | |
let g:netrw_liststyle=3 " 0=thin; 1=long; 2=wide; 3=tree | |
filetype plugin indent on | |
syntax on | |
colorscheme koehler | |
" Map Ctrl+[hjkl] to navigate windows vim style | |
nnoremap <silent> <C-h> <C-w>h | |
nnoremap <silent> <C-j> <C-w>j | |
nnoremap <silent> <C-k> <C-w>k | |
nnoremap <silent> <C-l> <C-w>l | |
" Map Ctrl+[arrow] to navigate windows` | |
nnoremap <silent> <C-Left> <C-w>h | |
nnoremap <silent> <C-Down> <C-w>j | |
nnoremap <silent> <C-Up> <C-w>k | |
nnoremap <silent> <C-Right> <C-w>l | |
" Increase/descrease window split size | |
if bufwinnr(1) | |
map + <C-W>+ | |
map - <C-W>- | |
endif | |
" Pageup/down will scroll half-page and center the current line on the screen | |
nnoremap <silent> <PageUp> <C-U>zz | |
vnoremap <silent> <PageUp> <C-U>zz | |
inoremap <silent> <PageUp> <C-O><C-U><C-O>zz | |
nnoremap <silent> <PageDown> <C-D>zz | |
vnoremap <silent> <PageDown> <C-D>zz | |
inoremap <silent> <PageDown> <C-O><C-D><C-O>zz | |
" F1 netrw file browser | |
" nnoremap <silent> <F1> :Explore<CR> | |
" F2 to toggle paste mode | |
nnoremap <silent> <F2> :set paste!<CR> | |
" F3 to remove all trailing whitespace | |
nnoremap <silent> <F3> :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR> | |
let mapleader="," | |
" Open netrw filebrowser in current window, with current file selected | |
let g:netrw_banner = 0 | |
let g:netrw_liststyle = 3 | |
let g:netrw_browse_split = 4 | |
let g:netrw_altv = 1 | |
let g:netrw_winsize = 20 | |
augroup ProjectDrawer | |
autocmd! | |
autocmd VimEnter * :Vexplore | |
augroup END | |
nmap <leader>e :Vexplore .<CR> | |
" Rotate windows | |
nmap <leader>r <C-w>r | |
" Quick save the current file | |
nmap <leader>w :w<CR> | |
" Insert empty line below | |
nmap <silent> <leader><CR> o<ESC> | |
" Clear search highlights | |
nmap <silent> <leader><space> :noh<CR> | |
" Close buffer without affecting splits | |
nmap <leader>d :bprevious<CR>:bdelete #<CR> | |
" Easy buffer navigation | |
nmap <leader>n :bn<CR> | |
nmap <leader>p :bp<CR> | |
nmap <leader>b :buffer <Tab> | |
" Load vimrc | |
nmap <leader>v :e ~/.vimrc<CR> | |
" Toggle/cycle line number modes | |
nmap <leader>l :call CycleLineNumbers()<CR> | |
function! CycleLineNumbers() | |
if (&number == 1 && &relativenumber == 0) | |
set relativenumber | |
else | |
if (&relativenumber == 1 && &number == 1) | |
set norelativenumber | |
set nonumber | |
else | |
set number | |
set norelativenumber | |
endif | |
endif | |
endfunc | |
" Function to automatically remove all trailing whitespaces. Does not remove | |
" newline though! | |
fun! TrimWhitespace() | |
let l:save = winsaveview() | |
keeppatterns %s/\s\+$//e | |
call winrestview(l:save) | |
endfun | |
command! TrimWhitespace call TrimWhitespace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment