Results 1 to 10 of 23

Thread: VS Code + Pascal : Editor for the future!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Got some vim hacks I can share with you. If you want to change the default mode, just edit the script. Now it defaults to {$mode delphi}. I think the .vimrc file of my current installation is around 1500 lines long *phew*. This example script shows two things:
    1. Vim is a powerful editor, that you can customize as you like (almost)
    2. Vim-script syntax is horrible


    Code:
    function! InsertModeLine()
    python << endpython
    import vim
    unitname=vim.eval("expand('%:r')")
    vim.current.buffer[0:0]=['unit '+unitname+';']
    vim.current.buffer[2:0]=['{$MODE DELPHI}']
    vim.command(":$")
    del vim
    endpython
    endfunc
    
    augroup Delphi
        autocmd!
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set tabstop=4
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set shiftwidth=2
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set softtabstop=4
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set expandtab
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :set nospell
        autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr :let g:pascal_delphi=1
        autocmd BufNewFile *.pas,*.pp :call InsertModeLine()
    augroup END
    In short, it sets tabs to be equal to 4 spaces, and sets the auto indent tabstop at 2 spaces. The rest is just for show For some reason vim defaults to some late 60'ies syntax for pascal, but more modern delphi and fpc syntax is provided.

    If you want fpc syntax: do this changes
    Code:
    // Change this line
    let g:pascal_delphi=1
    // to
    let g:pascal_fpc=1

  2. #2
    So, should we add that code to the end of the .vimrc file? That's all?
    No signature provided yet.

  3. #3
    Yes. Just copy those lines into your .vimrc and source it (:so %). Next time you create a unit (myUnit.pas or myUnit.pp for example) it will automatically insert the line 'unit myUnit' and {$MODE DELPHI}.

    Another quickie:
    Code:
    let g:primary_file=""
    
    function! CompilePascal(mode)
    python << endpython
    import vim
    mode=vim.eval("a:mode")
    primary_file=vim.eval("g:primary_file")
    if mode=='DEBUG':
        vim.command("set makeprg=ppcx64\ -dDEBUG\ @fp.cfg\ " + primary_file)
    elif mode=='NORMAL':
        vim.command("set makeprg=ppcx64\ -dNORMAL\ @fp.cfg\ " + primary_file)
    elif mode=='RELEASE':
        vim.command("set makeprg=ppcx64\ -dRELEASE\ @fp.cfg\ " + primary_file)
    vim.command("make")
    endpython
    endfunc
    Also, add these line to the Delphi augroup:
    Code:
    autocmd BufNewFile,BufRead *.pas,*.pp,*.dpr,*.lpr :compiler fpc
    autocmd QuickFixCmdPost [^l]* nested cwindow
    autocmd QuickFixCmdPost    l* nested lwindow
    This little snippet, which you can bind to a key if you like, build pascal projects using fp.cfg (created by the fp-ide).
    Usage:
    Code:
    :let g:primary_file="program.pas" // Only needed once. Subsequent runs will remember this
    :call CompilePascal("DEBUG") // replace with "RELEASE" or "NORMAL" for other build configurations
    I think I've made a function that scans the folder for a *.lpr or *.dpr file and automatically set it as the primary file. Can't find it right now. When the build is complete you'll be asked to press a key to return to vim, and when back there you'll see that a "quickfix" window has opened, showing errors and warnings issued by the compiler. If you click them, the cursor will be placed at the error, and if you like me doesn't like to use the mouse, you can either type ':cn' or ':cp', or bind them to a key of your choice to jump to next error (cn) or the previous one (cp)

  4. #4
    Got tons of tips and tricks for vim, some are a bit more advanced then others - ranging from remapping function keys to work in all modes (normal,insert and visual) to configuring Pyclewn for debugging inside vim. Got codecompletion, code generation, building and debugging all set up in a way I like it, and all in the same editor. Some of the more advanced stuff needs a bit of bash-hacking to work in a terminal, but I mainly use gvim (or vim -g), I only use terminal-based vim sessions for editing scripts and config files. Note that I don't know much about setting up vim on windows as I only work on Linux and OS/X. For C related stuff I prefer Emacs, but that's another story

  5. #5
    I did create my own color schema to be the same than good old Borland Turbo IDEs. That and setting a few odd edition stuff (show special characters, use two different back-up files...). That's all I did.

    Didn't test your code yet.
    No signature provided yet.

  6. #6
    Quote Originally Posted by Ñuño Martínez View Post
    I did create my own color schema to be the same than good old Borland Turbo IDEs. That and setting a few odd edition stuff (show special characters, use two different back-up files...). That's all I did.

    Didn't test your code yet.
    Code:
    :colorscheme borland


    If you want to I can try to tidy up my vimrc and post it here on the forums somewhere, or put it on github - either way is ok.
    What I can do with my vim settings:
    • Automatic insertion of 'header' in files (comment etc). Customized by filetype
    • Code completion - Provided by NeoComplete (plugin).
    • Browse tags with a keypress (actually Three ',tt')
    • Jump between declaration and implementation
    • Code generation for class procedures/functions/constructors/destructors
    • Extensive (ab)use of snippets
    • Build project (debug or release is set by a command)
    • Debug using Pyclewn and GDB
    • Send emails (Yeah, really )
    • Generate build scripts (really stupid at the moment, need improvements)
    • Calltips (also really stupid at the moment, but it's a WIP)


    Most of it is written in hackish python, with some extra lines of vimscript to spice it up.

  7. #7
    That would be great.

    You may post it at Lazarus forums too.
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •