Created
September 15, 2022 04:25
-
-
Save luiarthur/147d07feb77fd2c24e8aee699bb2f84a to your computer and use it in GitHub Desktop.
Single script init.vim for native windows
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
""" This file belongs in ~/AppData/Local/nvim/init.vim. Create if necessary. | |
""" Made for Windows OS. | |
""" Make sure that ~/AppData/Local/nvim/autoload/plug.vim contains a copy of plug.vim. | |
""" 1. Plugins | |
" NOTE: This script requires vim-plug. | |
" See: https://github.com/junegunn/vim-plug | |
" Install vimplug if needed. | |
" let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' | |
" if empty(glob(data_dir . '/autoload/plug.vim')) | |
" silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | |
" autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | |
" endif | |
" Specify a directory for plugins | |
" - For Neovim: stdpath('data') . '/plugged'. | |
" - Avoid using standard Vim directory names like 'plugin'. | |
call plug#begin(stdpath('data') . '/plugged') | |
" Add plugins here, then install by running `:PlugInstall` in vim. | |
" Make sure you use single quotes. | |
Plug 'godlygeek/tabular' " Auto Indent | |
Plug 'plasticboy/vim-markdown' " Markdown | |
Plug 'sheerun/vim-polyglot' " Syntax highlighter for many languages | |
Plug 'tmux-plugins/vim-tmux' " tmux | |
Plug 'octol/vim-cpp-enhanced-highlight' " C++ | |
Plug 'preservim/nerdtree' " file system explorer | |
" Plug 'neovim/nvim-lspconfig' " Language Server Protocol | |
Plug 'nvim-lua/completion-nvim' " Auto completion | |
Plug 'airblade/vim-gitgutter' " Add git diffs on side | |
Plug 'tpope/vim-fugitive' " Git utilities | |
Plug 'bling/vim-bufferline' " Display tab info | |
" Plug 'luiarthur/tmux.vim' " For REPL integration while editing. | |
Plug 'luiarthur/red.vim' " My personal colorscheme. | |
Plug 'JuliaEditorSupport/julia-vim' " Needs to be installed for unicode. | |
Plug 'luiarthur/repl.nvim' " REPL launcher for neovim | |
Plug 'luiarthur/vim-map-alt' " Use <ALT>+{hjkl} to move between windows in any mode | |
call plug#end() " Initialize plugin system | |
""" 2. Basic stuff. | |
" Ergo alias. | |
map <S-f> <C-w> | |
" NeoVIM stuff | |
set laststatus=0 ruler " Hides the status bar. The airline plugin seems to ignore this. | |
set splitbelow " vertical splits create windows below by default. | |
set splitright " horizontal splits create window to the right by default. | |
set mouse=a " enable copy / paste using mouse, while in vim. | |
set fillchars=stl:- " fill active window's statusline with - | |
set fillchars+=stlnc:- " also fill inactive windows' statusline with - | |
" Tab / buffer navigation. | |
map <S-Right> :tabnext<CR> | |
map <S-Left> :tabprevious<CR> | |
map <S-Down> :bnext<CR> | |
map <S-Up> :bprevious<CR> | |
" Make :q, by default, only deletes buffer. | |
" cnoreabbrev q bd<CR> | |
" Make :Q, an alias for :qa. | |
" cnoreabbrev Q qa<CR> | |
" Basic stuff | |
set number " Show line numbers on side. | |
syntax enable " Syntax highlighting | |
set hlsearch " Highlight search items | |
set incsearch " Highlight search items as you type | |
set showmatch " Show matches for parenthesis, etc. | |
set expandtab " Use softtabs | |
set tabstop=2 shiftwidth=2 " Set tab width | |
set autoindent " Automaticall indent lines | |
set nobackup " Don't create .swp | |
" set clipboard=unnamedplus " copy and paste to clipboard. | |
set guicursor=a:blinkon0 " disable cursor blinking | |
" Color scheme. | |
silent! colorscheme noir | |
" Terminal behavoir. | |
autocmd TermOpen * setlocal nonumber norelativenumber " Don't use line numbers in terminal. | |
autocmd TermOpen * startinsert " Enter insert mode when terminal opens. | |
autocmd BufWinEnter,WinEnter term://* startinsert " Enter insert mode after entering a terminal window. | |
autocmd BufLeave term://* stopinsert " Enter normal model after exiting terminal window. | |
" Use Escape key to leave terminal insert mode. | |
tnoremap <ESC> <C-\><C-n> | |
" Remap 'Ctrl + [' to 'Esc' | |
imap <C-[> <ESC> | |
" Indenting / unindenting in visual mode | |
vmap < <gv | |
vmap > >gv | |
vmap <s-tab> <gv | |
vmap <tab> >gv | |
" disable F1 for help | |
nmap <F1> <nop> | |
" Toggle folding with F9. | |
set foldmethod=manual " enables folding by visual selection select | |
inoremap <F9> <C-O>za | |
nnoremap <F9> za | |
onoremap <F9> <C-C>za | |
vnoremap <F9> zf | |
" Reset syntax highlight | |
noremap <F10> <ESC>:syntax sync fromstart<CR> | |
inoremap <F10> <C-o>:syntax sync fromstart<CR> | |
" Return to last position | |
augroup return_cursor_to_last_position | |
autocmd! | |
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif | |
augroup END | |
" Save and Load session. | |
function! SaveSession() | |
exec "mksession! ~/.session.vim" | |
endfunction | |
function! LoadSession() | |
exec "so ~/.session.vim" | |
endfunction | |
command -nargs=0 SaveSession :call SaveSession() | |
command -nargs=0 LoadSession :call LoadSession() | |
" Always open new files as tabs. | |
" NOTE: tabs can be close with `:bd`. | |
augroup open-tabs | |
au! | |
au VimEnter * ++nested if !&diff | tab all | tabfirst | endif | |
augroup end | |
" Maps <Alt>+{h,j,k,l} to jump to neighboring windows regardless of current | |
" mode (e.g. NORMAL, INSERT, TERMINAL), only if the luiarthur/vim_map_alt | |
" plugin is installed. | |
" Note that MacOS users should do ONE of the following: | |
" - change their Terminal Key setting so that Left-Option key (and perhaps | |
" Right-Option key) is set to `Esc+` instead of the default `Normal` mode. | |
" - replace this line with | |
" let g:vim_map_alt_mac = 1 | |
let g:vim_map_alt_linux = 0 | |
""" 3. Extend plugins. | |
" ---------------------------------- NERDTree Settings ------------------------ | |
" NERDTree Shortcut | |
nnoremap <C-n> :NERDTreeToggle<CR> | |
" If another buffer tries to replace NERDTree, put it in the other window, and | |
" bring back NERDTree. | |
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && | |
\ bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 | | |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | | |
\ execute 'buffer'.buf | endif | |
" Start NERDTree when Vim is started without file arguments. | |
autocmd StdinReadPre * let s:std_in=1 | |
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif | |
" ----------------------------------- Julia highlighting --------------------- | |
function! JuliaExtendHighligh() abort | |
syntax keyword juliaTodo contained NOTE | |
endfunction | |
au BufRead *.jl call JuliaExtendHighligh() | |
" ----------------------------------- Python highlighting -------------------- | |
function! PythonExtendHighligh() abort | |
syntax keyword pythonTodo NOTE NOTES contained | |
endfunction | |
au BufRead *.py call PythonExtendHighligh() | |
""" 4. Smart tab completion. | |
" TODO: Convert to plugin. | |
" Intelligent tab completion | |
function! InsertTabWrapper(direction) | |
let col = col('.') - 1 | |
if !col || getline('.')[col - 1] !~ '\k' | |
return "\<tab>" | |
elseif "backward" == a:direction | |
return "\<c-p>" | |
else | |
return "\<c-n>" | |
endif | |
endfunction | |
inoremap <tab> <c-r>=InsertTabWrapper ("forward")<cr> | |
inoremap <s-tab> <c-r>=InsertTabWrapper ("backward")<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment