Everyday Editing with Vim ------------------------- http://www.guckes.net/talks/vim/vim.everyday_editing.txt Latest change: Thu Apr 17 02:08:27 CEST 2008 by Sven Guckes vim_at_metalab(at)guckes(dot)net = Preview = 2008-04-17 Thu 20:20h at metalab.at Rathausstraße 6, 1010 Vienna, Austria http://metalab.at/wiki/Everyday_Editing_with_Vim -------------------------------------------------------- = Abstract = Vim has hundreds of commands and some 400 options - but everyone uses only a subset of that. Here is a glimpse on my command subset and the combinations i use more frequently. May this inspire you. :-) -------------------------------------------------------- = Undo + Redo = i tend to use undo a lot when some previously deleted text has dropped away from the numbered buffers. i go back quickly with "42u", search for the deleted text, copy it into a named buffer - and then return with "42" again. -------------------------------------------------------- = Jumps = == CTRL-O == when i jump around with searches i usually do not set marks. should i need to go back then i'll use CTRL-O for that - and CTRL-I (aka TAB) to go forward again. = Searches = Fixing typos: A typo is usually spotted by the eyes. To fix the typo you need to jump to its location - the faster, the better. of course i could move through the lines and jump a few words left and right - but mostly i just let vim search for its location by entering the typo itself. == * and # == the commands * and # search forward/backward for the current word. pretty quick and easy. == :g == :g/RE/p :g/RE/nu 21:00 -------------------------------------------------------- = Simple Changes = "dj" and "dk": Just two characters to delete the current and next/previous line. Of course you can just as easily use "yj" and "yk" to copy the current and the adjacent line. 'D': "delete rest of line" the 'D' deletes the rest of the line - just like "d$" would. pretty easy. 'C': "change rest of line" 'C' acts similar to 'D' - it deletes the rest of the line, however, it also switches from command mode to insert mode, so you can insert some new text right away. therefore remember that "changing" means "deleting and switching to insert mode". 'S': substitution of complete current line. substitutes the current line - but does not delete them. this command can be used to start over with the current line. :g/RE/d :v/RE/d :g/RE/co $ :g/RE/mo 'a = Transposition = "xp" map xp ddp = Replace = seperating a line by replacing a space with a "return". = Copy+Paste = Copying/Deleting the current word, sentence or paragraph is as easy as these: caw change current word caW change current WORD cas change current sentence cap change current paragraph daw delete current word daW delete current WORD das delete current sentence dap delete current paragraph yaw yank current word yaW yank current WORD yas yank current sentence yap yank current paragraph 22:23 = Qs = Q: how to turn of highlighting of search patterns? Q: use of utf-8.... -> neuer vortrag! Q: EOLs... Q: encoding fileencoding termencoding Q: hex view -> bvi hinweis: ga "give ascii" Windows :sp :vsp :close :only :new CTRL-W s v c o n CTRL-W hjkl CTRL-W gF = Registers = using registers for copying/deleting... set expandtab set tabstop set listchars=tab:»·,trail:· g? rot13 virtual editing visual modes license = Filters = gpg: decoding inline encrypted text piping an inline encoded text through gpg. when you are replying to such an email then the text is usually cited at first. so you have to remove the quotation signs before the encoded message. - sort: - boxes: - cowsay: = Indenting + De-Indenting = vmap > nmap >ip i_CTRL-D i_CTRL-T = Repetition = I use '.' (dot) to repeat the last command usually after a small change, eg deleting a line or word. = Visual Block = - adding or deleting comments - switching columns in wikis = Indenting = mapped F4 to indent current paragraph. = Text Formatting = mapped f5 and f6 to narrow/widen the current paragraph or visual selection. also adjusted comments to work with lines with weird commment characters. very useful for editing emails. CTRL-J mapped to adjust current paragraph to the current textwidth. = Writing = use of ":w" required the colon which is in different locations on german and us keyboard - which is three keys - dont forget the return at the end! as the comma is in the same location on both us and de keyboards i have mapped this to ",,". i almost never used the comma and semicolon commands, anyway, so the are free as additional command lead-ins. = Macro Recording = whenever i start some recording i usually use the register 'q'. So i type "qq" to start off with - and 'q' again to end. however, when i am pretty sure what i'll be doing then i will use the register 'a' for recording. macros are intended to be used again - so i could use "@a" to repeat what was recorded into register 'a' - and then use "@@" to repeat or even use "23@@" for repetition. however, i have mapped F12 to repeat the contents from register 'a'. -------------------------------------------------------- = Abbreviations = Prefix expansion is nice - except when you have included expansion from several dictionaries which can turn up hundreds of possible expansions. so whenever i think i will need a word or phrase that might pop up often within the text i am writing then i will create an alias for it. = Buffers = Switching buffers: CTRL-^ :b substring = Digraphs = insert german umlauts and french accented letters. = Marks = there are about a hundred file which i access frequently or every so often. and therefore i keep a tags file with abbreviations for them. -------------------------------------------------------- TODO Visual Mode -------------------------------------------------------- = Links = Extended Vi Cup [by Sven Guckes + Julius Plenz] http://www.guckes.net/talks/vi_cup.txt EOF