Toggling and Shortening

There are a number of options / settings in Vim, of course, and sometimes they’re not so easy to set. There are also a lot of things we tend to do over and over that take more than a couple of characters to write and you want to do them faster. This is where mappings come in:

" Toggle paste mode

nmap ,p :set invpaste:set paste?

" Turn off that stupid highlight search

nmap ,n :set invhls:set hls?

" Set text wrapping toggles

nmap ,w :set invwrap:set wrap?

" Set up retabbing on a source file

nmap ,rr :1,$retab

" cd to the directory containing the file in the buffer

nmap ,cd :lcd %:h

" Make the directory that contains the file in the current buffer.

" This is useful when you edit a file in a directory that doesn't

" (yet) exist

nmap ,md :!mkdir -p %:p:h

6 comments on this post.
  1. Nikos Aggelidis:

    To “Turn off that stupid highlight search” i use the space bar!

  2. Seth Milliken:

    Here?s one that piggybacks on the already familiar to Unix folk, :

    nnoremap <silent> <c-l> {your preferred hls off/toggle command here}<cr><c-l>

  3. Anton Chikin:

    nmap <silent> ,n :set invhls<cr>:set hls?<cr>

  4. Anton Chikin:

    HTML eating that <cr> tags. Look in source code of page for proper commands.

  5. Crazor:

    Mapped ,n to :nohl. This gets rid of the highlight, but doesn’t toggle ‘hlsearch’.

  6. happypeter:

    Thank you so much, @derek, this is useful.

    ” Toggle paste mode
    nmap ,p :set invpaste:set paste?

Leave a comment