Personal tools

Vim

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(Created page, filled it with plugins "module section", "module header")
 
(One intermediate revision by one user not shown)
Line 2: Line 2:
 
This page intended Haskell vim-users.
 
This page intended Haskell vim-users.
   
  +
= Indentation =
  +
  +
The following setup from merijn @ #haskell ensures you use spaces not tabs for indentation for generally sane behaviour:
  +
  +
<pre>
  +
" Tab specific option
  +
set tabstop=8 "A tab is 8 spaces
  +
set expandtab "Always uses spaces instead of tabs
  +
set softtabstop=4 "Insert 4 spaces when tab is pressed
  +
set shiftwidth=4 "An indent is 4 spaces
  +
set smarttab "Indent instead of tab at start of line
  +
set shiftround "Round spaces to nearest shiftwidth multiple
  +
set nojoinspaces "Don't convert spaces to tabs
  +
</pre>
   
 
= Plugins =
 
= Plugins =
Line 32: Line 46:
   
 
== Module Headers ==
 
== Module Headers ==
The following code prompts for module name, a note, a description of module, and places a section with that name at top, when key sequence "--h":
+
The following code prompts for module name, a note, a description of module, and places a module comment at top, when key sequence "--h":
 
<pre>
 
<pre>
 
let s:width = 80
 
let s:width = 80

Revision as of 10:35, 9 March 2012

This page intended Haskell vim-users.

Contents

1 Indentation

The following setup from merijn @ #haskell ensures you use spaces not tabs for indentation for generally sane behaviour:

" Tab specific option
set tabstop=8                   "A tab is 8 spaces
set expandtab                   "Always uses spaces instead of tabs
set softtabstop=4               "Insert 4 spaces when tab is pressed
set shiftwidth=4                "An indent is 4 spaces
set smarttab                    "Indent instead of tab at start of line
set shiftround                  "Round spaces to nearest shiftwidth multiple
set nojoinspaces                "Don't convert spaces to tabs

2 Plugins

Put code in file ~/.vim/plugin/Haskell.vim, or in multiple files in that directory.

2.1 Module Sections

The following code prompts for a name, and places a section with that name at current position, when key sequence "--s":

let s:width = 80

function! HaskellModuleSection(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Section name: ")

    return  repeat('-', s:width) . "\n"
    \       . "--  " . name . "\n"
    \       . "\n"

endfunction

nmap <silent> --s "=HaskellModuleSection()<CR>gp

Like so:

--------------------------------------------------------------------------------
--  my section


2.2 Module Headers

The following code prompts for module name, a note, a description of module, and places a module comment at top, when key sequence "--h":

let s:width = 80


function! HaskellModuleHeader(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Module: ")
    let note = 1 < a:0 ? a:2 : inputdialog("Note: ")
    let description = 2 < a:0 ? a:3 : inputdialog("Describe this module: ")
    
    return  repeat('-', s:width) . "\n" 
    \       . "-- | \n" 
    \       . "-- Module      : " . name . "\n"
    \       . "-- Note        : " . note . "\n"
    \       . "-- \n"
    \       . "-- " . description . "\n"
    \       . "-- \n"
    \       . repeat('-', s:width) . "\n"
    \       . "\n"

endfunction


nmap <silent> --h "=HaskellModuleHeader()<CR>:0put =<CR>

like so:

--------------------------------------------------------------------------------
-- | 
-- Module      : MyModule
-- Note        : This is a preview
-- 
-- This is an empty module, to show the headercomment produced. 
-- 
--------------------------------------------------------------------------------