Vim
I'm a big fan of modal editing and specifically Vim.
- This is a pretty good video to show some magic of Vim and it is very funny to boot! This would be mycurrent video of choice to show someone the power of Vim at the hands of an advanced user.
- but his channel full of Vim tips and tricks.
- Map
CapsLock
toEsc
- ! Swap caps lock and escaperemove Lock = Caps_Lock! keysym Escape = Caps_Lockkeysym Caps_Lock = Escapeadd Lock = Caps_Lock! Press both Shift keys to get Caps_Lockkeycode 50 = Shift_L Caps_Lock Shift_L Caps_Lockkeycode 62 = Shift_R Caps_Lock Shift_R Caps_Lock
- On macOS this could be done via settings -
- Appending result from an external command to the buffer - https://vim.fandom.com/wiki/Append_output_of_an_external_command
read !<external command>
For example, to get CPU info into the current buffer,read !cat /proc/cpuinfo
. - Format JSON,
- with
python
-:%!python -m json.tool
- with
jq
tool -:%!jq '.'
- " settings for tabs:set tabstop=2 shiftwidth=2 expandtab" convert the existing buffer:retabAnother option to would be to reindent the whole file with
gg=G
. - Enabling mouse scroll support - https://stackoverflow.com/questions/7225057/use-mouse-scroll-wheel-in-vim.set mouse=a
- Opening files based on a command line search. This is more of a command line tip, but I find this pattern to be quite useful. To open all Dockerfiles in a directory,vim $(fd Dockerfile ~/Code)Another adaptation of this pattern is to use a temporary vim buffer to put the search results and then open files based from buffer contents.fd Dockerfile ~/Code | vim -# Then open files one by one based on the contents (which could be empty if# the search results are empty). Opening buffers for file locations is a# pretty easy in Vim with Vim unimpared commands like `gf` in normal mode
- Write a file as superuser,:w !sudo tee %
Last modified 3yr ago