-
Notifications
You must be signed in to change notification settings - Fork 1
vim
one of us! one of us! we accept you! we accept you!
- Seven habits of effective text editing, by Bram Moolenaar, author of vim
-
hjkl
actually isn't any better than arrow keys. If you find yourself holding downl
, stop and think about what you're doing. Usef
ort
,:s/<fragment>
, or text objects to jump around. (w
,)
,}
, etc.:help objects
for more.) -
I prefer
:set relativenumber number
for line numbering. That way I can always see what line number I'm on, and can see how far away lines are so I can11j
, for example, to jump 11 lines down. And so I can tell at a glance that I want to5dd
without having to stop to count. -
You can move lines with
:m
. If you want to move the current line 7 lines up, instead ofdd7kp
, you can:m-7
. If you want Atom style moving lines up and down, remap something like Alt-k or the up arrow to:m-1
, and Alt-j or the down arrow to:m+1
.
Concepts that I consider to make vim great
-
registers
-
:reg
to view registers -
Note that
"+
is your system clipboard.gg"+yG
will yank your entire file to the clipboard. -
followed by a register will paste the contents of that register in insert mode.
-
macros
-
the contents of a register can be run as a macro. e.g. if
"f
isgg=G
,@f
will format your entire file.
-
marks
-
:marks
to view your marks
-
dot/repeat
Stuff I use a lot
-
:help
- Just read it. -
All the basic movement commands like
f
andF
,t
andT
, and:
and;
to repeat forward and backward those "find"s and "to"s -
^[
sends escape. very nice if you've mapped caps lock to CTRL -
*
Find word under cursor -
gx
Open URL under cursor. (gf
: open file path under cursor.) -
%
Find matching bracket -
>>
indent (<<
un-indent) -
^z
suspend. drop into the shell. (if you're in the terminal.) Do your stuff, thenfg
to bring vim back to the "foreground". -
H
,M
,L
jump to top, middle, bottom of screen. ("High", "Medium", "Low") -
zz
move current line to middle of screen. (see alsozt
andzb
)
Weird stuff
-
g?<dir>
- rot13.g??
a whole line
For the longest time, I didn't use any plugins. Now I do. 🤷♀️
Check out https://vimawesome.com/
A couple of faves:
-
NERDTree - file explorer
-
fugitive and gitgutter - get some git in your life
-
vim-surround - easily change/add/delete/etc surrounding characters
-
emmet-vim - HTML expander
-
vim-airline - aesthics
- keep your vimrc in a git repo. so you can pull it down where ever you are. snoop people's vimrcs on github. Here's mine: https://github.com/chrisman/dotfiles/blob/master/vimrc
-
Vimcasts! These are just great. http://vimcasts.org/
-
Giffy gifs! https://vimgifs.com/
-
wikia tips: http://vim.wikia.com/wiki/Best_Vim_Tips
-
Great video about autocompletion, registers, generally typing less: https://www.youtube.com/watch?v=3TX3kV3TICU
-
Coming Home To Vim: https://stevelosh.com/blog/2010/09/coming-home-to-vim/
Q. What kind of vim to use?
A. Use vim or neovim. (I use neovim.) Avoid using a GUI like gvim or macvim. One of the glorious things about vim in the terminal is having quick access to the command line and to UNIX utils. And being able to quickly suspend (c-z
)
and drop into a shell or into a REPL.
fix "smarty pants" formatting
:%s/’/'/e | :%s/“/"/e | :%s/”/"/e | :%s/…/.../e
swap artist - title order
:s,\(.*\) - \(.*\),\2 - \1,
search and replace in all buffers
:bufdo %s/old/new/e | update
Sometimes I want to make a table of contents including all the 2nd level headers in a markdown file:
:g/^## /t2
This copies all lines starting with ##
to line 2.
Here's all the headers (at the moment) in this file:
- Other neat stuff
- Appendix C: Macros I use often enough to have written them down
- Appendix B: FAQ
- Appendix A: Links and resources
- suggestions
- Plugins
- useful commands
- "basics"
- Movement
- Prerequisites
Oh but look, they're in reverse order 🤔
Okay well you can do the same thing by yanking to a register: qaq:g/^## /y A
(qaq
is a little hack to quickly clear the a
register since we're going to be appending to it.)
- Prerequisites
- Movement
- "basics"
- useful commands
- Plugins
- suggestions
- Appendix A: Links and resources
- Appendix B: FAQ
- Appendix C: Macros I use often enough to have written them down
- Other neat stuff
You can turn the ##
s into a numbered list using column editing.
On the first pound, <c-v>9jr0
to turn them all into zeros. Then <c-v>9jg<c-a>a
to auto increment them all. Then on the second pound, <c-v>9jr.
to turn them all into periods.
that is: ^V9jr0l^V9jr.h^V9jg^A