
If you are a swayor and you use vim as your main code editor here I will show you how to configure the sway syntax in vim, so you can develop smart contracts like a ninja.
Ensure you have the
forc-lspinstalled withforc-lsp —version. If not, install the Sway toolchain.Clone the sway.vim repo
git clone https://github.com/FuelLabs/sway.vim.git
Copy the folders 'ftdetect' and 'syntax' to your .config folder:
cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvimIf you do not have the
~/.config/nvim/init.luafile, install kickstart.nvim.Add the following to
~/.config/nvim/init.lua:-- Install Sway LSP as a custom server local lspconfig = require 'lspconfig' local configs = require 'lspconfig.configs' -- Check if the config is already defined (useful when reloading this file) if not configs.sway_lsp then configs.sway_lsp = { default_config = { cmd = {'forc-lsp'}, filetypes = {'sway'}, on_attach = on_attach, init_options = { -- Any initialization options logging = { level = 'trace' } }, root_dir = function(fname) return lspconfig.util.find_git_ancestor(fname) end; settings = {}; }; } end lspconfig.sway_lsp.setup{}Check that the
LSPis installed running:LspInfo

To configure sway in vim the steps are very similar to the ones we did to configure in neovim.
Clone the sway.vim repo
git clone https://github.com/FuelLabs/sway.vim.gitCopy the folders 'ftdetect' and 'syntax' to your .config folder:
cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvimAdd the following code to your
~/.vim/filetype.vimif exists("did_load_filetypes") finish endif augroup filetypedetect au! BufNewFile,BufRead *.[sS][wW] setf sway augroup ENDInstall vim.plug with the following command
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vimAdd the following code to your
~/.vimrccall plug#begin() Plug 'prabirshrestha/vim-lsp' call plug#end()Create a file called
~/.vim/lsp.vimwith the following code" vim-lsp for Sway (sway-lsp) if executable('sway-lsp') au User lsp_setup call lsp#register_server({ \ 'name': 'sway-lsp', \ 'cmd': {server_info->['sway-lsp']}, \ 'whitelist': ['sway'], \ }) endifOpen vim and run
:source ~/.vim/lsp.vimCheck that the
LSPis installed running:LspStatus
And done!! Now to code with sway in vim or neovim.
That's all for today, I hope this tutorial has worked for you, thanks for making it this far!
