Home Random

Neovim

Is a fork from the original vim-project. Some key-features are:

Vimscript essentials#

The most fundamental config without lua.

filetype plugin indent on

set expandtab
set tabstop=2
set softtabstop=2
set shiftwidth=2

" Indentation and re-selection
vnoremap > >gv
vnoremap < <gv

Keybindings Cheat Sheet#

These just work with my setup, which is not public (right now).

Syntax-Highlighting#

By default neovim has native syntax highlighting which cannot take it up with Treesitter. When Treesitter is setup, you can install treesitter-parsers with the following command.

:TSInstall <tab>

By pressing the autocompletion shows you a plethora of installable languages.

With the :InspectTree you can display the the AST (Abstract-Syntax-Tree) in a speperate window.

Treesitter-Install#

Beforehand you need to have Treesitter setup by your package-manager (in this case lazy.nvim):

return
  {
    {
      "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      config = function()
        require("nvim-treesitter.configs").setup(
        {
          ensure_installed = { "lua", "vim", "go", "python", "bash" },
          auto_install = true,
          highlight = {
            enable = true,
          },
          ignore_install = { "ruby" },
        }) end,
    },
  }

How to rename a variable?#

There are several cases where you would want to rename a variable. The place before the s is reserved for the scope, which is:

Go to the string of your choice and press *. All matched occurences will be highlighted. Then do

:%s/

With C-r you can paste the highlighted string. At first it looks like this

:%s/"

After a /:

:%s/\<string\>

Continue with another / and your wanted string.

:%s/\<string\>/mynewstring/

You can now specifiy, if you want to change globally with g (don't know what this means) and if you want confirmation with c.

:%s/\<string\>/mynewstring/gc

Renaming a variable with LSP#

If you have lsp configured, you can do it with vim.lsp.buf.rename:

-- Source: https://github.com/neovim/nvim-lspconfig?tab=readme-ov-file#suggested-configuration
-- Keymaps for LSP
v.keymap.set("n", "<space>e", v.diagnostic.open_float)
v.api.nvim_create_autocmd("LspAttach", {
 group = v.api.nvim_create_augroup("UserLspConfig", {}),
 callback = function(ev)
  local opts = { buffer = ev.buf }
  v.keymap.set("n", "<space>rn", v.lsp.buf.rename, opts)
 end,
})

Renaming a variable in your entire project#

The native vim-way goes like that:

:grep <string> `<location>`
:grep h.maier `find . -type f`

The seconds command would search all subdirectorys for h.maier. Depending on the size of your project, this could take a while. You can always abort the grep with C-c. After finishing the search, you can load the found occurences into a quickfix list by doing a :copen.

If you use Telescope for searching (which is way more ergonimic than the grep-method) you can use C-q to load the found-occurences into a quickfix list.

From there on, :cdo is your friend. Replacing a variable-name goes like this:

:cdo %s/h.maier/nobody/gc

:cdo lets you iterate through the quickfix list and execute the given command for every entry.

Adding characters to the END of every line of selected text#

:'<,'>
:'<,'>norm A <the-string-of-my-choice>

Add at the end of every line#

:%norm A<stuff-that-you-want-to-add>

Which means:

How to enter the commandline history?#

Just press q: (not :q). Now you can browse through are executed commands and copy them.

Plugins#

The plugin manager of my choice is lazy.nvim. Have a look at lazy.folke.io to get to know how its done.

Lua#

Ein angenehmes Tool um den ganzen Lua-Code nach nem Herumfuschen übersichtlicher zu machen ist stylua. Mehr zu Lua gibt es hier: lua

Neovim in the Browser#

Troubleshooting#

Fehler nach Updates von Plugins#

In einer Vielzahl von Fällen treten Probleme nach Updates von Plugins auf. Lässt sich der Fehler nicht zur eigenen Konfiguration, sondern in den Quellcode des Plugin zurückverfolgen, ist es am einfachsten das Plugin einfach neu zu installieren.

Dies funktioniert unter Lazy.nvim in dem man das geklonte Repository unter ~/.local/share/nvim/lazy/<repo> löscht.