Skip to content

Instantly share code, notes, and snippets.

@nirdosh17
Last active July 26, 2024 15:53
Show Gist options
  • Save nirdosh17/52d4114e60f859cb7e2c1b4355222b19 to your computer and use it in GitHub Desktop.
Save nirdosh17/52d4114e60f859cb7e2c1b4355222b19 to your computer and use it in GitHub Desktop.
Neovim commands

Leader key

Create subcommands based on this key. e.g. If leader is space key, <space> + sf displays UI to search files.

Editing file contents

Using cursors

up/down/left/right cursor do exactly as they are named. Alternatively, you cna also use:

             k (up) 
    h(left)          l(right)
             j(down)

Scrolling

  • Paragraph: shift { or shift }
  • Using GOTO :<linenumber><enter>

Deletion Commands

In normal mode:

  • Press x to delete character at the cursor.
  • dap: deletes current paragraph
  • dw: deletes one word after cursor
  • d2w: deletes 2 words afte cursor. You can modify the number d<n>w
  • d$ deletes everything starting from the cursor to end of line.

Undo:

Press u as many times you want to undo.

Insertion

presss i to go to insert mode.

Appending

Presss shift+a. It moves the cursor to the end of line.

Multicursor edits

TBD

Deleting a file/folder

To go Neotree folder view and select the folder with cursor, and press d.


Commands: Operators and Motions

Many commans that change texts are made from operators and motion. e.g. format for delete command d motion. d = delete operator motion = w, e, $ Pressing just the motion, will move the cursor in the motion specified. e.g. if we only press w, cursor will move right by a word.

Using count for a motion

  • 2w moves to 2 words forward.
  • 0 start of line.

Using count to delete more

d count motion

  • d2w: delete two words

File actions

Go to end of file: G or shift + g Go to start of file: gg

Line actions [292]

  • Delete a whole line: dd
  • Deleting a line copies the line in Neovim's register. We can also paste it with p command.
  • Adding a count will delete N lines after cursor. For e.g. 2dd deletes 2 lines

Undo command:

  • u to undo last command.
  • U to fix a whole line. Returns just the line to its original state.
  • Redo: ctrl + r

Text selection and copying

  • yy to copy the line where cursor is
  • Type v to enter into visual mode.
  • y to yank or copy selected lines
  • p to paste
  • yap Yank Around Paragraph: means it copies whole paragraph moving cursor to the starting of the paragraph.

Put command or Paste command:

After selecting text or deleting with dd, we can type p to paste the line after the cursor.

Create a new file:

Shift+5 or %

Explore directory

  • `:Explore``
  • Go to ../ and press Enter.

Reload NVIM configs after change

  • Source whole configs: :source $MYVIMRC
  • Source changed file only: :source /path/to/your/config/file.lua

Plugin manager

  • Lazy.nvim and Nvchad. Lazy.nvim seems to be the better one.
  • To open plugin manager: :Lazy
  • To update all plugins: :Lazy update or press U after opening Lazy.
  • Displays how long it took to load nvim: :Lazy profile

Autocomplete

To apply suggestions: ctrl + y or enter, tab for next suggestion

Moving around tabs

  • gt or gT
  • close currenttab: :tabclose
  • Switch to a specific tab with number: :tabn 2

Replace(substitute) string

:%s/<original>/<text-to-replace> e.g. :%s/Hover/Definition

Run lua file in current buffer

source %

LSP

Go to definition

gd

Hover request

shift + k To enter inside hover window, press shift k again and nagivate documentation using usual key maps.

Code Actions

<leader> + ca

LSP Info

Shows which LSPs are running in current buffer. :LspInfo

Language client log: /Users/nirdosh/.local/state/nvim/lsp.log
 Detected filetype:   markdown

 1 client(s) attached to this buffer:

 Client: nirdoshgolsp (id: 1, bufnr: [1])
  filetypes:
  autostart:       false
  root directory:  Running in single file mode.
  cmd:             /Users/nirdosh/Personal/golsp/main

 Configured servers list: lua_ls, gopls

Autocommand events

When you are editing files, various events are fired e.g. opening buffer, entering into insert mode e.t.c. You can write your custom Lua code to trigger in this events. For example, autosaving file when we leave insert mode.

You can see all events using: :h autocmd-events

Open Terminal Tab

:tabnew | terminal and go to insert mode.


References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment