[Tutor] [off-topic] vi/vim editor settings (was: Pep 8, about indentation)

Cameron Simpson cs at zip.com.au
Sat Aug 8 09:14:22 CEST 2015

On 07Aug2015 21:50, Alex Kleider <akleider at sonic.net> wrote:
>On 2015-08-07 20:56, Cameron Simpson wrote:
>> autoindent: start the next line's text on the same indent as this one
>> expandtab: write spaces instead of a TAB character
>> shiftwidth: how far the < and > shift-text operations move
>> tabstop: the multiple used to tabstops - every 4 columns for me
>Here is what I've got in my ~/.vimrc file:
>set autoindent
>set shiftwidth=4
>set expandtab
>set textwidth=72
>set scrolljump=2
>set scrolloff=2
>I'll add
>set tabstop=4
>>Happy to post my other settings should anyone care.
>... and yes, I for one certainly do "care."
>I'd very much like to see your other settings.

Ok. Here are my other vi settings which I think useful (it seems I have plenty 
which aren't).  Vim specific settings follow after that.

  set autowrite
    Automatically save the file when switching to another. Saves tedious :w and 
    also worrying about whether I should, not to mention all those "file 
    modified" warnings.

  set ignorecase
    Saves fiddling with shift keys.

  set nowrapscan
    Searches do not resume from the top of the file if nothing found below the 
    current position. I used to have this on, but now consider this more 

  set optimize
  set redraw
    I forget, probably dates from editing over a 300baud modem.

  set report=1
    Threshold for reporting changed lines.

  set showmatch
    Highlight matching open/close bracket. Handy for nested stuff. And C code.

  set noterse
    Longer warnings and other messages.

  set writeany
    Trust me, I'm a doctor. (I'm not.)

  map! \c cs at zip.com.au
  map! \C Cameron Simpson <\c>
    Insert mode macros to recite my email, short and long.
    I've got matching ones for my partner's email, very often CCed or 

  map!  :stop
    Suspend the editor, just as with ^Z in the shell.

  map!  a
    Redraw the screen then resume inserting.

  map!  I
  map!  i
  map!  A
  map!  lli
    Emacs mode motion: start of line, left, end of line, right, resume insert 

  map # :n #
    Edit the previous file. Very very handy.
  map g Gz.
    Go to line and position it in the centre of the screen.

  map q ZZ
    Save and quit.

  map t :ta
    Commence "go to tag".

  map Y y$
    Yank to end of line.

  map  1G}-:.r!exec </dev/tty 2>/dev/tty; readline -B 'Attach: '
    My uber-convenient "attach file" macro. In mutt (my mailer) an "Attach:" 
    header gets turned into a real attachment. So this macro runs a bit of 
    shell to issue the prompt "Attach: " and accept the filename you typ, _with 
    filename completion!_. And inserts that as an Attach: header. When I leave 
    the editor, mutt adds the file to the attachments for this message.

  set bg=dark
    My terminals have a dark background.

  syntax reset
  syntax on
    I like my syntax highlighting.

  set wildmenu wildmode=list:longest
    Make vim's filename completion act more like zsh's, which I find far more 
    ergonomic than bash's. Essentially: complete as much as you can and 
    _immediately_ show me the remainder without an extra TAB keystroke.

  set ignorecase
  set smartcase
    Case insensitive searches unless there is an uppercase letter in the search 

  set incsearch
    Show the first match in the file as you type the search regexp.

  set backupcopy=yes
    I prefer to overwrite the original file instead of making a new one and 
    cutting it in with rename(). The former edits the file I intended to edit.  
    The latter breaks hardlinks and has to do silly hoop jumping with symlinks.  
    Gah! Do what I say, not what you think I want!

  set noswapfile
  set swapsync=
    Vim's fetish for .swp files drives me mad, especially if one loses remote 
    sessions regularly or terminal emulators die or one coworks with others in 
    the same directories or simply closes one's laptop one a whim or moves 
    around. I save files very regularly anyway, so I pretty much never lose a 
    significant edit.

  set nofsync
    Trust the filesystem, the filesystem is your friend. Once I've handed the 
    file to the OS (i.e. written it) I do not want to shout at the OS: not get 
    that onto the disc, now! Especially when fsync() means sync(0 on many 
    filesystems i.e. write _all_ pending disc I/O before returning, often with 
    a huge and visible hit to the system behaviour.

  set scrolloff=2
    Like you, keep some screen context.

  set t_Co=256
    Yes, my terminal have lots of colours.

  set ttyfast
    Better display instead of lower bandwidth display.

  set spellfile=~/rc/vim/spellfile.utf-8.add
    Additional words to augument the spelling table.

  set spelllang=en_gb
    British English.

  set nospell
    Spell checking off by default.

  let g:loaded_netrw = 1
    I forget. Anyone?

  map <F3> :set hlsearch! nospell! <CR>
    F3 turns off highlighting.

and when composing email I use:

  set formatoptions=wa
    This supports writing format=flowed email text. See ":help fo-table".

Cameron Simpson <cs at zip.com.au>

Philosophy is questions that may never be answered. Religion is answers that
may never be questioned. - anonymous

More information about the Tutor mailing list