Vim syntax file for Sway
Pre-requisites:
- Clone this repo
- Ensure you have the
forc-lsp
binary withwhich forc-lsp
. If not, install the Sway toolchain.
- Copy the folders 'ftdetect' and 'syntax' to the config folder:
cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvim
- If you do not have
~/.config/nvim/init.lua
, install kickstart.nvim. - If you already have
init.lua
, you may need to require extra dependencies, or simply copy this block. - 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 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
- Clone this repo
- Copy the folders 'ftdetect' and 'syntax' to the config folder:
cp -R ~/sway.vim/syntax ~/.vim && cp -R ~/sway.vim/ftdetect ~/.vim
- 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
- Install plug.vim
- Add the following to your
~/.vimrc
call plug#begin()
Plug 'prabirshrestha/vim-lsp'
call plug#end()
- 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
- Open vim and
:source ~/.vim/lsp.vim
- Check that the LSP is running with
:LspStatus
and try out feature like:LspDefinition
and:LspHover
. The full list of commands are defined here.