one of us! one of us!
- 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
,/<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 I'm on, and can see how far away lines are so I can11j
for example, and so I can tell at a glance that I want to5dd
without having to stop to count. -
You can move lines with
:m
. 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 its analog to:m+1
.
Concepts that I consider to make vim great
-
registers
- https://sanctum.geek.nz/arabesque/advanced-vim-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
- https://sanctum.geek.nz/arabesque/advanced-vim-macros/
- contents of a register can be run as a macro. e.g.
"f
isgg=G
.@f
will format your entire file.
-
marks
- http://kylecoberly.com/blog/using-marks-in-vim
:marks:
to view your marks
-
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 favs:
- NERDTree
- fugitive and gitgutter
- vim-surround
- emmet-vim
- vim-airline
- 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 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
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.
Q. How many different places can I use "vim"?
A. A lot. Most text editors support vim keys, or have a "vim mode" to various degrees. Including online editors like codepen. I make prodigious use of the vimium plugin in both Chrome and Firefox for a superior browser experience.