<< Back to wiki homepage

Table of contents:

Map ctrl-right/left to the next word

Your key mapping can be different, find out with pressing ctrl-v on an empty

terminal and pressing ctrl-right/left afterwards

map <ESC>[1;5C <C-Right>
map <ESC>[1;5D <C-Left>

ctrl-right/left should also pause at the end of the line (thanks to: crose @ #vim)

inoremap <expr><silent> <c-right> search('\s', 'Wn', line('.')) <bar><bar> col('.') >= col('$') - 1 ? '<c-right>' : '<c-o>$'
nnoremap <expr><silent> <c-right> search('\s', 'Wn', line('.')) <bar><bar> col('.') >= col('$') - 1 ? '<c-right>' : '$'

Return to last edit position when opening files

autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
     \   exe "normal! g`\"" |
     \ endif

Replace capital commands automatically

So no more Not an editor command: Q!

cabb W w
cabb X x
cabb Q q

Try to fix all indentation with F7

map <F7> gg=G<C-o><C-o>

Switch tabs with Ctrl-Shift-left/right

" for normal mode
nnoremap <C-S-right> :tabnext<CR>
nnoremap <C-S-left> :tabprevious<CR>
" for insert mode
inoremap <C-S-right> <Esc>:tabnext<CR>
inoremap <C-S-left> <Esc>:tabprevious<CR>

Append modeline at the end of files

" Append modeline after last line in buffer.
function! AppendModeline()
  let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
        \ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
  let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
  call append(line("$"), l:modeline)
" and bind this to whatever shortcut you want
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>

Make tab characters visible

As ad-hoc command:

:set list
:set listchars=tab:>-
:set noexpandtab

Or just make it single command in your rc file

command Showtabs set list|set listchars=tab:>-|set noexpandtab

Search for multiple things

Start your search with /\v and use pipe to separate terms: