14 Vim
14.1 Exit and Save
:xexits and saves:wsaves without exit:w filenamesaves file as filename:q!exits without save
14.2 Run commands
:!CMDwhere CMD is command. e.g.., !ls
14.4 Inserting
iInsert text before the cursoraInsert text after cursorAAppend text to end of current line. -IInsert text at beginning of line.oOpen blank line below cursor for text. -OOpen blank line above cursor for text.pputs the Vim register (from delete) after cursor (if full line, on next line).rxreplaces the character at the cursor with ‘x’Rreplaces multiple characters. Type ESC when done.cedeletes until end of word and places you in insert. Press ESC when donec$deletes until end of line and places you in insert. Press ESC when done:%s/old/new/gc- replaces old with new in full doc with prompt for replace.:r filenameto insert text in filename above cursor
14.5 Deleting
xdeletes the character under the cursordwdeletes from cursor to start of next word (including space spearator).d2wdeletes from cursor to end of second word, etc.dedelets from curors to end of current fordddeletes the line.2dddeletes two lines.d$deletes from cursor to end of line.uto undo the last command.CTRL-Rfor redo -Uto undo all fixes on a line.
14.6 Spell check
:set spell– Turn on spell checking:set nospell– Turn off spell checking]s– Jump to the next misspelled word[s– Jump to the previous misspelled wordz=– Bring up the suggested replacementszg– Good word: Add the word under the cursor to the dictionaryzw– Woops! Undo and remove the word from the dictionary
14.7 Search in VIM
/textto search forward for text. Type ENTER to exit to that text.?textto search backward for text.nto find next instance of text (after ENTER)Nto find previous instance of text (after ENTER)
For search and replace
- `%s/
/ /options  - options include 
gfor replace all,cfor confirmation andifor case insensitive 
14.8 Visual selection
vto select text. Move cursor around with hjkl keys- then 
dto delete (can later p(ut) it somewhere if needed) - or 
yto yank (copy) so you can later p(ut) it somewhere - or 
wto write to separate file 
14.9 Copy
yto yank (copy) selction (use with v for visual selection)ywto yank a wordyyto yank a line
14.10 Working with multiple files
Vim can open multiple files in separate buffers. This can be done at the start by providing multiple filenames to vim (e.g., vim file1.md file2.md)
Alternatively, additional files can be opened for editting later (:e file2.txt).
Moving between buffers
bnmoves to next bufferbpmoves to previous buffer:buffersdisplays all open buffers: buffer 1allows switch to buffer 1 (or any other number) if there are many buffers open:bddeletes the current buffer. Will fail unless buffer has first been saved (or no changes made)
yank/delete/put will work between buffers
14.11 Command line in VIM
Switch to command line from normal mode by typing :
You can then use:
pwdto print the current working directorcdto change the working directory for the vim shelllcdto change the working directory for the specific buffer you are in
14.12 Render files
We tend to use either md or qmd files for writing, code, etc. Our .vimrc file turns on markdown highlighting for these files if saved with .md or ..qmd extensions. qmd is preferred because it works with RStudio as well.
These files can be rendered to html or pdf if desired.
quarto render file.qmdto render to htmlquarto render file.qmd --to pdfto render to pdf
We can use a full yaml header for more fancy output. We have templates for apa manuscripts, letterhead, and a generally nice format pdf output if desired. Just paste the yaml at the top of the file.
14.13 Installing plugins
If the plugin is on github, simply clone it using the github url into the vim plugin folder: /home/jjcurtin/.vim/pack/vendor/start
And you are done!
14.14 Learing VIM
run
vimtutorbooks: https://iccf-holland.org/vim_books.html