https://github.com/fuellabs/sway.vim
Vim syntax file for Sway.
https://github.com/fuellabs/sway.vim
Last synced: 8 months ago
JSON representation
Vim syntax file for Sway.
- Host: GitHub
- URL: https://github.com/fuellabs/sway.vim
- Owner: FuelLabs
- License: apache-2.0
- Created: 2021-11-11T21:15:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T20:59:07.000Z (over 2 years ago)
- Last Synced: 2025-05-21T18:34:22.817Z (about 1 year ago)
- Language: Vim Script
- Homepage:
- Size: 17.6 KB
- Stars: 20
- Watchers: 22
- Forks: 12
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## About
Vim syntax file for Sway
## Installation
Pre-requisites:
1. Clone this repo
1. Ensure you have the `forc-lsp` binary with `which forc-lsp`. If not, install [the Sway toolchain](https://fuellabs.github.io/sway/v0.25.2/introduction/installation.html).
### Neovim
1. Copy the folders 'ftdetect' and 'syntax' to the config folder:
```
cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvim
```
2. If you do not have `~/.config/nvim/init.lua`, install [kickstart.nvim](https://github.com/nvim-lua/kickstart.nvim).
3. If you already have `init.lua`, you may need to require extra dependencies, or simply copy [this block](https://github.com/nvim-lua/kickstart.nvim/blob/38828dcaf7c140902fedeaa75b017bf968400bb0/init.lua#L401-L604).
4. 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{}
```
4. Check that the LSP is running by running `:LspInfo` and trying out features like Goto Definition (`gd`) and Hover (`K`). The key mappings are defined in `~/.config/nvim/init.lua`

### Vim
1. Clone this repo
2. Copy the folders 'ftdetect' and 'syntax' to the config folder:
```
cp -R ~/sway.vim/syntax ~/.vim && cp -R ~/sway.vim/ftdetect ~/.vim
```
3. Edit your `~/.vim/filetype.vim` to contain the following block:
```
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au! BufNewFile,BufRead *.[sS][wW] setf sway
augroup END
```
4. Install [plug.vim](https://github.com/junegunn/vim-plug)
5. Add the following to your `~/.vimrc`
```
call plug#begin()
Plug 'prabirshrestha/vim-lsp'
call plug#end()
```
6. Create a file called `~/.vim/lsp.vim` with the following contents, or add this to an existing vim script:
```
" 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
```
7. Open vim and `:source ~/.vim/lsp.vim`
8. Check that the LSP is running with `:LspStatus` and try out feature like `:LspDefinition` and `:LspHover`. The full list of commands are defined [here](https://github.com/prabirshrestha/vim-lsp).
