[VIM one-liners] Useful VIM one-liners #vim #oneliner
# open up current file (useful for opening markdowns in chrome)
:!open %
# search across folder tree for test
# From within buffer at top most level of folder tree to search
:grep '<searchstring>' **/*.<fileending to search> or grep -R <searchstring> . to recursievely search all files in project
:copen to open the quickfix list, and :ccl to close it
:cn to go to the next on the quickfix list
:cp to go to the previous
# OR
# use Ripgrep (brew install ripgrep with jremmen/vim-ripgrep)
:Rg <search-string/pattern>
# OR
# use vimgrep to use vim's search patterns (lvimgrep use locaiton list instead which is basically same as quickfix)
:vimgrep /search_pattern/ **/*
# open up multiple files as tabs from terminal
vim -p *.txt
# pipe into vim
ls -1 | vim -
# spellcheck
:setlocal spell/nospell
[s ]s # move forward and backwards between misspellings
z= # provide potential alternatives for mistakes
# search repalce on arglist of files
:ar *.py #assemble arglist with wildcards for names of files
:argdo %s/old/new/g | update #do search replace and then write the buffer
# case sensitive search replace
%s/<old>/<new>/gI (or end with gcI to ask each time for confirmation)
# run awk on the selected area and replace with the results
:'<'>!awk 'BEGIN{FS=","} {print $5}' # would select out fifth column of csv file
# run column on the whole file to convert output to pretty-printed table
:%!column -s , -t # will convert csv to white-space delimited table with nice spacing, -s $'\t' will delimit on tabs