INDEX
########################################################### 2024-01-12 15:40 ########################################################### Luke smith... Misc videos on vim https://www.youtube.com/playlist?list=PL-p5XmQHB_JSTaEPygu1DZjuFfb704Uv7 Can define macros to repeat tasks in vim qv # record macro on letter "v" {O\begin{verse}ESC # Go to start of paragraph and insert text }O\end{verse}ESC # Go to end of paragraph and insert text kkV{jj # Move up 2 lines, select mode (whole line), move to line 2 in paragraph (selected) :norm A \\ # On each line selected, run "insert \\" }jzzq # Move to start of next paragraph, center screen and end the macro @v # Repeat macro Say you want to format footnotes "(1234)" into latex form qfdi( # Record macro - Cut out text in brackets ^CTRL-r") # Go to start of line, go to line with that text (e.g. 1234) daW # Delete around word, leaving just the actual footnote content D'' # Cut to end of line and go back to previous position /() # Search for empty brackets (where footnote was extracted from) la\footnote{}ESChp # Move, insert "footnote {}" text, move, and paste footnote text inside {} F)da( # Find ")" and delete around () to delete () /([0-9]\+)q # Search for next footnote like (1234) or (1) - and end macro 10@f # Repeat macro 10 times - once it stop matches it ends # Could also run @f inside the macro to make it recursively run to the end Another thing you can do is "." repeats your last command :g/^@/m$ # Globally (for all lines) move lines starting with @ to the end :earlier 10m # Go back to changes from 10 minutes ago :later 10m # Go forward (undo "earlier") - can even do hours Use "plugged" to manage vim plugins in .vimrc call plug#begin('~/.vim/plugged') Plug '...' # Line for each plugin name call plug#end() :PlugInstall :PlugUpdate # goyo plugin centers text in vim - more readable # vimagit plugin manages git using vim (commit changes by writing config lines) # vimwiki plugin lets you view vim wiki set number relativenumber # Shows line number relative to current position set wildmode=longest,list,full # Autocomplete on vim command line autocmd FileType * setlocal formatoptions-=c ...-=r ...-=o # Turn off auto commenting set splitbelow splitright # Split vim to the right/below by default # Use "map" to set your own keybinds map <leader>o :setLocal spell spelllang=en_us<CR> # Turn on spell checker map <leader>s :!clear && shellcheck %<CR> # Check a script for issues/posix compliance # Sometimes need to force vim to load certain files as certain formats let g:vimwiki_ext2sysntax = {'.markdown': 'markdown'} autocmd BuffRead,BuffNewFile *.tex set filetype=tex # Copy selected text to system keyboard (requires "gvim") vnoremap <C-c> "*Y :let @+=@*<CR> map <C-p> "+P autocmd BuffWritePre * %s/\s\+$//e # Remove trailing whitespace from files Can turn vim into an IDE for html by using keybinds and macros # .vimrc set nocompatible filetype plugin on syntax on # Map "space-space" to find <++>, delete it (to empty buffer) and go to insert mode inoremap <Space><Space> <Esc>/<++><Enter>"_c4l # Map ";i" to wrapping text in <em> (emphatic) tags - but only for html files autocmd FileType html inoremap ;i <em>/</em><Space><++><Esc>FeT>i #
Mental Outlaw... Configure VIM https://www.youtube.com/watch?v=nOhlk3mpgmM Use .vimrc to manage everything - can set colour XResources (to be universal) set hlsearch # When searching, highlight all results set incsearch # When searching, highlight as you type set clipboard=unnamedplus # Now clipboard is shared between vim and system set tabstop=4; set softtabstop=4; set shiftwidth=4 # Set tabs to 4 spaces set expandtab; set autoindent; set fileformat=unix # Force use spaces over tabs set nocompatible # Required for vim to work normally on windows syntax on # Turn on syntax highlighting set encoding=utf-8 # Set text encoding to normal set wildmode=longest,list,full # Turn on autocomplete with ctrl-n # CTRL-w v and CTRL-w h split the vim window - move with CTRL-w arrow keys nnoremap S :%s//g<Left><Left> # "S" does global search nnoremap <silent> <C-t> :tabnew<CR> # "CTRL-t" open a new vim tab map <S-Insert> <C-i> # Map shift-insert (paste system clipboard) to CTRL-i