aboutsummaryrefslogtreecommitdiffstats
path: root/nixos/vim.nix
blob: 461339028a3447499db0d2191131a71102143512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{pkgs, ...}: {
  environment = {
    systemPackages = with pkgs; [
      (
        (vim_configurable.override {}).customize {
          name = "vim";
          vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
            start = [
              nerdcommenter
              vim-airline
              vim-airline-themes
              vim-colors-solarized
              vim-sleuth
              vim-surround
              undotree
            ];
            opt = [];
          };
          vimrcConfig.customRC = ''
            filetype off
            set nocompatible
            set modelines=0
            set encoding=utf-8
            set scrolloff=3
            set wildmode=list:longest
            set visualbell
            set backspace=indent,eol,start
            set laststatus=2
            set number
            set history=1000
            set title
            set ignorecase
            set smartcase
            set gdefault
            set incsearch
            set showmatch
            set hlsearch

            let mapleader = ","
            nmap <silent> <leader><space> :silent :nohlsearch<CR>

            set wrap
            set textwidth=0
            set list
            set listchars=tab:▸\ ,eol:¬
            set mousehide
            set mouse=a
            set cursorline
            set cursorcolumn

            set backupdir=~/.local/vim/backup
            set directory=~/.local/vim/swap
            set undodir=~/.local/vim/undo

            for _dir in ["backup", "swap", "undo"]
              let target_path = expand("~/.local/vim/" . _dir)
              if !isdirectory(target_path)
                call mkdir(target_path, "p", 0700)
              endif
            endfor

            au VimResized * exe "normal! \<c-w>="

            augroup vimrc_autocmd
              autocmd!

              " jump to the last position when reopening a file
              autocmd BufReadPost *
                \ if line("'\"") > 1 && line("'\"") <= line("$") |
                \   exe "normal! g`\"" |
                \ endif
            augroup END

            syn on
            set background=dark
            colorscheme solarized

            nnoremap <F5> :UndotreeToggle<CR>
            if has("persistent_undo")
              set undofile
            endif
          '';
        }
      )
    ];

    variables = {
      EDITOR = "vim";
      VISUAL = "vim";
    };
  };
}