Skip to content

adachng/nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

$HOME/.config/nvim

Table of Contents

Overview

This repository serves as version-controlled Neovim config:

cd $HOME/.config && git clone <THIS_REPO>

Non-plugin Keymaps

clang-format

vim.keymap.set(
    'n',
    '<leader>cf',
    ':w<Enter>:!clang-format -style=file -i %<Enter>:e!<Enter>',
    { desc = 'clang-format -style=file -i' }
)

vim.diagnostic.open_float()

vim.keymap.set(
    'n',
    '<leader>do',
    vim.diagnostic.open_float,
    { desc = 'vim.diagnostic.open_float()' }
)

Plugin-related Keymap Prefixes

If applicable, all keymaps associated with a plugin are grouped by prefixes.

For example, the keymap prefix for telescope.nvim is <leader>f, and the keymap to run require('telescope.builtin').find_files() is <leader>ff.

Plugin Keymap Prefix
cppassist.nvim <leader>c
⚡flash.nvim <leader>s
grug-far.nvim <leader>g
Harpoon 2 <leader><leader>
nvim-tree <leader>t
Persistence <leader>q
telescope.nvim <leader>f

Plugins

Pastel theme for Neovim (appearance only).

Toggle comments.

Usage

These mappings are enabled by default. (config: mappings.basic)

  • NORMAL mode
`gcc` - Toggles the current line using linewise comment
`gbc` - Toggles the current line using blockwise comment
`[count]gcc` - Toggles the number of line given as a prefix-count using linewise
`[count]gbc` - Toggles the number of line given as a prefix-count using blockwise
`gc[count]{motion}` - (Op-pending) Toggles the region using linewise comment
`gb[count]{motion}` - (Op-pending) Toggles the region using blockwise comment
  • VISUAL mode
`gc` - Toggles the region using linewise comment
`gb` - Toggles the region using blockwise comment

C/C++ assistance to generate implementation in corresponding source file.

Custom fork considers CUDA code.

Requires brew install fd.

Usage

        local cppassist = require('cppassist')
        cppassist.setup(opts)

        local map = vim.keymap.set
        local keymap_prefix = '<leader>c'

        -- switch between source and header
        map(
            'n',
            keymap_prefix .. 's',
            cppassist.SwitchSourceAndHeader,
            { desc = 'cppassist switch source and header' }
        )
        -- generate the function definition or static variable definition in source
        map(
            'n',
            keymap_prefix .. 'c',
            cppassist.ImplementInSource,
            { desc = 'cppassist implement in source' }
        )
        -- generate the function definition or static variable definition in source in visual mode
        map(
            'v',
            keymap_prefix .. 'C',
            cppassist.ImplementInSourceInVisualMode,
            { desc = 'cppassist implement in source in visual mode' }
        )
        -- generate the function definition or static variable definition in header
        map(
            'n',
            keymap_prefix .. 'o',
            cppassist.ImplementOutOfClass,
            { desc = 'cppassist implement out of class' }
        )
        -- goto the header file
        map(
            'n',
            keymap_prefix .. 'g',
            cppassist.GotoHeaderFile,
            { desc = 'cppassist go to header file' }
        )

Fast code navigation via search labels.

Usage

        {
            '<leader>ss',
            mode = { 'n', 'x', 'o' },
            function()
                require('flash').jump()
            end,
            desc = 'Flash',
        },
        {
            '<leader>sS',
            mode = { 'n', 'x', 'o' },
            function()
                require('flash').treesitter()
            end,
            desc = 'Flash Treesitter',
        },
        {
            '<leader>sr',
            mode = 'o',
            function()
                require('flash').remote()
            end,
            desc = 'Remote Flash',
        },
        {
            '<leader>sR',
            mode = { 'o', 'x' },
            function()
                require('flash').treesitter_search()
            end,
            desc = 'Treesitter Search',
        },
        {
            '<leader>s<c-s>',
            mode = { 'c' },
            function()
                require('flash').toggle()
            end,
            desc = 'Toggle Flash Search',
        },

VSCode-style search-and-replace menu (CTRL + SHIFT + H).

Do <leader>gf to open the window.

Quickly jump between specified set of files.

Usage

        local keymap_prefix = '<leader><leader>'
        vim.keymap.set('n', keymap_prefix .. 'q', function()
            harpoon.ui:toggle_quick_menu(harpoon:list())
        end, { desc = 'harpoon toggle quick menu' })
        vim.keymap.set('n', keymap_prefix .. 'a', function()
            harpoon:list():add()
        end, { desc = 'harpoon add' })
        vim.keymap.set('n', keymap_prefix .. 'c', function()
            harpoon:list():clear()
        end, { desc = 'harpoon clear' })

        for i = 1, 9 do
            -- HarpoonList:select()
            vim.keymap.set('n', keymap_prefix .. tostring(i), function()
                harpoon:list():select(i)
            end, { desc = 'harpoon select ' .. tostring(i) })

            -- HarpoonList:replace_at()
            vim.keymap.set(
                'n',
                keymap_prefix .. 's' .. tostring(i), -- 's' for set
                function()
                    harpoon:list():replace_at(i)
                end,
                { desc = 'harpoon set ' .. tostring(i) }
            )

            -- HarpoonList:remove_at()
            vim.keymap.set(
                'n',
                keymap_prefix .. 'd' .. tostring(i), -- 'd' for delete
                function()
                    harpoon:list():remove_at(i)
                end,
                { desc = 'harpoon delete ' .. tostring(i) }
            )
        end

To split the file in the quick menu:

        harpoon:extend({
            UI_CREATE = function(cx)
                vim.keymap.set('n', '<C-v>', function()
                    harpoon.ui:select_menu_item({ vsplit = true })
                end, { buffer = cx.bufnr })

                vim.keymap.set('n', '<C-x>', function()
                    harpoon.ui:select_menu_item({ split = true })
                end, { buffer = cx.bufnr })

                vim.keymap.set('n', '<C-t>', function()
                    harpoon.ui:select_menu_item({ tabedit = true })
                end, { buffer = cx.bufnr })
            end,
        })

Plugin for finding and suggesting memorable and easy-to-press keys for nvim shortcuts with ability to mark duplicates.

Usage

Do :HawtKeys.

Automatically install the Language Server Protocols (LSPs) specified in the opts.ensure_installed of the plugin spec.

The following plugins are dependencies:

  • blink.cmp v1
    • Autocompletion suggestions with controls similar to VSCode's autocompletion.
  • mason.nvim
    • Mandatory. Portable package manager to install and manage LSP servers, DAP servers, linters, and formatters.
  • nvim-lspconfig
    • Collection of LSP server configurations. Included so mason.nvim can actually hook the LSP client to the servers.

mason.nvim handles downloading and managing the LSP binaries, while mason-lspconfig.nvim is explicitly designed to bridge mason.nvim and nvim-lspconfig so that servers installed by mason.nvim are automatically wired into nvim-lspconfig configurations.

Enables multi-cursor.

Usage

    {"<C-j>", "<Cmd>MultipleCursorsAddDown<CR>", mode = {"n", "x"}, desc = "Add cursor and move down"},
    {"<C-k>", "<Cmd>MultipleCursorsAddUp<CR>", mode = {"n", "x"}, desc = "Add cursor and move up"},

    {"<C-Up>", "<Cmd>MultipleCursorsAddUp<CR>", mode = {"n", "i", "x"}, desc = "Add cursor and move up"},
    {"<C-Down>", "<Cmd>MultipleCursorsAddDown<CR>", mode = {"n", "i", "x"}, desc = "Add cursor and move down"},

    {"<C-LeftMouse>", "<Cmd>MultipleCursorsMouseAddDelete<CR>", mode = {"n", "i"}, desc = "Add or remove cursor on mouse click"},
    {"<C-Return>", "<Cmd>MultipleCursorsAddDelete<CR>", mode = {"n"}, desc = "Add a locked cursor or remove an existing cursor"},

    {"<Leader>m", "<Cmd>MultipleCursorsAddVisualArea<CR>", mode = {"x"}, desc = "Add cursors to the lines of the visual area"},

    {"<Leader>a", "<Cmd>MultipleCursorsAddMatches<CR>", mode = {"n", "x"}, desc = "Add cursors to cword"},
    {"<Leader>A", "<Cmd>MultipleCursorsAddMatchesV<CR>", mode = {"n", "x"}, desc = "Add cursors to cword in previous area"},

    {"<Leader>d", "<Cmd>MultipleCursorsAddJumpNextMatch<CR>", mode = {"n", "x"}, desc = "Add cursor and jump to next cword"},
    {"<Leader>D", "<Cmd>MultipleCursorsJumpNextMatch<CR>", mode = {"n", "x"}, desc = "Jump to next cword"},

    {"<Leader>l", "<Cmd>MultipleCursorsLock<CR>", mode = {"n", "x"}, desc = "Lock virtual cursors"},

Usage

        local keymap_prefix = '<leader>t'
        vim.keymap.set('n', keymap_prefix .. 't', function()
            -- NOTE: do :lua print(vim.bo.filetype) to see for debug.
            if vim.bo.filetype == 'NvimTree' then
                api.tree.close()
            else
                api.tree.focus()
            end
        end, { desc = 'nvim-tree toggle focus' })
        vim.keymap.set(
            'n',
            keymap_prefix .. 'c',
            api.tree.close,
            { desc = 'nvim-tree close' }
        )

For the buffer-specific mappings:

 `<C-]>`           n    CD                         |nvim_tree.api.tree.change_root_to_node()|
 `<C-e>`           n    Open: In Place             |nvim_tree.api.node.open.replace_tree_buffer()|
 `<C-k>`           n    Info                       |nvim_tree.api.node.show_info_popup()|
 `<C-r>`           n    Rename: Omit Filename      |nvim_tree.api.fs.rename_sub()|
 `<C-t>`           n    Open: New Tab              |nvim_tree.api.node.open.tab()|
 `<C-v>`           n    Open: Vertical Split       |nvim_tree.api.node.open.vertical()|
 `<C-x>`           n    Open: Horizontal Split     |nvim_tree.api.node.open.horizontal()|
 `<BS>`            n    Close Directory            |nvim_tree.api.node.navigate.parent_close()|
 `<CR>`            n    Open                       |nvim_tree.api.node.open.edit()|
 `<Del>`           nx   Delete                     |nvim_tree.api.fs.remove()|
 `<Tab>`           n    Open Preview               |nvim_tree.api.node.open.preview()|
 `>`               n    Next Sibling               |nvim_tree.api.node.navigate.sibling.next()|
 `<`               n    Previous Sibling           |nvim_tree.api.node.navigate.sibling.prev()|
 `.`               n    Run Command                |nvim_tree.api.node.run.cmd()|
 `-`               n    Up                         |nvim_tree.api.tree.change_root_to_parent()|
 `a`               n    Create File Or Directory   |nvim_tree.api.fs.create()|
 `bd`              n    Delete Bookmarked          |nvim_tree.api.marks.bulk.delete()|
 `bt`              n    Trash Bookmarked           |nvim_tree.api.marks.bulk.trash()|
 `bmv`             n    Move Bookmarked            |nvim_tree.api.marks.bulk.move()|
 `B`               n    Toggle Filter: No Buffer   |nvim_tree.api.filter.no_buffer.toggle()|
 `c`               nx   Copy                       |nvim_tree.api.fs.copy.node()|
 `C`               n    Toggle Filter: Git Clean   |nvim_tree.api.filter.git.clean.toggle()|
 `[c`              n    Prev Git                   |nvim_tree.api.node.navigate.git.prev()|
 `]c`              n    Next Git                   |nvim_tree.api.node.navigate.git.next()|
 `d`               nx   Delete                     |nvim_tree.api.fs.remove()|
 `D`               nx   Trash                      |nvim_tree.api.fs.trash()|
 `E`               n    Expand All                 |nvim_tree.api.tree.expand_all()|
 `e`               n    Rename: Basename           |nvim_tree.api.fs.rename_basename()|
 `]e`              n    Next Diagnostic            |nvim_tree.api.node.navigate.diagnostics.next()|
 `[e`              n    Prev Diagnostic            |nvim_tree.api.node.navigate.diagnostics.prev()|
 `F`               n    Live Filter: Clear         |nvim_tree.api.filter.live.clear()|
 `f`               n    Live Filter: Start         |nvim_tree.api.filter.live.start()|
 `g?`              n    Help                       |nvim_tree.api.tree.toggle_help()|
 `gy`              n    Copy Absolute Path         |nvim_tree.api.fs.copy.absolute_path()|
 `ge`              n    Copy Basename              |nvim_tree.api.fs.copy.basename()|
 `H`               n    Toggle Filter: Dotfiles    |nvim_tree.api.filter.dotfiles.toggle()|
 `I`               n    Toggle Filter: Git Ignored |nvim_tree.api.filter.git.ignored.toggle()|
 `J`               n    Last Sibling               |nvim_tree.api.node.navigate.sibling.last()|
 `K`               n    First Sibling              |nvim_tree.api.node.navigate.sibling.first()|
 `L`               n    Toggle Group Empty         |nvim_tree.api.node.open.toggle_group_empty()|
 `M`               n    Toggle Filter: No Bookmark |nvim_tree.api.filter.no_bookmark.toggle()|
 `m`               nx   Toggle Bookmark            |nvim_tree.api.marks.toggle()|
 `o`               n    Open                       |nvim_tree.api.node.open.edit()|
 `O`               n    Open: No Window Picker     |nvim_tree.api.node.open.no_window_picker()|
 `p`               n    Paste                      |nvim_tree.api.fs.paste()|
 `P`               n    Parent Directory           |nvim_tree.api.node.navigate.parent()|
 `q`               n    Close                      |nvim_tree.api.tree.close()|
 `r`               n    Rename                     |nvim_tree.api.fs.rename()|
 `R`               n    Refresh                    |nvim_tree.api.tree.reload()|
 `s`               n    Run System                 |nvim_tree.api.node.run.system()|
 `S`               n    Search                     |nvim_tree.api.tree.search_node()|
 `u`               n    Rename: Full Path          |nvim_tree.api.fs.rename_full()|
 `U`               n    Toggle Filter: Custom      |nvim_tree.api.filter.custom.toggle()|
 `W`               n    Collapse All               |nvim_tree.api.tree.collapse_all()|
 `x`               nx   Cut                        |nvim_tree.api.fs.cut()|
 `y`               n    Copy Name                  |nvim_tree.api.fs.copy.filename()|
 `Y`               n    Copy Relative Path         |nvim_tree.api.fs.copy.relative_path()|
 `<2-LeftMouse>`   n    Open                       |nvim_tree.api.node.open.edit()|
 `<2-RightMouse>`  n    CD                         |nvim_tree.api.tree.change_root_to_node()|

Integrates tree-sitter into Neovim so that code is parsed as syntax tree.

Automated Neovim session management.

Usage

        local persistence = require('persistence')
        persistence.setup(opts)

        local keymap_prefix = '<leader>q'
        -- save session
        vim.keymap.set(
            'n',
            keymap_prefix .. 's',
            persistence.save,
            { desc = 'Persistence save' }
        )
        -- load the session for the current directory
        vim.keymap.set(
            'n',
            keymap_prefix .. 'q',
            persistence.load,
            { desc = 'Persistence load' }
        )
        -- select a session to load`
        vim.keymap.set(
            'n',
            keymap_prefix .. 'Q',
            persistence.select,
            { desc = 'Persistence select' }
        )
        -- load the session for the current directory
        vim.keymap.set('n', keymap_prefix .. 'l', function()
            persistence.load({ last = true })
        end, { desc = 'Persistence load last' })
        -- stop Persistence => session won't be saved on exit
        vim.keymap.set(
            'n',
            keymap_prefix .. 'd',
            persistence.stop,
            { desc = 'Persistence stop' }
        )

Allows opt.scrolloff to be applied even scrolling towards end-of-file.

Powerful plugin that provides pickers (UI element that displays one or more scrollable lists of values to choose from).

Usage

        local keymap_prefix = '<leader>f'
        vim.keymap.set(
            'n',
            keymap_prefix .. 'f',
            builtin.find_files,
            { desc = 'Telescope find files' }
        )
        vim.keymap.set(
            'n',
            keymap_prefix .. 'g',
            builtin.live_grep,
            { desc = 'Telescope live grep' }
        )
        vim.keymap.set(
            'n',
            keymap_prefix .. 'b',
            builtin.buffers,
            { desc = 'Telescope buffers' }
        )
        vim.keymap.set(
            'n',
            keymap_prefix .. 'h',
            builtin.help_tags,
            { desc = 'Telescope help tags' }
        )
        vim.keymap.set(
            'n',
            keymap_prefix .. 's',
            builtin.lsp_document_symbols,
            { desc = 'Telescope document symbols' }
        )
        vim.keymap.set(
            'n',
            keymap_prefix .. 'S',
            builtin.lsp_workspace_symbols,
            { desc = 'Telescope workspace symbols' }
        )

Helps to remember Neovim keymaps by showing available keybindings in a popup while typing.

About

My Neovim configurations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages