Random snippets of Vim that I need to remember and use or else they will fade
:set
Print current settings - Useful to figure out tab stops etc.
Spacing + tabs #
expandtab = use spaces vs tabs
noexpandtab = use tabs vs spaces
Re-indent file after making any type of tabbing changes.
:retab
Covert tab to spaces What soft tab is used for
Text objects #
gg- Go to top of page)- Jump forward to next sentence(- Jump backwards to next sentence}- Jump forward one paragraph{- Jump backwards one paragraphcc- Delete the current line and go into insert mode
Word text objects #
emoves you to the end of a word word perfect for then issuing adawordiwdiwdelete an inside word that your cursor is sitting on.
Deleting #
Stop using d$ to delete to the end of line but use c$ instead, this puts you into auto insert mode right after deleting.
Cleanup whitespace #
We have a custom function called TrimWhiteSpace - Call that when you want to rid yourself of trailing white space. There’s also a status bar check that will display an icon if you have trailing whitespace.
Write to current file with sudo if you don’t have editing rights #
:w !sudo tee %
LSP Python but can be for other languages as well #
- gd => go to def
- ctrl-o => go back
- shift-k => signature
- space-e => show error
Editing multiple lines aka inserting something like a “-” at the front of something #
- Hit
ctrl + vto go into visual block mode. Do not confuse this withshift + vwhich will place you into visual line mode. - Select to the bottom of the selection and hit
shift + I - Add what you want to the front and hit esc. - This should then apply to all of the lines you selected.
Quickly go to the bottom of a file and add new content #
Go
- G goes to the end of the file
- Enters insert mode on a line below the current one
Quickly cutting and pasting a line right under cursor position #
- This example is cut line 23 and paste it right under the current cursor
:23t.
Deleting up to line number #
If you are on your current line and want to delete everything up to a line number:
:,126d
Surround #
Change single quotes to double
cs"'
Committing hunks with fugitive #
- Pull up Git Fugitive via
:Gitor whichkey<leader>gg - Jump to file you can use
ctrl + n >on file to expand the file for changes.- Visual select the lines of changes.
son the lines selected.cc- Fugitive shortcut for commit<leader>qor:wq
Splits #
ni -O file1 file2- Open both files in vertical splitsctrl + w + x- Swap split positionsctrl + w + w- Jump swapsvsp file- if you are editing a file and want to open another in a veritcal split- FZF - After looking up a file, if you hit
ctrl-von the file it will open in a vertical split orctrl-xwill open in horizontal split. - Resize -
ctrl=w |- Maximizes screen on current split (it’s like hiding the other split)ctrl+w =Resize things back to normal
Marks #
m + [a-z]That ism+ any letter from [a-z]:marks- Displays all your marks- Deleting a mark
:delmarks a
Jumping around using marks and backtick #
ctrl + o- This should jump back to prior location but occasionally it will open up a previous file. This might be because ofGlobal marksctrl + i- Jumps Forward- Use
backtick+.- Jump to the last edit or last change you’ve made
Shada (Shared data) file #
I leared about these file after noticing my marks persisting after I was deleting them. They are stored here: ~/.local/share/nvim/shada
Visually Selecting from current line to line number #
shift + V - 55 - G
Yanking #
Yanking lines of text and pasting below cursor Source
:10,20t.<enter>
Visual select up to line #
Stop using arrow instead use: V35G - where 35 is the line number you want to select up to.