trying to fix nvim-tree wsl

This commit is contained in:
Christoph J. Scherr 2023-07-05 10:15:41 +02:00
parent 0454fc29ba
commit 3ca222f05f
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
2 changed files with 56 additions and 45 deletions

View File

@ -152,18 +152,18 @@ command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.org
" Mappings for CoCList " Mappings for CoCList
" Show all diagnostics " Show all diagnostics
nnoremap <silent><nowait> <space>CA :<C-u>CocList diagnostics<cr> nnoremap <silent><nowait> <leader>CA :<C-u>CocList diagnostics<cr>
" Manage extensions " Manage extensions
nnoremap <silent><nowait> <space>CE :<C-u>CocList extensions<cr> nnoremap <silent><nowait> <leader>CE :<C-u>CocList extensions<cr>
" Show commands " Show commands
nnoremap <silent><nowait> <space>CC :<C-u>CocList commands<cr> nnoremap <silent><nowait> <leader>CC :<C-u>CocList commands<cr>
" Find symbol of current document " Find symbol of current document
nnoremap <silent><nowait> <space>CO :<C-u>CocList outline<cr> nnoremap <silent><nowait> <leader>CO :<C-u>CocList outline<cr>
" Search workspace symbols " Search workspace symbols
nnoremap <silent><nowait> <space>CS :<C-u>CocList -I symbols<cr> nnoremap <silent><nowait> <leader>CS :<C-u>CocList -I symbols<cr>
" Do default action for next item " Do default action for next item
nnoremap <silent><nowait> <space>CJ :<C-u>CocNext<CR> nnoremap <silent><nowait> <leader>CJ :<C-u>CocNext<CR>
" Do default action for previous item " Do default action for previous item
nnoremap <silent><nowait> <space>CK :<C-u>CocPrev<CR> nnoremap <silent><nowait> <leader>CK :<C-u>CocPrev<CR>
" Resume latest coc list " Resume latest coc list
nnoremap <silent><nowait> <space>CP :<C-u>CocListResume<CR> nnoremap <silent><nowait> <leader>CP :<C-u>CocListResume<CR>

View File

@ -3,8 +3,9 @@ nnoremap <F5> :NvimTreeToggle<CR>
lua << EOF lua << EOF
local HEIGHT_RATIO = 0.8 -- You can change this -- disable netrw at the very start of your init.lua
local WIDTH_RATIO = 0.8 -- You can change this too vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
local function my_on_attach(bufnr) local function my_on_attach(bufnr)
local api = require "nvim-tree.api" local api = require "nvim-tree.api"
@ -13,46 +14,56 @@ local function my_on_attach(bufnr)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end end
-- default mappings -- default mappings
api.config.mappings.default_on_attach(bufnr) -- for some reason, this does not work well when loaded with a wsl linux.
-- attempt to index field 'config' (a nil value)
-- which does not make sense, as config is a defined field of the Api variable
api.config.mappings.default_on_attach(bufnr)
-- custom mappings -- custom mappings
-- cd -- cd
vim.keymap.set('n', '<C-c>', api.tree.change_root_to_node, opts('Up')) vim.keymap.set('n', '<C-c>', api.tree.change_root_to_node, opts('Up'))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help')) -- default is g?
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end end
-- empty setup using defaults local HEIGHT_RATIO = 0.8
require("nvim-tree").setup() local WIDTH_RATIO = 0.8
require('nvim-tree').setup({
view = { -- set termguicolors to enable highlight groups
float = { vim.opt.termguicolors = true
enable = true,
open_win_config = function() -- setup with some options
local screen_w = vim.opt.columns:get() require("nvim-tree").setup({
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() sort_by = "case_sensitive",
local window_w = screen_w * WIDTH_RATIO view = {
local window_h = screen_h * HEIGHT_RATIO float = {
local window_w_int = math.floor(window_w) enable = true,
local window_h_int = math.floor(window_h) open_win_config = function()
local center_x = (screen_w - window_w) / 2 local screen_w = vim.opt.columns:get()
local center_y = ((vim.opt.lines:get() - window_h) / 2) local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
- vim.opt.cmdheight:get() local window_w = screen_w * WIDTH_RATIO
return { local window_h = screen_h * HEIGHT_RATIO
border = 'rounded', local window_w_int = math.floor(window_w)
relative = 'editor', local window_h_int = math.floor(window_h)
row = center_y, local center_x = (screen_w - window_w) / 2
col = center_x, local center_y = ((vim.opt.lines:get() - window_h) / 2)
width = window_w_int, - vim.opt.cmdheight:get()
height = window_h_int, return {
} border = 'rounded',
relative = 'editor',
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
width = function()
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end, end,
}, },
width = function() on_attach = my_on_attach,
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end,
},
on_attach = my_on_attach,
}) })
EOF EOF