summary refs log tree commit diff stats
path: root/user
diff options
context:
space:
mode:
authorAlan Pearce2020-10-29 20:15:18 +0100
committerAlan Pearce2020-10-29 20:15:18 +0100
commitdd829bbad56e53a35d86e8e43165a92268339929 (patch)
treedb2a6cc99844a92da065692f3f237dc691a5f7c3 /user
parentbe7dd55d729eaf4c001790430bafe2b6115328c2 (diff)
downloadnixfiles-dd829bbad56e53a35d86e8e43165a92268339929.tar.lz
nixfiles-dd829bbad56e53a35d86e8e43165a92268339929.tar.zst
nixfiles-dd829bbad56e53a35d86e8e43165a92268339929.zip
neovim: configure smart completion
Diffstat (limited to 'user')
-rw-r--r--user/nvim/coc-settings.json5
-rw-r--r--user/nvim/init.vim25
-rw-r--r--user/settings/base.nix25
3 files changed, 44 insertions, 11 deletions
diff --git a/user/nvim/coc-settings.json b/user/nvim/coc-settings.json
new file mode 100644
index 00000000..718446b1
--- /dev/null
+++ b/user/nvim/coc-settings.json
@@ -0,0 +1,5 @@
+{
+	"json.enable": true,
+	"suggest.enablePreview": true
+}
+
diff --git a/user/nvim/init.vim b/user/nvim/init.vim
new file mode 100644
index 00000000..0b2438d5
--- /dev/null
+++ b/user/nvim/init.vim
@@ -0,0 +1,25 @@
+set autoindent
+
+set background=light
+set shiftwidth=2
+set tabstop=2
+set noexpandtab
+set relativenumber
+set smartcase
+
+" use <tab> for trigger completion and navigate to the next complete item
+function! s:check_back_space() abort
+  let col = col('.') - 1
+  return !col || getline('.')[col - 1]  =~ '\s'
+endfunction
+
+inoremap <silent><expr> <Tab>
+      \ pumvisible() ? "\<C-n>" :
+      \ <SID>check_back_space() ? "\<Tab>" :
+      \ coc#refresh()
+
+inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
+inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
+
+" use <c-space> to trigger completion
+inoremap <silent><expr> <c-space> coc#refresh()
diff --git a/user/settings/base.nix b/user/settings/base.nix
index b5031dc7..823aa5f3 100644
--- a/user/settings/base.nix
+++ b/user/settings/base.nix
@@ -9,20 +9,22 @@
   programs.neovim = {
     enable = true;
     vimAlias = true;
+    vimdiffAlias = true;
+    package = pkgs.unstable.neovim-unwrapped;
     configure = {
-      customRC = ''
-        set autoindent
-
-        set background=light
-        set shiftwidth=2
-        set tabstop=2
-        set noexpandtab
-        set relativenumber
-        set smartcase
-      '';
-      packages.myVimPackage = with pkgs.vimPlugins; {
+      customRC = builtins.readFile ../nvim/init.vim;
+      packages.myVimPackage = with pkgs.unstable.vimPlugins; {
         start = [
           commentary
+          coc-css
+          coc-eslint
+          coc-git
+          coc-html
+          coc-json
+          coc-nvim
+          coc-prettier
+          coc-tabnine
+          coc-yaml
           vim-surround
           vim-nix
         ];
@@ -30,6 +32,7 @@
       };
     };
   };
+  xdg.configFile."nvim/coc-settings.json".source = ../nvim/coc-settings.json;
   home.sessionVariables = {
     EMAIL = "alan@alanpearce.eu";
     XDG_CACHE_HOME = if pkgs.stdenv.isDarwin then "$HOME/Library/Caches/XDG" else "$HOME/.cache";