|
|
|||||||||||||
set whichwrap=h,l,~,[,]In many applications (Netscape Navigator, Lynx, Mutt, Pine, SLRN, More, and Less), <Space> scrolls down a page. When reading files with Vim (particularly when instigated as
view or gview)
I often found myself trying to use <Space> to page down.
Since <Space> by default is yet another key for moving
the cursor right, it seemed sensible to remap it:
noremap <Space> <PageDown>Applications vary between using BkSpc or - to page up, but since there are plenty of other keys for moving both left and up, I remapped them both:
noremap <BS> <PageUp> noremap - <PageUp>In Lynx it is possible to scroll the window by a couple of lines, leaving the cursor at the same text, with <Ins> and <Del>. (This choice of keys isn’t as barmy as it first sounds after noticing how the <Ins>/<Del> pair are situated next to the <Home>/<End> and <PgUp>/<PgDn> pairs.) Normally these only duplicate i and x do, so can safely be remapped:
noremap <Ins> 2<C-Y> noremap <Del> 2<C-E>To cycle through panes of split windows, I use <F6> (cos that’s what that keystroke does in the CUA definition, still used in many Windows applications), which is more convenient than the default of <Ctrl>+Ww. Cycling backwards with <Shift>+<F6> only generally works in the gui, not in terminals:
nnoremap <F6> <C-W>w nnoremap <S-F6> <C-W>WIf viewing a large number of files (perhaps with
gview *), switching between them can be tedious.
Remapping <Ctrl>+N and <Ctrl<+P helps
with this, and is also mnemonic:
nnoremap <C-N> :next<CR> nnoremap <C-P> :prev<CR>(By default these keystrokes respectively move down and up one line. It is unclear why anybody thought this was necessary, given that there are several simpler (IE unchorded) keystrokes already providing these functions; I can’t think of any situation in which it is easier to press <Ctrl>+N than j.) The % keystroke is useful for bouncing around pairs of various sorts of brackets. It can be made to work for angled brackets as well:
set matchpairs+=<:>
nnoremap <F1> :help<Space> vmap <F1> <C-C><F1> omap <F1> <C-C><F1> map! <F1> <C-C><F1>The required help topic can then be entered at the prompt (using command-line completion if necessary). The original function of <F1> can be obtained with <F1><Enter>.
nnoremap Q gqap vnoremap Q gqThese mappings allow the <Ctrl>+T and <Ctrl>+D keystrokes to adjust the indent of selected text (in the same way that they do with single lines in insert mode), and for <Tab> and <Shift>+<Tab> (where it works) to do the same thing:
vnoremap <C-T> > vnoremap <C-D> <LT> vmap <Tab> <C-T> vmap <S-Tab> <C-D>Y by default is incongruous with C and D, in that it yanks a complete line (duplicating yy) rather than yanking to the end of the line. This fixes that:
noremap Y y$
The paste option is intended for invoking temporarily while
pasting in text. It avoids things like autoindent causing
‘stepped’ text. This defines the \tp
(“toggle paste”) mapping, also set to <F4>
in both normal and insert mode:
nnoremap \tp :set invpaste paste?<CR> nmap <F4> \tp imap <F4> <C-O>\tp set pastetoggle=<F4>This defines \tf (“toggle format”) and <F2> to toggle whether lines should automatically be wrapped as they are typed:
nnoremap \tf :if &fo =~ 't' <Bar> set fo-=t <Bar> else <Bar> set fo+=t <Bar> \ endif <Bar> set fo?<CR> nmap <F3> \tf imap <F3> <C-O>\tfThis defines \tl (“toggle list”) and <F2> to toggle indicating non-printing characters:
nnoremap \tl :set invlist list?<CR> nmap <F2> \tlThis defines \th (“toggle highlight”) to toggle highlighting the most-recently-found search text:
nnoremap \th :set invhls hls?<CR>
set backspace=eol,start,indent<Tab> can be used to insert spaces to indent lines to
shiftwidth, rather than insert tab characters. This is
generally more useful, and avoids setting tabstop to
something other than 8 (which is Bad when sharing files with other people
or programs that are used to it being 8). Indentation can be changed
with the cursor anywhere in a line. Here are the mappings — the <Shift>+<Tab> one probably only works in the gui:
inoremap <Tab> <C-T> inoremap <S-Tab> <C-D>Note that so long as sensible makefile settings are used, this will not prevent <Tab> from inserting tab characters in them. In any file, a genuine tab character can be inserted at the cursor position with <Ctrl>+V<Tab>.
Useful abbreviations can be set up for anything you type often. I tend to end mail and news postings with sm, which automatically expands itself to “Smylers” as soon as <Esc> is pressed:
iabbrev lfpg Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch iabbrev hse he/she iabbrev sm Smylers
Defined elsewhere are mappings for spell-checking, which all start \s, and mappings useful when editing HTML files, which all start \h.
Some of these mappings are also assigned to function keys, which are obviously faster to press than three-character mappings, but since function keys don’t always work (particularly when using Vim over a telnet session), these are in addition to the \ mappings.