## Part 1 ```vim " comments start with " :echo "hello" :echom "world" " shows "world" but not "hello" -- echom = echo message :messages " get help :help echo :help echom :help :messages " boolean options :set number :set nonumber " toggle with :set number! " query with :set number? " more numbers :set numberwidth=10 :set numberwidth=6 :set numberwidth? " more set :set wrap? :set shiftround? :set matchtime? " multiple :set numberwidth=2 number " more help :help 'number' :help relativenumber :help numberwidth :help wrap :help shiftround :help matchtime " shiftround when set causes shifts to round to inter mults of shiftwidth " in insert mode, Ct and Cd always round ``` ## Mappings ```vim " pressing - does the same as pressing x :map - x " and similarly :map - dd :map viw :map dd :map viw " Select word :map - ddp " there are also nmap vmap and imap " for normal mode, visual mode and insert mode " so :imap ddi " switch to normal mode, delete line and then switch back to insert mode " then the fun begins :imap " map just turns keypresses into keypresses " to unmap :nunmap / :vunmap - :iunmap " if you don't want the results of a mapping to be mapped :nmap x dd :nnoremap \ x " this doesn't get turned into x " sequences :noremap -c ahello " this uses the 'leader', which is - by default :let mapleader = "-" :noremap d dd " is whatever mapleader is set to :let maplocalleader = "\\" :help mapleader :help maplocalleader " example :nnoremap ev :vsplit $MYVIMRC " also we learn that :vsplit filename " splits vertically and opens 'filename' in the new pane :nnoreamp sv :source $MYVIMRC ``` ## Abbreviations ```vim :iabbrev mr flibble " then imr will result in flibble being input " the abbrev takes affect when you press " or but not when you press a non-whitespace char. :iabbrev teh the " poor man's spelling autocorrect " vim abbrevs when you type a non-keyword char ;set iskeyword? ``` ## More mapping ```vim :let mapleader = "," :nnoremap x imrflibble ``` then ```vim :let maplocalleader = "." " changes the leader char on a per-buffer basis " and on the subject of local :setlocal wrap :setlocal nowrap :setlocal number " and :nnoremap Q x " will override :nnoremap Q dd " as it is more specific ``` ## Autocommands ```vim :autocmd BufNewFile * :write " Event pattern command " pattern is a glob pattern like *.py, not a regex :autocmd BufWritePre *.html :normal gg=G :autocmd BufWritePre,BufRead *.html :normal gg=G :autocmd BufNewFile,BufRead *.html setlocal nowrap " insert comments :autocmd FileType javascript nnoremap c I// :autocmd FileType python nnoremap c I# " I inserts at the start of the line, whereas i inserts " at the cursor position. :help autocmd-events ``` ## Buffer Local Abbrevs ```vim :iabbrev --- — :autocmd FileType python :iabbrev iff if: ``` ## Autocommand groups ```vim :augroup testgroup : autocmd BufWrite * :echom "Baz" :augroup END " to clear :augroup testgroup : autocmd! :augroup END ``` ## Operator-Pending Mappings An operator command waits for you to enter a movement command, then does something with the text between where you are and where the movement would take you. e.g. ``` dw -- delete to next word ci( -- change inside paren yt, -- yank until comma ``` Also note **`ct,`** is how you do this, so you don't need `c/re/,` To make mappings ```vim :onoremap p i( ``` so then `dp` is equivalent to `di(`