5 ms·
I got pretty proficient at vim using basically the defaults (I added tabs to spaces and tab width to 4 spaces, and auto/smart indent in the .vimrc). These are t
by gamegoblin 13y ago
I got pretty proficient at vim using basically the defaults (I added tabs to spaces and tab width to 4 spaces, and auto/smart indent in the .vimrc). These are the keys I use regularly. If you can memorize these, you can use vim proficiently:
h/j/k/l (movement keys)
i (insert mode)
esc (leave current mode/go to default state)
u (undo)
>> / << (indent, unindent)
dd (delete line)
yy (copy line)
p (paste)
v (visual mode, used to highlight stuff)
gg (go to beginning of file)
G (go to end of file)
r (replace the char under the cursor with the next char entered)
% (jump to next paren/bracket, or if on a paren/bracket, jump to matching paren/bracket)
w (go to next word)
dw (delete word)
cw (change word (deletes the word then goes into insert mode))
A (append (goes to the end of the line and into insert mode)
0 (go to beginning of line)
$ (go to end of line)
/some_word (searches for some_word, hit n to jump to the next occurrence)
?some_word (searches for some_word, in reverse direction)
Common commands:
:%s/regex/replacement/g (replace regex matches with replacement)
:q (quit)
:q! (quit without saving)
:w (save)
:wq (save then quit)
:x (save then quit)
:set blah (turns on setting blah)
:set noblah (turns off setting blah)
Most vim commands you can stick a number N before to execute N times.
e.g. 5d deletes 5 lines. 5y copies 5 lines. 5> indents 5 lines. 5j jumps down 5 lines. Some common command combinations:
%v%> (jump to next bracket, go into visual mode, jump to next bracket (highlighting everything in between), then indent it all)
ggdG (jump to top, then delete everything to the end of file, (clears a file))
ddp (deletes a line of text and then pastes it (below where it currently it), thus this transposes two lines)
You can see how you quickly develop strings of commands you rattle off by chaining basic commands together.
EDIT (joke):
Q. How do you algorithmically generate a cryptographically strong random string?
A. Put a newbie in front of vim.
- dmix 13y agoI have a scenario that I need help with in VIM: switching between 2-3 files while working on them simultaneously. For ex: working on an HMTL+CSS+JS documents all at once. Assuming smaller screen where I can't have a vsplit screen. How to I jump between them quickly? Buffers/tabs? I love VIM but I haven't found a good tab/file switching solution. In Textmate tabbing was straight-forward. VIM doesn't seem well suited for tabs (especially with things like NERDTree and control-p).
- Neliel 13y agoIf you use tabs, you can use gt and gT in normal mode to switch to the next and previous tabs, respectively.
- pilgrim689 13y agoI don't have any plugins for this stuff. I just do: nnoremap <Leader>b :buffers<CR>:buffer<Space> nnoremap <Leader>n :bn<CR> nnoremap <Leader>p :bp<CR> My <Leader> is space. So "space+b" opens up my buffers, I type a few letters that match a file and Tab to autocomplete it, then press enter to open it. I also use ctrl+shift+6 to quickly switch between the 2 most recent buffers. So I'd give that a shot. If that doesn't work for you, try just ":tabe <file>" for your three files, then ctrl+pageup, ctrl+pagedown (or gt, gT) to quickly switch between them.
- dmix 13y agoThanks this is working for me. I just switched b/p (since I use p w/ ctrl-p as a fuzzy finder to list all files).
- gamegoblin 13y agoTo be honest, I usually just have several terminals open and I alt-` (ubuntu) between them. I have a friend who has a sweet setup with gvim that has a lot of tab and file management tools, so you might look into gvim, but I don't use it.
- eieio 13y agoI swear by tabbar[1] as well as a few bindings to make switching between buffers faster. Specifically: map <C-n> :bn<Cr> map <C-p> :bp<Cr> It probably helps that I've mapped caps-lock to ctrl so using ctrl is very convenient for me. [1] http://www.vim.org/scripts/script.php?script_id=1338 http://www.vim.org/scripts/script.php?script_id=1338
- bgar 13y agoTabs in vim are different to tabs in other programs. You should be using buffers. This[1] StackOverflow answer is excellent. I use a plugin[2] to view my buffers in a bar. 1: http://stackoverflow.com/a/103590/1212338 http://stackoverflow.com/a/103590/1212338 2: https://github.com/bling/vim-bufferline https://github.com/bling/vim-bufferline
- SomeCallMeTim 13y agoHuh. I know almost all of those key bindings in vim, because I have to use vim when I'm editing over ssh. And that brings me to about 20% efficiency compared to what I can do with a modern text editor (I don't use Sublime, but another GUI IDE -- which one doesn't matter, except that it's not Eclipse). So I guess there are different levels of "proficiency" of editor use? On a related note: I've never understood the fixation with being able to enter numbers into vim. I almost never know the exact number of characters or lines I need to move/delete/indent/whatever, but key repeat is fast enough to "replay" or redo an action that I'm likely done with it before I would have figured out the exact number. I like the general concept of being able to "program" an editor with strings of commands. But in practice I'm much faster with the GUI approach. As a bonus, all of the commands I need to know to edit text in a Firefox window, or in any other window in a GUI-based OS, also follow the GDI standards, so I get a base level of efficiency in whatever program I need to enter text in. VIM is great for editing over ssh. When I have no choice. But I feel seriously handicapped having to use ONLY the basics to move around, copy, paste, and edit, when I'm used to having much more powerful functionality at my fingertips.
- gamegoblin 13y agoI guess it's also one thing to know them, and one thing to be comfortable typing them in a nonstop flow of text. My keystroke speed rarely changes from insert mode to control mode; vim commands have become an integral part of my typing process. I feel severely gimped whenever I can't use my vim controls. As for knowing the number of lines you need to jump, either do :set number and be quick at math, or you can modify the numbers to be relative to your current line. I took me probably a week to be able to actually get anything done in vim, and a month to prefer vim to anything else. That being said, I know far more commands than the ones I listed. Those commands got me to my first month, though.
- gingerlime 13y agoI think the number thing can be confusing, and it is hard to think in terms of 'delete the following 5 lines'. For those things I tend to use visual mode and highlight (still think keyboard-based selection is faster than with a mouse most times). I also have a shortcut for a 3-way toggle using F2 - so I can either see absolute, relative or no line numbers at all. I don't use it much, but it can be handy at times. function! NumberToggle() if(g:numberstate == 0) set number let g:numberstate=1 elseif(g:numberstate == 1) set relativenumber let g:numberstate=2 else set nonumber set norelativenumber let g:numberstate=0 endif set foldcolumn=0 endfunc let g:numberstate=0 nnoremap <F2> :call NumberToggle()<CR>
- suhastech 13y agoThis one post had me learn a lot better than any fancy game or blog post about vim. Thank you.
- tsironakos 13y agoI do suggest although you read the "Practical Vim" book, it has some real scenarios in there.
- gamegoblin 13y agoAnything to spread the gospel of vim.
- walshemj 13y agoKids to day I first hear a similar joke and the editor in question was TECO.
- IanCal 13y agoThe ones I find most useful while coding are ci" ca) The i and a here are "in" and "around" So you can be anywhere inside a quote and do "change inside quotemark" and it'll delete everything inside and leave you in insert mode. "around" would delete everything inside and the quotemarks. These can be used with other things, parentheses, square brackets (and I think some plugins extend it to html tags and the like). Of course, you can swap out c for d, y or any of the other verbs. Working in clojure and deleting everything inside a particular level of nested parentheses is awesome.
- alanning 13y agoOne nice little extra is that your cursor doesn't even have to be inside the string for the command to work.