example_init.lua (3688B)
1 -- Set <space> as the leader key 2 -- See `:help mapleader` 3 -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) 4 vim.g.mapleader = ' ' 5 6 -- [[ Setting options ]] See `:h vim.o` 7 -- NOTE: You can change these options as you wish! 8 -- For more options, you can see `:help option-list` 9 -- To see documentation for an option, you can use `:h 'optionname'`, for example `:h 'number'` 10 -- (Note the single quotes) 11 12 -- Print the line number in front of each line 13 vim.o.number = true 14 15 -- Use relative line numbers, so that it is easier to jump with j, k. This will affect the 'number' 16 -- option above, see `:h number_relativenumber` 17 vim.o.relativenumber = true 18 19 -- Sync clipboard between OS and Neovim. Schedule the setting after `UIEnter` because it can 20 -- increase startup-time. Remove this option if you want your OS clipboard to remain independent. 21 -- See `:help 'clipboard'` 22 vim.api.nvim_create_autocmd('UIEnter', { 23 callback = function() 24 vim.o.clipboard = 'unnamedplus' 25 end, 26 }) 27 28 -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term 29 vim.o.ignorecase = true 30 vim.o.smartcase = true 31 32 -- Highlight the line where the cursor is on 33 vim.o.cursorline = true 34 35 -- Minimal number of screen lines to keep above and below the cursor. 36 vim.o.scrolloff = 10 37 38 -- Show <tab> and trailing spaces 39 vim.o.list = true 40 41 -- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), 42 -- instead raise a dialog asking if you wish to save the current file(s) See `:help 'confirm'` 43 vim.o.confirm = true 44 45 -- [[ Set up keymaps ]] See `:h vim.keymap.set()`, `:h mapping`, `:h keycodes` 46 47 -- Use <Esc> to exit terminal mode 48 vim.keymap.set('t', '<Esc>', '<C-\\><C-n>') 49 50 -- Map <A-j>, <A-k>, <A-h>, <A-l> to navigate between windows in any modes 51 vim.keymap.set({ 't', 'i' }, '<A-h>', '<C-\\><C-n><C-w>h') 52 vim.keymap.set({ 't', 'i' }, '<A-j>', '<C-\\><C-n><C-w>j') 53 vim.keymap.set({ 't', 'i' }, '<A-k>', '<C-\\><C-n><C-w>k') 54 vim.keymap.set({ 't', 'i' }, '<A-l>', '<C-\\><C-n><C-w>l') 55 vim.keymap.set({ 'n' }, '<A-h>', '<C-w>h') 56 vim.keymap.set({ 'n' }, '<A-j>', '<C-w>j') 57 vim.keymap.set({ 'n' }, '<A-k>', '<C-w>k') 58 vim.keymap.set({ 'n' }, '<A-l>', '<C-w>l') 59 60 -- [[ Basic Autocommands ]]. 61 -- See `:h lua-guide-autocommands`, `:h autocmd`, `:h nvim_create_autocmd()` 62 63 -- Highlight when yanking (copying) text. 64 -- Try it with `yap` in normal mode. See `:h vim.hl.on_yank()` 65 vim.api.nvim_create_autocmd('TextYankPost', { 66 desc = 'Highlight when yanking (copying) text', 67 callback = function() 68 vim.hl.on_yank() 69 end, 70 }) 71 72 -- [[ Create user commands ]] 73 -- See `:h nvim_create_user_command()` and `:h user-commands` 74 75 -- Create a command `:GitBlameLine` that print the git blame for the current line 76 vim.api.nvim_create_user_command('GitBlameLine', function() 77 local line_number = vim.fn.line('.') -- Get the current line number. See `:h line()` 78 local filename = vim.api.nvim_buf_get_name(0) 79 print(vim.system({ 'git', 'blame', '-L', line_number .. ',+1', filename }):wait().stdout) 80 end, { desc = 'Print the git blame for the current line' }) 81 82 -- [[ Add optional packages ]] 83 -- Nvim comes bundled with a set of packages that are not enabled by 84 -- default. You can enable any of them by using the `:packadd` command. 85 86 -- For example, to add the "nohlsearch" package to automatically turn off search highlighting after 87 -- 'updatetime' and when going to insert mode 88 vim.cmd('packadd! nohlsearch') 89 90 -- [[ Install plugins ]] 91 -- Nvim functionality can be extended by installing external plugins. 92 -- One way to do it is with a built-in plugin manager. See `:h vim.pack`. 93 vim.pack.add({ 'https://github.com/neovim/nvim-lspconfig' })