Last active
July 28, 2023 01:32
-
-
Save orvn/afdd881fba9223a19a32e8224056f28c to your computer and use it in GitHub Desktop.
A minimal and portablel vi configuration, to make CLI a little more usable. Additionally there are some comments at the bottom as reminders of important vi key bindings.
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
""" A minimal, portable vi configuration, use in ~/.exrc or ~/.vimrc """ | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function! ResetOsTheme() | |
" Detect current macOS theme | |
let l:os_theme = system("defaults read -g AppleInterfaceStyle 2> /dev/null") | |
" Adjust Vim settings based on macOS theme | |
if l:os_theme == "Dark\n" | |
" Set Vim to dark theme settings | |
set background=dark | |
highlight Comment ctermfg=Gray | |
highlight Constant ctermfg=Blue | |
highlight Normal ctermfg=White | |
highlight NonText ctermfg=White | |
highlight Special ctermfg=DarkMagenta | |
highlight Cursor ctermfg=Green | |
highlight LineNr ctermfg=DarkGray | |
highlight Search ctermfg=White ctermbg=Blue | |
else | |
" Set Vim to light theme settings | |
set background=light | |
highlight Comment ctermfg=DarkGray | |
highlight Constant ctermfg=DarkBlue | |
highlight Normal ctermfg=Black | |
highlight NonText ctermfg=Black | |
highlight Special ctermfg=DarkMagenta | |
highlight Cursor ctermfg=Green | |
highlight LineNr ctermfg=Gray | |
highlight Search ctermfg=Black ctermbg=Yellow | |
endif | |
endfunction | |
" Compatibility, run with -u to override | |
if &compatible | |
set nocompatible | |
endif | |
" Try to identify the indenation of file type for use | |
if has('filetype') | |
filetype plugin indent on | |
endif | |
" Enable syntax highlighting if available for file type | |
if has('syntax') | |
syntax on | |
endif | |
" Customize visual appearance based on OS theme | |
call ResetOsTheme() | |
set hlsearch | |
" Status and command line bar adjustments | |
set wildmenu | |
set showcmd | |
set cmdheight=2 | |
set laststatus=2 | |
" Faster mode timeouts | |
set notimeout ttimeout ttimeoutlen=200 | |
" Case insensitive search | |
set ignorecase | |
set smartcase | |
" Confirmation dialog | |
set confirm | |
" Additional tab, spacing and indentation behavior | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 | |
set expandtab | |
set autoindent | |
set backspace=indent,eol,start | |
"""""""""""""""""""""""""""""""""""""""""""" | |
""" Additional features and usability tweaks | |
"""""""""""""""""""""""""""""""""""""""""""" | |
" Show which mode vi is in | |
set showmode | |
" Show cursor position | |
set ruler | |
" Show line numbers | |
set number | |
" Don't jump to the start of the line when switching lines | |
set nostartofline | |
" Use mouse navigation, if available | |
if has('mouse') | |
set mouse=a | |
endif | |
" Use visual bell instead of chime for errors | |
set visualbell | |
""""""""""""""""""""""""""""""" | |
""" Useful vim syntax reminders | |
""""""""""""""""""""""""""""""" | |
" hjkl = arrows for original qwerty keyboard that didn't have arrow keys | |
" 0 = start of line | |
" $ = end of line | |
" w = next word | |
" b = preceding word | |
" (Using the keyboard arrow keys in conjunction with the shift key may also do this) | |
" ^u = Up half screen | |
" ^d = Down half screen | |
" :0 = first line | |
" :n = nth line | |
" :$ = last line | |
" i = insert at cursor | |
" A = end of line | |
" I = insert start of line | |
" u = toggle undo | |
" x = delete single char | |
" D = delete rest of line | |
" dd = delete line | |
" ndd = delete n lines | |
" yy = yank line (copy) | |
" P = paste | |
" nyy = yank n lines | |
" /foo = search foo | |
" ?foo = search backwards | |
" n = next result | |
" N = previous result | |
" ^g = line count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment