GithubHelp home page GithubHelp logo

tehnix / spaceneovim-layers Goto Github PK

View Code? Open in Web Editor NEW
42.0 7.0 7.0 276 KB

Layers for usage in SpaceNeovim ๐Ÿ‘‰

Home Page: https://github.com/Tehnix/spaceneovim

License: MIT License

Vim Script 100.00%
neovim layers vim spaceneovim-layers spaceneovim spacevim

spaceneovim-layers's Introduction

SpaceNeovim Layers Build Status

Managing layers to use with SpaceNeovim.

Current Layers

Name Description
+core/behavior Core functionality for SpaceNeovim
+core/sensible Sensible default settings
+completion/asyncomplete Auto-completion with asyncomplete
+completion/coc Auto-completion with coc.nvim
+completion/deoplete Auto-completion with deoplete
+completion/ncm2 Auto-completion with NCM2
+completion/snippets Snippet support
+checkers/ale Syntax checking with Ale
+checkers/neomake Syntax checking with Neomake
+checkers/syntastic Syntax checking with Syntastic
+docs/dash Browse offline documentation with Dash
+docs/zeal Browse offline documentation with Zeal
+gui/ide An opinionated setup with VimR/Oni
+nav/buffers Common buffer functionality
+nav/comments Manipulating comments
+nav/files Common file operations
+nav/fuzzy Fuzzy search for files, buffers and methods
+nav/fzf Fuzzy search using FZF
+nav/jump Easy navigation inside files
+nav/navigation Easy navigation on screen
+nav/quit Common quit functionality
+nav/start-screen Add start screen when opening Neovim
+nav/text Common text operations
+nav/tmux Navigate between VIM and TMUX panes
+nav/windows Common window functionality
+scm/git Git and fugitive support
+specs/testing Run tests directly from the editor
+tools/format Format files
+tools/language-server Language server support
+tools/multicursor Support for multiple cursors
+tools/terminal Defaults and keybindings for the terminal
+ui/airline Replace the status bar with airline
+ui/dynamic-cursor Dynamically change the cursor depending on the mode
+ui/toggles Toggles for common components

Language layers

Name Description
+lang/-example A template for creating new language layers
+lang/elm Support for Elm
+lang/fsharp Support for F#
+lang/go Support for Go
+lang/haskell Support for Haskell
+lang/java Support for Java
+lang/javascript Support for JavaScript
+lang/php Support for PHP
+lang/purescript Support for PureScript
+lang/python Support for python
+lang/ruby Support for Ruby
+lang/rust Support for Rust
+lang/vim Support for VimL

Adding a New Layer

A layer consists of, as minimum:

  • a README.md describing the layer (configuration, keybindings etc),
  • either a config.vim, adding the layer key bindings, or
  • a packages.vim, adding the packages that needs to be installed
  • optionally, if a func.vim is present, it is loaded first (define commands and helper functions in this to keep things clean)

These files are grouped under a +category/layer-name directory hierarchy. As an example, the layer buffers is located under the group +nav (short for navigation).

A layer is only ever run if it is enabled, so there is no need to check for it. However, if you want to check if another layer is enabled, before doing anything, it can be done with,

if SpaceNeovimIsLayerEnabled('+checkers/neomake')
  " Make specific configuration for neomake here...
endif

This can especially be useful in the +lang layers, to add information to checkers and completions.

API

The API available to layers are (<arg> are required, [arg] are optional), for keybindings,

Command Arguments Description Example
SpBind <map>, <binding>, <name>, <value>, <isCmd> Map a key to a specific mapping type, with a description and command to execute. The <isCmd> argument adds <CR> on the end if 1 and nothing if 0. SpBind 'tmap', 'wj', 'window-down', 'wincmd j', 1
SpMap <binding>, <name>, <value>, [isCmd] Map a key with map/noremap, with a description and command to execute. <isCmd> defaults to 1 (i.e. adds <CR>). SpMap 'wk', 'window-up', 'wincmd k'
SpMap <binding>, <name>, <value>, [isCmd] Map a key with nmap/nnoremap, with a description and command to execute. <isCmd> defaults to 1 (i.e. adds <CR>). SpMap 'wk', 'window-up', 'wincmd k'
SpVMap <binding>, <name>, <value>, [isCmd] Map a key with vmap/vnoremap, with a description and command to execute. <isCmd> defaults to 1 (i.e. adds <CR>). SpVMap 'wk', 'window-up', 'wincmd k'
SpFileTypeBind <filetype>, <map>, <binding>, <name>, <value>, <isCmd> Map a key, only shown under a specific filetype, to a specific mapping type, with a description and command to execute. The <isCmd> argument adds <CR> on the end if 1 and nothing if 0. SpBind 'tmap', 'wj', 'window-down', 'wincmd j', 1
SpFileTypeMap <filetype>, <binding>, <name>, <value>, [isCmd] Map a key with map/noremap, only shown under a specific filetype, with a description and command to execute. <isCmd> defaults to 1 (i.e. adds <CR>). SpFileTypeMap 'haskell', 'mgt', 'show-type-at', 'GhcModType'
SpFileTypeNMap <filetype>, <binding>, <name>, <value>, [isCmd] Map a key with nmap/nnoremap, only shown under a specific filetype, with a description and command to execute. <isCmd> defaults to 1 (i.e. adds <CR>). SpFileTypeNMap 'haskell', 'mgt', 'show-type-at', 'GhcModType'

And the API for various helper functions,

Command Arguments Description Example
SpAddPlugin <PluginName>, [Configuration] Adds a plugin to load with vim-plug optionally with a vim-plug configuration. SpAddPlugin 'Shougo/vimproc.vim', { 'for': 'haskell', 'do' : 'make' }
SpSpaceIndent <filetype>, <indentation> Set the amount of spaces a certain filetype is indented. SpSpaceIndent 'haskell', 2
SpTabsIndent <filetype>, <indentation> Set the amount of tabs a certain filetype is indented. SpTabsIndent 'go', 8
SpLoadFunc <path-to-script>, <file-name> Load (source) a file into Vim. SpLoadFunc expand('<sfile>:p') 'other-file.vim'' for loading 'other-file.vim' in the layer directory

Add a Keybinding

To add a keybinding, first make sure that the vim-leader-guide grouping exists with

" Top level grouping (i.e. SPC e)
let g:lmap.e = get(g:lmap, 'e', { 'name': 'errors' })
" Deeper level Grouping under SPC e m
let g:lmap.e.m = get(g:lmap.e, 'm', { 'name': 'more' })

NOTE: It is important to use get() to avoid overwriting the mapping if it exists in another layer already.

ANOTHER NOTE: if you are adding a new language, you don't have to add the grouping, since let g:lmap.m = { 'name': 'major-mode-cmd' } already exists.

The e in g:lmap.e denotes the key that the group is under. Then add your keybinding by using SpBind or the shorter SpMap/SpMap,

SpBind 'map', 'eC', 'neomake-check-file', 'Neomake', 1
" Is equivalent to,
SpMap 'eC', 'neomake-check-file', 'Neomake'

SpBind 'nmap', 'eC', 'neomake-check-file', 'Neomake', 0
" Is equivalent to (default value is `1`, so we explicitly say `0` to not automatically add `<CR>` behind),
SpMap 'eC', 'neomake-check-file', 'Neomake', 0

which puts the keybinding at SPC e l. Note that the first e in el is necessary to put it under the e grouping.

For more check out the +nav/buffers layer for an example of usage, and keybinding-helpers.vim for the helper functions.

Adding Packages

This time we use SpAddPlugin to add the plugin and its vim-plug configuration,

SpAddPlugin 'neomake/neomake'
SpAddPlugin 'Shougo/vimproc.vim', { 'for': 'haskell', 'do' : 'make' }

which will add the package 'neomake/neomake' to be installed with the configuration {} (default value), and 'Shougo/vimproc.vim' with the more complex configuration { 'for': 'haskell', 'do' : 'make' }. The configuration can be used for post-installation commands or to lazy-load the plugin (e.g. only loading a language plugin when that language filetype is active).

Including Files

To keep the files a bit more clean, your functions should reside in separate files, such as func.vim. If func.vim is found in your layer, it is automaticaly included as the first item. To easily include other files, use,

" Load `func.vim` in the current layer directory
SpLoadFunc expand('<sfile>:p')

" Load `other-file.vim` in current layer directory
SpLoadFunc expand('<sfile>:p'), 'other-file.vim'

The expand('<sfile>:p') bit is to include the path of the current layer that is calling the SpLoadFunc function. If no second argument is given it defaults to func.vim, since that is the normal convention.

For more check out the +nav/files layer for an example of usage, and helpers.vim for the helper functions.

Adding a New Language Layer

Most of adding a new language layer is just like adding a normal layer, except for keybindings and groupings, as described below.

Add a language keybinding

Adding a language keybinding is a bit different, since we only want it shown when the language is actually active. All language keybindings should be under SPC m, and if you use the helper functions, that's also where they'll go.

It consist of two combined steps:

  1. Add your groupings
  2. Add your mappings

Step 1. and step 2. is done using au FileType MYFILETYPE, for example, a snippet of the haskell keybindings,

au FileType haskell let g:lmap.m = { "name": "major-mode-cmd",
\"c": ["GhcModCheckAndLintAsync", "ghcmod/check"],
\"r": { "name": "haskell/refactor"
     \, "b": ["call ApplyAllSuggestion()", "hlint/refactor-buffer"]
     \, "r": ["all ApplyOneSuggestion()", "hlint/refactor-at-point"]
  \ },
\"h": { "name": "haskell/documentation"
     \, "h": ["SpaceNeovimHaskellHoogle", "search-hoogle"]
     \, "t": ["GhcModType", "ghcmod/type-at"]
     \, "i": ["GhcModInfo", "ghcmod/info"]
  \ },
\}

We simply construct a new dictionary mapping for g:lmap.m which is only valid under our filetype, and contains the commands we want to bind. A "name": "haskell/grouping" defines a simple grouping and a ["GhcModCheckAndLintAsync", "ghcmod/check"] defines a command and description respectively.

Note: The reason it's defined under a filetype in this tedious way, is so that we get unique mappings for each filetype and that the change happens automatically.

For more check out the +lang/haskell layer for an example of usage, and bindings.vim for the helper functions.

Pre-commit linting

It is recommended to add the following to .git/hooks/pre-commit,

# Get the current dir
startDir=$(pwd)
# Get the project root
rootDir=$(git rev-parse --show-toplevel)

cd $rootDir

# Run vint
vint auto-layers.vim keybinding-helpers.vim helpers.vim

spaceneovim-layers's People

Contributors

aodq avatar azuwis avatar brett avatar nikonakoneko avatar srstevenson avatar tehnix avatar vviikk avatar yshalenyk avatar ytang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

spaceneovim-layers's Issues

Question about SpFileTypeBind

Hi,

I've just discovered this project, and thanks for making my configuation simpler, and more poweer at the same time! ๐Ÿ˜„

SpFileTypeBind/Map/NMap are all marked as broken in the documentation.
Is that something that's being worked on?
What would be a good workaround to have language specific shortcuts?

Thanks

Window 1-10 commands are not working as intended

It seems the mappings for SPC 0-9 (i.e. opening window 1-10) are currently not mapping correctly. Instead they are triggering a search, whereas they should be calling 1 wincmd w to go to the window given by the number.

Updating Spaceneovim layers Fails

Hi, when trying to update the spaceneovim layers (for me it was space -> f -> e -> (u)pdate layers) I get the following error messages:

Error detected while processing function <SNR>32_update_spaceneovim_layers:                                                   
line    2:                                                                                                                    
E461: Illegal variable name: a:home_dir                                                                                       
Updating SpaceNeovim layers, please hold on...                                                                                
line    5:                                                                                                                    
E121: Undefined variable: a:home_dir                                                                                          
E116: Invalid arguments for function resolve                                                                                  
E116: Invalid arguments for function expand                                                                                   
E15: Invalid expression: expand(resolve(a:home_dir . '/.config/nvim'))                                                        
line    8:                                                                                                                    
E461: Illegal variable name: a:config_dir                                                                                     
line    9:                                                                                                                    
E121: Undefined variable: a:config_dir                                                                                        
E116: Invalid arguments for function resolve                                                                                  
E116: Invalid arguments for function expand                                                                                   
E15: Invalid expression: expand(resolve(a:config_dir . '/spaceneovim-layers'))                                                
line   11:                                                                                                                    
E461: Illegal variable name: a:scratch_buffer                                                                                 
line   14:                                                                                                                    
E121: Undefined variable: a:scratch_buffer                                                                                    
E15: Invalid expression: {  'out': ['Updating SpaceNeovim layers'], 'buf': a:scratch_buffer}                                  
line   18:                                                                                                                    
E121: Undefined variable: data                                                                                                
E116: Invalid arguments for function function                                                                                 
E15: Invalid expression: {  'on_stdout': function('OutputJobToBuffer', data), 'on_stderr': function('OutputJobToBuffer', data)
, 'on_exit': function('OutputJobExitToBuffer', [function('g:SyncConfiguration')], data), 'cwd': a:spacevim_layers_dir}        
line   24:                                                                                                                    
E121: Undefined variable: l:job_options                                                                                       
E116: Invalid arguments for function jobstart                                                                                 
E15: Invalid expression: jobstart([  'git', 'pull', 'origin', 'master'], l:job_options)

update-spaceneovim-layers isn't working on stable release of neovim(0.1.5)

So I noticed on another machine that is running the latest stable release of Neovim (0.1.5) that the function that is supposed to update the spaceneovim layers results in a runtime error. The screenshot below shows the result of invoking the corresponding keybinding feU

screen shot 2016-10-22 at 00 36 53 1

It seems that the nvim_buf_set_lines function isn't present in the current stable release of Neovim. It works fine however in 0.1.6, which is the unstable release. I'm not sure what part of the target audience of spaceneovim is actually using the HEAD version of Neovim but that is definitely something to keep in mind whilst adding new features.

woop

Not the best place to leave a message, but the only place I can reach you. Is IRC down?

Use idiomatic locations for viminfo (shada) and undodir

By default, Neovim stores viminfo (a.k.a. shada) at ~/.local/share/nvim/shada/main.shada and undodir at ~/.local/share/nvim/undo (see :h shada-file-name and :h undodir). FYI, Neovim has clear distinction on the usage of $XDG_CONFIG_HOME and $XDG_DATA_HOME (see neovim/neovim#3470). Would you please not overwrite them with non-idiomatic paths in +core/sensible, or provide an option of just using the default paths? Thanks!

Keybinding conflict: Ctrl-K

Ctrl-K is used both in +nav/text and in +completion/snippets. Since both layers are enabled by default in vimrc.sample.vim, it would be ideal to avoid any conflict.

+lang/rust undefined variable g:sp_format_on_save

On a fresh install when I enable +lang/rust layer I get the following error:

Error detected while processing /home/andrea/.config/nvim/spaceneovim-layers/layers/+lang/rust/config.vim:                                                     
line   23:                                                                                                                                                     
E121: Undefined variable: g:sp_format_on_save                                                                                                                  
E15: Invalid expression: g:sp_format_on_save                                                                                                                   
"main.rs" 3L, 45C                                                                                                                                              
E121: Undefined variable: g:sp_format_on_save

Language Server with Python and virtual env

I have the language server setup running and working for php. But I am trying to get it running for python. It seems to be running, but none of the commands work. I think it may be because it is not seeing the required virutal environment for a given project.

Does anyone know how I can specify a virtualenv based on a directory or project I am in?

Terminal enhancements

Moved from original issue Tehnix/spaceneovim#11, opened by @alexanderjeurissen.

Whilst testing spaceneovim I came across several terminal related issues. Most of these issues are rather easily fixed and will drastically improve the experience of using terminal splits in spaceneovim.

  1. Using WinCmd's in neovim terminal splits
  2. Entering insertmode when entering a terminal split using WinCmd's
  3. closing the terminal split when the terminal process exits (or when a user manually types exit in the prompt)

Regarding the first issue, I've had this issue at first in my own neovim config aswel. The problem is that the terminal doesn't execute vim commands unless you have specific tnoremap bindings. as the documentation states:

Navigating to other windows is only possible by exiting to normal mode, which
can be cumbersome with <C-> keys.

I solved this in my own config using:

 " Window navigation between terminal and nonterminal {{{
    tnoremap <silent> <leader>wh <C-\><C-n><C-w>h
    tnoremap <silent> <leader>wj <C-\><C-n><C-w>j
    tnoremap <silent> <leader>wk <C-\><C-n><C-w>k
    tnoremap <silent> <leader>wl <C-\><C-n><C-w>l

    tnoremap <silent> <leader>wv <C-\><C-n>:vs<cr>:startinsert<cr>
    tnoremap <silent> <leader>ws <C-\><C-n>:split<cr>:startinsert<cr>
"}}}

The second issue can be solved with a single autocmd

au BufEnter * if &buftype == 'terminal' | :startinsert | endif

The third issue, I'm not sure how and if we can fix that..


When looking into this some more I discovered that there are terminal bindings defined in layers/+nav/windows/config.vim however they make use of wincmd command which isn't executed correctly when you are in insertmode in the terminal.

So replacing these with the approach I've outlined above should remedy this. I'll create a PR for this tonight.

API enhancements

Pinging @lowski

I was wondering if you had any wishes for improvements to the layer workflow? Like missing functions, renaming things etc.

I'll also use this opportunity to let you know that I've more or less revamped the user API in init.vim to add layers. Feels much cleaner! Check out the README in https://github.com/Tehnix/spaceneovim and let me know if you have any thoughts :)

Mapping for ALEDetail

Hi,
I'm programming in Haskell, and the formatted messages are mostly unreadable when put on one line.
A mapping to ALEDetail would be very nice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.