Last night I have finished re-reading Drew Neil’s “Practical Vim” and I gathered a whole lot of little things that I want to try, and include in my workflow if they fit.
Normal mode
- {number}G — go to that line
- @: — repeat the last ex-mode command
- = — autoindent
- g;/g, — navigate change list
- gi — back to last insertion in insert mode
Insert mode
-
{register}, e. g. 0 to paste the text that I just yanked, as if it were being typed one character at a time; 0 inserts text literally. -
{any one normal mode command} -
=6+35 -
— filename completion -
— current buffer keywords -
— included file keywords; see :h 'include' -
— whole line completion -
— omni-completion; see :h compl-omni-filetypes -
— revert to the originally typed text (exit from autocompletion) -
— trick: The first command invokes autocomplete, summons the pop-up menu, and selects the first item in the word list. The second command selects the previous item in the word list, taking us back to where we started but without dismissing the pop-up menu. Now we can continue to type, and Vim will filter the word list in real time. -
— :h 'complete’ -
/ — insert the last search pattern
Visual mode
- o — go to other end of highlighted text
Ex commands
- :setlocal makeprg=NODE_DISABLE_COLORS=1\ nodelint\ % — use this to not need jshint/csslint/tidty in every project¹.
-
{register} -
— insert the word under cursor - read !ls -la — read the output from a shell command into the current buffer
- %write !sort — pass the range to the shell command and insert into the current buffery
-
mapping to switch to the command-line window, preserving a copy of the command that was typed at the prompt - :read !{cmd} — direct standard output into a buffer. As you might expect, the :write !{cmd} does the inverse—is this useful with pbcopy?
- :2,$!sort — sort the lines in a given range
- :argdo {ex cmd} — execute the ex command for all the files given as CLI args
- :edit %:h
— is expanded to the full path of the current file’s directory - :w !sudo tee % > /dev/null — or maybe :w !sudo cat > % — write a file that needs sudo, for example /etc/hosts
- :& — repeats the last :substitute command (see :h:&), the g& command is a handy shortcut
- :vimgrep /
// \*/.txt - :global — check chapter 15 for thoughts on implementing code refactorings
Windows
-
\_ — maximize the current window
General
- runtime macros/matchit.vim — match opening and closing XML tags with %
Finding files
- :set path+=app/**
- :find ticket
Search
- /\Vverbatim text — except / and \
Check
- :h digraph-table
- :h motion.txt
- :h text-objects
- :h function-list
- :h :s_flags
- :h g&
- :h popupmenu-completion
- :grep -i Waldo *
- :h option-list
- :h filename-modifiers
¹ Some time ago I was wondering how should I set my linting system: I considered a separate repository with makefiles, a separate npm package on GitHub, even looked at other editors and IDEs. The :make and :compile in Vim seem to be a promising option. =]
:make, :compile, and :grep act as a level of abstraction and lets you change the underlying tools without having to also change editing habits.