Giter Club home page Giter Club logo

nim.vim's Introduction

Nim language support for Vim

This provides Nim language support for Vim:

  • Syntax highlighting
  • Auto-indent
  • Build/jump to errors within Vim
  • Project navigation and Jump to Definition (cgats or compiler-assisted idetools).

The source of this script comes mainly from http://www.vim.org/scripts/script.php?script_id=2632, which comes from a modified python.vim (http://www.vim.org/scripts/script.php?script_id=790).

Installation

Installing nim.vim is easy but first you need to have a plugin manager such as pathogen, vundle or vim-plug installed. If you already have one working then skip to the final step. It is also recommended that you use the syntastic plugin for best results.

Pathogen

Step 1: Install pathogen.vim

First I'll show you how to install tpope's pathogen.vim so that it's easy to install nim.vim. Do this in your Terminal so that you get the pathogen.vim file and the directories it needs:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Next you need to add this to your ~/.vimrc:

call pathogen#infect()

Step 2: Install nim.vim as a pathogen bundle

You now have pathogen installed and can put nim.vim into ~/.vim/bundle like this:

cd ~/.vim/bundle
git clone https://github.com/zah/nim.vim.git

You may also want to install synastic by calling

git clone https://github.com/scrooloose/syntastic.git

Vundle

Vundle is a more automatic way to install vim plugins that works by cloning the git reposotory.

Step 1: Install Vundle

Add the vundle script to your vim:

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Modify your ~/.vimrc to get vundle running, lightly adapted from Vundle's readme

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install bundles
"let path = '~/some/path/here'
"call vundle#rc(path)

" let Vundle manage Vundle, required
Bundle 'gmarik/vundle'

filetype plugin indent on     " required

Step 2: Install nim.vim

On the line after Bundle 'gmarik/vundle', add Bundle 'zah/nim.vim'. You may also want to add Bundle 'scrooloose/syntastic'. Save ~/.vimrc and restart vim. Execute :BundleInstall and wait for nim.vim to be installed.

vim-plug

vim-plug is a minimalist Vim plugin manager.

Step 1: Install vim-plug

Install vim-plug so that it loads automatically at launch:

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
      https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Step 2: Add nim.vim to your list of plugins

Modify your ~/.vimrc to add the nim.vim plugin to the list of plugins:

" ...
call plug#begin('~/.vim/plugged')
 " ...
 Plug 'zah/nim.vim'
call plug#end()

Execute :PlugInstall and wait for nim.vim to be installed.

Final Step

Next you need to add this to your ~/.vimrc:

fun! JumpToDef()
  if exists("*GotoDefinition_" . &filetype)
    call GotoDefinition_{&filetype}()
  else
    exe "norm! \<C-]>"
  endif
endf

" Jump to tag
nn <M-g> :call JumpToDef()<cr>
ino <M-g> <esc>:call JumpToDef()<cr>i

The JumpToDef function hooks the nim.vim plugin to invoke the nim compiler with the appropriate idetools command. Pressing meta+g will then jump to the definition of the word your cursor is on. This uses the nim compiler instead of ctags, so it works on any nim file which is compilable without requiring you to maintain a database file.

Other recomended Vim plugins

If something goes wrong

Since you are using vim, on source code which might have syntax problems, invoking an external tool which may have its own share of bugs, sometimes stuff just doesn't work as expected. In these situations if you want to debug the issue you can type :e log://nim and a buffer will open with the log of the plugin's invocations and nim's idetool answers.

This can give you a hint of where the problem is and allow you to easily reproduce on the commandline the idetool parameters the vim plugin is generating so you can prepare a test case for either this plugin or the nim compiler.

nim.vim's People

Contributors

benjamingorman avatar bkerin avatar daddye avatar def- avatar doccaico avatar erw7 avatar federicoceratto avatar gradha avatar hide0123 avatar justjosias avatar kearnh avatar magnostherobot avatar mattn avatar miyakogi avatar nepeckman avatar rhysd avatar rogercloud avatar schneiderfelipe avatar siddhantgoel avatar superfunc avatar tyler-anderson avatar unclechu avatar yglukhov avatar zah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nim.vim's Issues

json_decode related error (VIM 7.4)

Error detected while processing function nim#init:
line    6:
E117: Unknown function: json_decode
E15: Invalid expression: json_decode(raw_dumpdata)

I get this error on a system using VIM 7.4
since commit dce4bab

No default shiftwidth

When I loaded the plugin I needed to add "set sw=2" to indent/nim.vim otherwise the default was 8, did I miss something or is this a bug?

tagbar integration

is there an integration with the tagbar plugin which also uses ctags?

Python 3 support

To get it working in Termux (which defaults to Python 3, as everything should), I had to:

  • apt install vim-python

  • ~/.vim/bundle/nim.vim/autoload/nim.vim: replace the "pyfile" line with:
    exe 'py3file ' . fnameescape(s:plugin_path) . '/nim_vim.py'

  • ~/.vim/bundle/nim.vim/autoload/nim_vim.py: remove Queue from the import line, and add:
    from multiprocessing import Queue

Syntastic not working for more than one directory deep

If I edit the file ./hello.nim syntastic works perfectly, but if I edit ./test/hello_test.nim and vim CWD is ./ syntastic won't work for ./test/hello_test.nim.

I guess that this has something to do with the fact that nim check --hints:off test/hello_test.nim outputs
hello_test.nim(5, 1) Error: value of type 'bool' has to be discarded
instead of
test/hello_test.nim(5, 1) Error: value of type 'bool' has to be discarded
and this somehow confuses buffers.

Comment in type definition causes cursor to jump to first column

Entering the comment char # in a type definition makes the cursor jump to the first column. For example:

type
  Foo = object
    |

If | represents, the cursor, entering a # in insert mode will result in

type
  Foo = object
#

As opposed to:

type
  Foo = object
    #

This only seems to happen if # is the first character entered on that line. If you enter another character, backspace, and then enter a #, the cursor stays in place.

not working with n/vim spf13

Hey this plugin looks awesome. That said, I can't use it :( I installed it the way described in the readme. Currently on a MacBook Pro OSX El Capitan 10.11.5 (15F34).

Tested with:
NVIM 0.1.5
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Apr 5 2016 14:53:37)

both with spf13 installs.

Here's what I see when opening up one of my nim files:

screen shot 2016-08-23 at 2 39 31 pm

I can't get it to run at all

I use vundle already and have C and Python packages installed.

I install zah/nimrod.vim without issue. Add the extra lines to my .vimrc. No auto-indent, K goes to a shell request, very little highlighting (just comments really), and until I added

au BufRead,BufNewFile *.nim set ts=2 sw=2 sts=2 expandtab autoindent

to my vimrc the tabs were tabs etc.

I'm running ubuntu 14.04 with Gnome 3.12 and Vim 7.4. Hmmm - my shell is zsh. I tried going to a minimal vimrc and then I tried dropping 7.4 and installing 7.3 from debs instead. No change.

I suspect I'm doing something amazingly stupid but I don't know what it is. Any ideas on how I could test it or provide better feedback.

Dirty ?

Maybe there is something wrong with my vim config but autocomplete give me those results:

screen shot 2013-07-22 at 12 07 26 am

Any idea how I can fix it?

Vim error when opening a .nim file on Windows

When opening a nim file in vim on Windows the nim plugin issues an error:

"C:\Nim\nimsuggest\nimsuggest.nim" 414L, 12172C
Error detected while processing C:\Users\Username.vim\bundle\nim.vim\autoload\nim.vim:
line 12:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Username.vim\bundle\nim.vim\autoload/nim_vim.py", line 78, in
NimLog = open("/tmp/nim-log.txt", "w")

This is because the path /tmp does not exist on Windows, or at least that's generally not where you'd want to store temporary files on Windows...

Plugin not finding nim compiler in $PATH

When opening a test .nim file using Vim or GVim 7.4 on Ubuntu 14.10:

"test.nim" [New File]
Error detected while processing /home/.vim/bundle/nimrod.vim/autoload/nim.vim:
line 9:
the Nim compiler must be in your system's PATH

The nim compiler is definitely in the PATH (I can call it without issues), and this error even appears when I set vim to silent. The issue doesn't occur on a similar installation on OS X.

Also, I should note the syntax and indentation is working as expected, there is just a spurious error when launching.

Does this plugin require vim compiled with the python flag?

After installing the Nim compiler to my PATH and installing nim.vim, on opening a nim buffer I get this error:

Error detected while processing /Users/dave/.vim/bundle/nim.vim/autoload/nim.vim:
line   12:
E117: Unknown function: provider#python#Call

My vim was not compiled with the python flag. Do you think that's the cause, or is this something else?

Autocomplete known keywords

It is weird that vim knows a set of keywords which have to be highlited, but they are not used for autocompletion when pressing Ctrl+P. Is there any vim option to make these keywords available for Ctrl+P?

Jump to file mentioned in import line with gf

When I write code like:

import test.nim

I can position the vim cursor on the test.nim string and press gf to open it. Without the extension, however, the command doesn't work. It would be nice if the plugin could detect this and automatically add the expected extension.

Compile with threads:on

I'm new to nim, but when I try to use threading mechanisms like TThread, I get the error undeclared identifier: 'TThread'. I believe this is because you must compile with --threads:on. How does one do that with this plugin?

Indents too long

I've noticed that hitting tab results in a very long indentation--twice as long as expected, to be exact. (I.e., eight spaces rather than four.) I'm having a hard time figuring out how to change this. I thought maybe this is a more general setting in Vim rather than a Nim-specific one, but I've only noticed it when writing Nim.

Sorry, just discovered this was already noted in Issue #34.

Syntastic: No Checkers?

Upon installing this plugin and opening a nim file, I don't seem to get any syntax checking via syntastic. Running :SyntasticInfo yields the following:

Syntastic version: 3.9.0-23 (Vim 800, Neovim, Linux)                                                                          
Info for filetype: nim                                                                                                        
Global mode: active                                                                                                           
Filetype nim is active                                                                                                        
The current file will be checked automatically                                                                                
Available checkers: -                                                                                                         
Currently enabled checkers: -  

So syntastic reports no available checkers. Is there any setup required here?

Error when run from the latest version of macOS

Hello
I have installed nim.vim, but every time I try to edit a nim file, the next error message appears.
Any ideas?

Error detected while processing /Users/teras/.vim/bundle/nim.vim/autoload/nim.vim:
line   15:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/teras/.vim/bundle/nim.vim/autoload/nim_vim.py", line 2, in <module>
    import threading, subprocess, signal, os, platform, getpass
  File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 13, in <module>
    from collections import deque as _deque
  File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 20, in <module>
    from _collections import deque, defaultdict
ImportError: dlopen(/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_collections.so, 2): no suitable image f
ound.  Did find:
^I/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_collections.so: code signature in (/usr/local/Cellar/pyth
on@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_collections.so) not valid for use in process using Library Validation: mapped fil
e has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
Press ENTER or type command to continue

Make 'else:' back up to matching if indentation

Given the following snippet of code:

      if state.debug_idetools:
        if not state.server_mode:
          output.add(ATT_NL & "command: " &
            XMLEncode(idetools_args(state,
              state.procs[index].line,
              state.procs[index].col).join(" ")))

pressing enter at the end will put the cursor aligned with state, and typing else: will autoalign the else: with the column starting with XMLEncode. It would be better if the indentation went back to the first found if starting a column.

New Release?

Hi,

It has been a decade since the last tag/release found here

Could you please add a new one with all the new features and files?

Thanks

No visual warning jumping to file opened in another terminal

If I open a file like lib/system.nim with vim, then in another terminal try to jump to the definition of newException the session seems hanged. What actually happens is that vim is trying to display the "You are already editing file blah, press R to rm -fR /, e to reload the file in read only mode" but there is no visual cue about this. Usually pressing enter is enough to continue in read only mode, but the problem is you have no indication of what is happening, so you end up waiting, waiting, waiting, and sometimes wondering "that's taking too long".

Configuring tab width

In the project readme there's a reference that this plugin adds smart indent and I was wondering if there was an option to configure said indent or just disable the version provided by this plug in as the default is 2 spaces but I personally always use 4.

nim#init executes nimscript on load

When opening a nimscript file (*.nims) into vim, all "exec" statements are executed. This makes editing nimscript files very impractical, and poses a huge security risk.

example.nims:

exec "touch a_wild_file_appears.txt"
exec "rm -r ~/my_important_projects"

This seems to occur in autoload/nim.vim:nim#init:

  let cmd = printf("nim --dump.format:json --verbosity:0 dump %s", s:CurrentNimFile())
  let raw_dumpdata = system(cmd)

My current workaround is to comment out the whole function call in ftplugin/nim.vim:
"call nim#init()

Thanks for your time.

Add syntax highlighting to source code filters

Presuming source code filters use the .tmpl extension it would be nice if the syntax highlighting could be applied despite all the actual nimrod code being behind a first column of hashes styling everything else as comment. Though it would be even more useful if there was a keyboard mapping to invert the syntax highlighting to the nimrod code or to the other code, using some default for C/HTML/JS syntax.

With this keyboard mapping you could decide what part of the code you want to focus on and the highlighting would follow.

Incorrect main project file detection

The plugin doesn't detect correctly the main project file despite starting to use idetools from it. See the following steps:

$ git clone https://github.com/dom96/ipsumgenera.git
$ cd ipsumgenera
$ git checkout fca1d7c100e06c2d4c900e4e75e50931a06e583d
$ vim ipsum.nim
/renderRst<enter>
:call JumpToDef() -> opens src/rstrender.nim
advance cursor to any type (like string) and :call JumpToDef()

At this point any jump query inside rstrender.nim will fail with SIGSEGV: Illegal storage access. (Attempt to read from nil?). The reason for this is that the file doesn't compile without special parameters, which are present in the root ipsum.nimrod.cfg file. The parameters add the required path switches to find the rst related modules. This can be seen running nimrod check src/rstrender.nim which doesn't find the types either and at some point crashes.

Another way to see the problem is to manually run the query stored in the log replacing the project file with ipsum.nim so it works, like

nimrod idetools --def --track:"/private/tmp/ipsumgenera/src/rstrender.nim,205,22" ipsum.nim

I wonder if this situation can be autodetected better. If not, would it be valid to help the vim plugin with explicit files? Maybe the plugin could look for .vim.idetools.proj files which would be symbolic links to the correct main .nim file?

Improve documentation

Hi and thank you for developing nim.vim
Can you please add a help page on how to use the features, especially:

  • Build/jump to errors within Vim
  • Project navigation and Jump to Definition (cgats or compiler-assisted idetools).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.