dotfiles

config files for my linux setup
git clone git://edryd.org/dotfiles
Log | Files | Refs | README

init.lua (4778B)


      1 require("config.lazy")
      2 vim.cmd('source ~/.config/nvim/vimrc.vim')
      3 
      4 vim.g.mapleader = ' '
      5 
      6 ---- Mappings
      7 
      8 function _G.set_terminal_keymaps()
      9   local opts = {buffer = 0}
     10   vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
     11   vim.keymap.set('t', 'jj',    [[<C-\><C-n>]], opts)
     12   vim.keymap.set('t', '<A-h>', [[<Cmd>wincmd h<CR>]], opts)
     13   vim.keymap.set('t', '<A-j>', [[<Cmd>wincmd j<CR>]], opts)
     14   vim.keymap.set('t', '<A-k>', [[<Cmd>wincmd k<CR>]], opts)
     15   vim.keymap.set('t', '<A-l>', [[<Cmd>wincmd l<CR>]], opts)
     16   vim.keymap.set('t', '<C-w>', [[<C-\><C-n><C-w>]], opts)
     17 end
     18 vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
     19 
     20 vim.keymap.set('n', '<A-h>', [[<C-w>h]])
     21 vim.keymap.set('n', '<A-j>', [[<C-w>j]])
     22 vim.keymap.set('n', '<A-k>', [[<C-w>k]])
     23 vim.keymap.set('n', '<A-l>', [[<C-w>l]])
     24 
     25 -- TODO nmap <C-w>> 5<C-w>>
     26 
     27 -- Switch between C source and header files
     28 if vim.bo.filetype == 'c' then
     29   vim.keymap.set('n', '<leader>a', 'edit %<.h')
     30 elseif vim.bo.filetype == 'h' then
     31   vim.keymap.set('n', '<leader>a', 'edit %<.c')
     32 end
     33 
     34 
     35 ---- Plugins
     36 
     37 ---- FZF
     38 local fzf = require('fzf-lua')
     39 vim.keymap.set('n', '<leader>f', fzf.files, {})
     40 vim.keymap.set('n', '<leader>g', fzf.live_grep, {})
     41 vim.keymap.set('n', '<leader>b', fzf.buffers, {})
     42 vim.keymap.set('n', '<leader>t', fzf.tags, {})
     43 -- vim.keymap.set('c', 'help', fzf.help_tags, {})
     44 
     45 -- vim.keymap.set('n', '<leader>m', , {})
     46 
     47 ---- ToggleTerm
     48 local set_opfunc = vim.fn[vim.api.nvim_exec(
     49 [[
     50 func s:set_opfunc(val)
     51 let &opfunc = a:val
     52 endfunc
     53 echon get(function('s:set_opfunc'), 'name')
     54   ]], true
     55 )]
     56 -- Send motion to terminal
     57 vim.keymap.set("n", [[<leader><c-_>]], function()
     58   set_opfunc(function(motion_type)
     59     require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
     60   end)
     61   vim.api.nvim_feedkeys("g@", "n", false)
     62 end)
     63 -- TODO breaks send motion ↑
     64 -- Double the command to send line to terminal
     65 -- vim.keymap.set("n", [[<leader><c-_><c-_>]], function()
     66 --   set_opfunc(function(motion_type)
     67 --     require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
     68 --   end)
     69 --   vim.api.nvim_feedkeys("g@_", "n", false)
     70 -- end)
     71 -- Send whole file
     72 vim.keymap.set("n", [[<leader><leader><c-_>]], function()
     73   set_opfunc(function(motion_type)
     74     require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
     75   end)
     76   vim.api.nvim_feedkeys("ggg@G''", "n", false)
     77 end)
     78 
     79 --- Treesitter
     80 require'nvim-treesitter.configs'.setup {
     81   -- A list of parser names, or "all" (the listed parsers MUST always be installed)
     82   ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" },
     83 
     84   -- Install parsers synchronously (only applied to `ensure_installed`)
     85   sync_install = false,
     86 
     87   -- Automatically install missing parsers when entering buffer
     88   -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
     89   auto_install = true,
     90 
     91   -- List of parsers to ignore installing (or "all")
     92   ignore_install = { "javascript" },
     93 
     94   ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
     95   -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
     96 
     97   highlight = {
     98     enable = true,
     99 
    100     -- list of language that will be disabled
    101     disable = { "markdown" },
    102 
    103     -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    104     -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    105     -- Using this option may slow down your editor, and you may see some duplicate highlights.
    106     -- Instead of true it can also be a list of languages
    107     additional_vim_regex_highlighting = false,
    108   },
    109 }
    110 
    111 -- Orgmode
    112 vim.api.nvim_set_hl(0, "@org.headline.level2.org", { link = "Title" })
    113 vim.api.nvim_set_hl(0, "@variable", { link = "Ignore" })
    114 vim.api.nvim_set_hl(0, "@variable.parameter", { link = "Ignore" })
    115 vim.wo.foldmethod = 'expr'
    116 vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
    117 vim.wo.foldlevel = 8
    118 
    119 vim.opt.conceallevel = 2
    120 -- vim.opt.concealcursor = 'nc'
    121 
    122 
    123 ---- LSP
    124 require'lspconfig'.pyright.setup{}
    125 vim.api.nvim_create_autocmd('FileType', {
    126   -- This handler will fire when the buffer's 'filetype' is "python"
    127   pattern = 'racket',
    128   callback = function(ev)
    129     vim.lsp.start({
    130       name = 'racket',
    131       cmd = {'racket', '-l', 'racket-langserver'},
    132 
    133       -- Set the "root directory" to the parent directory of the file in the
    134       -- current buffer (`ev.buf`) that contains either a "setup.py" or a
    135       -- "pyproject.toml" file. Files that share a root directory will reuse
    136       -- the connection to the same LSP server.
    137       -- root_dir = vim.fs.root(ev.buf, {'setup.py', 'pyproject.toml'}),
    138     })
    139   end,
    140 })