Skip to content

tact-lang/tact.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tact.vim

Tact.Vim

🚀 Adds syntax highlighting, grammar completion, and miscellaneous support for the Tact programming language to Vim 8+ and Neovim.

⚡ Tact is a new programming language for TON blockchain focused on efficiency and simplicity. It is designed to be easy to learn and use and to be a good fit for smart contracts because it is a statically typed language with a simple syntax and a powerful type system.

Features

See the highlighting showcase below (uses the One Dark color scheme).
Note, that you can disable highlighting of identifiers, if you want to :)

Highlighting showcase

Installation

via Vundle

Click to see

Info about it: Vundle repository.

Steps:

  1. Add tact.vim to your plugin list in ~/.vimrc (or ~/_vimrc on Windows) by inserting the line that starts with Plugin:

    call vundle#begin()
      " ...
      Plugin 'tact-lang/tact.vim'
      " ...
    call vundle#end()
  2. Restart Vim or run :source ~/.vimrc.

  3. Run :PluginInstall.

via vim-plug

Click to see

Info about it: vim-plug repository.

Steps:

  1. Add tact.vim to your plugin list in ~/.vimrc (or ~/_vimrc on Windows) by inserting the line that starts with Plug:

    call plug#begin()
      "...
      Plug 'tact-lang/tact.vim'
      "...
    call plug#end()
  2. Restart Vim or run :source ~/.vimrc.

  3. Run :PlugInstall.

via lazy.nvim (Neovim-only)

Click to see

Info about it:

Steps:

  1. Add tact.vim to your lazy.nvim setup in ~/.config/nvim/init.lua (or ~/AppData/Local/nvim/init.lua on Windows):

     require('lazy').setup({
       -- ...
       { 'tact-lang/tact.vim' },
       -- ...
     }, {})
  2. Run :Lazy.

Language Server

In addition, it's strongly recommended that a Tact language server be installed and set up.

Get an official one here: tact-language-server.

Configuration

Completion

By default this plugin sets an omnifunc option to provide auto-completions by triggering CTRL-xCTRL-o in INSERT mode. However, if you're using an LSP client for Tact language, it may overwrite this option and turn off the completion and basic linting capabilities provided by this plugin alongside it.

To prevent that behavior, you may want to bind the completion features of this plugin to a competefunc option (which is quite conveniently triggered by CTRL-xCTRL-u in INSERT mode). Add the following to your ~/.vimrc (or ~/_vimrc on Windows) if you'd like to prefer and bind completefunc over omnifunc:

" CTRL-x CTRL-u instead of CTRL-x CTRL-o
let g:tact_prefer_completefunc = 1
Neovim-only
vim.g.tact_prefer_completefunc = 1

Alternatively, add the following to the init key of your lazy.nvim config:

require('lazy').setup({
  -- ...
  {
    'tact-lang/tact.vim',
    init = function()
      -- ...
      vim.g.tact_prefer_completefunc = 1
      -- ...
    end,
  },
  -- ...
}, {})

Indentation

Add the following to your ~/.vimrc (or ~/_vimrc on Windows) to enable the preferred indentation style for Tact:

let g:tact_style_guide = 1
Neovim-only
vim.g.tact_style_guide = 1

Alternatively, add the following to the init key of your lazy.nvim config:

require('lazy').setup({
  -- ...
  {
    'tact-lang/tact.vim',
    init = function()
      -- ...
      vim.g.tact_style_guide = 1
      -- ...
    end,
  },
  -- ...
}, {})

Highlighting

If you want to turn off highlighting of identifiers: variables, and constants (but not structures), add the following option:

let g:tact_blank_identifiers = 1
Neovim-only
vim.g.tact_blank_identifiers = 1

Alternatively, add the following to the init key of your lazy.nvim config:

require('lazy').setup({
  -- ...
  {
    'tact-lang/tact.vim',
    init = function()
      -- ...
      vim.g.tact_blank_identifiers = 1
      -- ...
    end,
  },
  -- ...
}, {})

To turn off highlighting of structures (names of traits, messages, contracts, and structs), add the following:

let g:tact_blank_structures = 1
Neovim-only
vim.g.tact_blank_structures = 1

Alternatively, add the following to the init key of your lazy.nvim config:

require('lazy').setup({
  -- ...
  {
    'tact-lang/tact.vim',
    init = function()
      -- ...
      vim.g.tact_blank_structures = 1
      -- ...
    end,
  },
  -- ...
}, {})

Formatting

A series of Vim motions can do basic code formatting: gg=G (plus Ctrl-o twice to return to the original cursor position) or by invoking a :TactFmt command, which does all that for you without messing up with your cursor. Use both with caution, as Vim-native indentation handling is known to be prone to errors.

Folding

To enable code-folding, add the following snippet. This one might have an impact on editing performance; proceed with caution:

augroup tact_folding
    au!
    au FileType tact setlocal foldmethod=syntax
augroup END
Neovim-only

Make a ~/.config/nvim/after/ftplugin directory (~/AppData/Local/nvim/after/ftplugin) and put the file tact.lua in it with the following contents:

vim.opt.foldmethod = "syntax"
vim.opt.foldenable = false  -- turn off automatic folding on file opening

Abbreviations

To trigger an abbreviation, type it in followed by punctuation such as a space or comma, and it will expand into a code snippet. It's advised to use space for this, as it usually produces the best results.

These abbreviations (and auto-completions of their names) are available right away:

  1. a_fun — expands to the function declaration
  2. a_extfun — expands to the extension function declaration
  3. a_mutfun — expands to the mutable function declaration
  4. a_natfun — expands to the native function declaration
  5. a_co — expands to the contract declaration
  6. a_tr — expands to the trait declaration
  7. a_st — expands to the struct declaration
  8. a_me — expands to the message declaration
  9. a_se — expands to send(SendParameters{...}) call

Keep in mind that abbreviations are always there, and you can always type them in, even if they're not shown by omnicompletion when deemed unsuitable for the current completion context.

To avoid expansion in INSERT mode, type Ctrl-V after the last character of the abbreviation (on Windows, type Ctrl-Q instead of Ctrl-V).

To completely disable abbreviations provided by this plugin only, add this to your ~/.vimrc (or ~/_vimrc on Windows):

let g:tact_disable_abbreviations = 1
Neovim-only
vim.g.tact_disable_abbreviations = 1

Alternatively, add the following to the init key of your lazy.nvim config:

require('lazy').setup({
  -- ...
  {
    'tact-lang/tact.vim',
    init = function()
      -- ...
      vim.g.tact_disable_abbreviations = 1
      -- ...
    end,
  },
  -- ...
}, {})

Linting

Simply run the :Tact command to try compiling using Tacts' compiler and look for errors. See the Usage section for more info on the command.

Miscellaneous

For the ease of omnicompletion usage, you may want to add this or similar bindings, but they are not obligatory to use the plugin:

" Open omnicompletion menu on ctrl-space
inoremap <silent> <c-space> <c-x><c-o>
Neovim-only
vim.keymap.set('i', '<c-space>', '<c-x><c-o>', { noremap = true, silent = true})

Note that on macOS, there's a default system-wide keyboard shortcut for CtrlSpace (^space). You may want to change it to CmdSpace instead or use the different binding in Vim.

At times when omnicompletion (CTRL-xCTRL-o) can't complete much it fallbacks to keyword completion (CTRL-xCTRL-n). But that's not always the case, so if omnicompletion doesn't show anything, try keyword one!

Usage

For your convenience, a :Tact command is available whenever you open any .tact files. It tries to run the build script from your package.json project file, which, as shown in this official example here, should invoke a Tact compiler. You're expected to have a Node.js of the current LTS (or later) version installed on your system, alongside npm for the :Tact command to work.

It's generally recommended that you go over the example, which shows how to get started with Tact. Alternatively, use the official project template: either copy it or create a new repository based on it.

We wish you good luck and fun exploring Tact! ⚡

Useful Tact links

Credits

Based on The Open Network.

Built with 🤍 by Novus Nota.

License

MIT

About

⚡ All-in-one Vim 8+ plugin for Tact programming language

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •