# Setting up Sway in Vim **Published by:** [andrw](https://paragraph.com/@andrw/) **Published on:** 2023-09-24 **URL:** https://paragraph.com/@andrw/setting-up-sway-in-vim ## Content 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. Let's started Pre-requisites: Ensure you have the forc-lsp installed with forc-lsp —version. If not, install the Sway toolchain. Clone the sway.vim repo git clone https://github.com/FuelLabs/sway.vim.git Setting up Neovim Copy the folders 'ftdetect' and 'syntax' to your .config folder: cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvim If you do not have the ~/.config/nvim/init.lua file, 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 LSP is installed running :LspInfo Setting up Vim 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.git Copy the folders 'ftdetect' and 'syntax' to your .config folder: cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvim Add the following code to your ~/.vim/filetype.vim if exists("did_load_filetypes") finish endif augroup filetypedetect au! BufNewFile,BufRead *.[sS][wW] setf sway augroup END Install vim.plug with the following command curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim Add the following code to your ~/.vimrc call plug#begin() Plug 'prabirshrestha/vim-lsp' call plug#end() Create a file called ~/.vim/lsp.vim with 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'], \ }) endif Open vim and run :source ~/.vim/lsp.vim Check that the LSP is 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! ## Publication Information - [andrw](https://paragraph.com/@andrw/): Publication homepage - [All Posts](https://paragraph.com/@andrw/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@andrw): Subscribe to updates - [Twitter](https://twitter.com/andrwmayorca): Follow on Twitter