Skip to content

Commit f6ad510

Browse files
authored
Merge pull request #17 from ntk148v/update-options
update options, mappings and more instructions for newbie
2 parents 5547113 + c5d86f6 commit f6ad510

File tree

6 files changed

+149
-90
lines changed

6 files changed

+149
-90
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,18 @@ These are the default keymaps, in the following shortcuts, the `<leader>`+` key
249249
| <kbd>kk</kbd> | Insert | Esc with `kk` |
250250
| <kbd>rr</kbd> | Normal | Reload configuration file |
251251
| <kbd>tt</kbd> | Normal | Create terminal |
252-
| `<leader>`+<kbd>s</kbd> | Normal | Save file |
253-
| `<leader>`+<kbd>q</kbd> | Normal | Save (close all windows) and exit from Neovim |
254252
| `<leader>`+<kbd>fm</kbd> | Normal | Open mini.files (Directory of the current files) |
255253
| `<leader>`+<kbd>fM</kbd> | Normal | Open mini.files (cwd) |
256-
| `<leader>`+<kbd>ff</kbd> | Normal | Open Telescope to find files |
257-
| `<leader>`+<kbd>fg</kbd> | Normal | Open Telescope to do live grep |
258-
| `<leader>`+<kbd>fb</kbd> | Normal | Open Telescope to list buffers |
259-
| `<leader>`+<kbd>fh</kbd> | Normal | Open Telescope to show help |
260-
| `<leader>`+<kbd>fo</kbd> | Normal | Open Telescope to show recent opened files |
261-
| `<leader>`+<kbd>cm</kbd> | Normal | Open Telescope to list git commits |
254+
| `<leader>`+<kbd>sh</kbd> | Normal | Open Telescope to search help |
255+
| `<leader>`+<kbd>sk</kbd> | Normal | Open Telescope to search keymaps |
256+
| `<leader>`+<kbd>sf</kbd> | Normal | Open Telescope to search files |
257+
| `<leader>`+<kbd>ss</kbd> | Normal | Open Telescope to search select telescope |
258+
| `<leader>`+<kbd>sg</kbd> | Normal | Open Telescope to search by live grep |
259+
| `<leader>`+<kbd>sd</kbd> | Normal | Open Telescope to search diagnostics |
260+
| `<leader>`+<kbd>sr</kbd> | Normal | Open Telescope to search resume |
261+
| `<leader>`+<kbd>s.</kbd> | Normal | Open Telescope to search recent files |
262+
| `<leader>`+`<leader>` | Normal | Open Telescope to search existing buffers |
263+
| `<leader>`+<kbd>sc</kbd> | Normal | Open Telescope to list git commits |
262264
| `<leader>`+<kbd>wh/j/k/l</kbd> | Normal | Move around splits |
263265
| <kbd>mm</kbd> | Normal | Comment/Uncomment line |
264266

lua/mappings.lua

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
local map = vim.keymap.set
1515
local cmd = vim.cmd
1616

17-
map("n", "<leader>q", ":qa!<CR>", {})
18-
-- Fast saving with <leader> and s
19-
map("n", "<leader>s", ":w<CR>", {})
2017
-- Move around splits
21-
map("n", "<leader>wh", "<C-w>h", { desc = "switch window left" })
22-
map("n", "<leader>wj", "<C-w>j", { desc = "switch window right" })
23-
map("n", "<leader>wk", "<C-w>k", { desc = "switch window up" })
24-
map("n", "<leader>wl", "<C-w>l", { desc = "switch window down" })
18+
map("n", "<leader>wh", "<C-w>h", { desc = "Switch [W]indow left" })
19+
map("n", "<leader>wj", "<C-w>j", { desc = "Switch [W]indow right" })
20+
map("n", "<leader>wk", "<C-w>k", { desc = "Switch [W]indow up" })
21+
map("n", "<leader>wl", "<C-w>l", { desc = "Switch [W]indow down" })
2522

2623
-- Reload configuration without restart nvim
2724
-- Or you don't want to use plenary.nvim, you can use this code
@@ -43,43 +40,67 @@ function _G.reload_config()
4340
vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO)
4441
end
4542

46-
map("n", "rr", _G.reload_config, { desc = "Reload configuration without restart nvim" })
43+
map("n", "rr", _G.reload_config, { desc = "[R]eload configuration without restart nvim" })
4744

4845
-- Telescope
4946
local builtin = require "telescope.builtin"
50-
map("n", "<leader>ff", builtin.find_files, { desc = "Open Telescope to find files" })
51-
map("n", "<leader>fg", builtin.live_grep, { desc = "Open Telescope to do live grep" })
52-
map("n", "<leader>fb", builtin.buffers, { desc = "Open Telescope to list buffers" })
53-
map("n", "<leader>fh", builtin.help_tags, { desc = "Open Telescope to show help" })
54-
map("n", "<leader>fo", builtin.oldfiles, { desc = "Open Telescope to list recent files" })
55-
map("n", "<leader>cm", builtin.git_commits, { desc = "Open Telescope to list git commits" })
47+
map('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
48+
map('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
49+
map('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
50+
map('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
51+
map('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
52+
map('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
53+
map('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
54+
map('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
55+
map("n", "<leader>sc", builtin.git_commits, { desc = "[S]earch git commits" })
56+
map('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
57+
map('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
58+
-- Slightly advanced example of overriding default behavior and theme
59+
map('n', '<leader>/', function()
60+
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
61+
builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
62+
winblend = 10,
63+
previewer = false,
64+
})
65+
end, { desc = '[/] Fuzzily search in current buffer' })
66+
67+
-- It's also possible to pass additional configuration options.
68+
-- See `:help telescope.builtin.live_grep()` for information about particular keys
69+
map('n', '<leader>s/', function()
70+
builtin.live_grep {
71+
grep_open_files = true,
72+
prompt_title = 'Live Grep in Open Files',
73+
}
74+
end, { desc = '[S]earch [/] in Open Files' })
75+
76+
-- Shortcut for searching your Neovim configuration files
77+
map('n', '<leader>sn', function()
78+
builtin.find_files { cwd = vim.fn.stdpath 'config' }
79+
end, { desc = '[S]earch [N]eovim files' })
5680

5781
-- Mini.files
5882
map(
5983
"n",
6084
"<leader>fm",
6185
function() require("mini.files").open(vim.api.nvim_buf_get_name(0), true) end,
62-
{ desc = "Open mini.files (Directory of Current File)"}
86+
{ desc = "Open [m]ini.files (Directory of Current File)" }
6387
)
6488

6589
map(
6690
"n",
6791
"<leader>fM",
6892
function() require("mini.files").open(vim.uv.cwd(), true) end,
69-
{ desc = "Open mini.files (cwd)"}
93+
{ desc = "Open [M]ini.files (cwd)" }
7094
)
7195

72-
-- LSP
96+
-- Autoformat
7397
map(
7498
"n",
75-
"<leader>gm",
99+
"<leader>l",
76100
function() require("conform").format { lsp_fallback = true } end,
77-
{ desc = "General Format file" }
101+
{ desc = "[F]ormat buffer" }
78102
)
79103

80-
-- global lsp mappings
81-
map("n", "<leader>ds", vim.diagnostic.setloclist, { desc = "LSP Diagnostic loclist" })
82-
83104
-- Comment
84105
map("n", "mm", "gcc", { desc = "Toggle comment", remap = true })
85106
map("v", "mm", "gc", { desc = "Toggle comment", remap = true })
@@ -89,3 +110,10 @@ map("n", "tt", function()
89110
local height = math.floor(vim.o.lines / 2)
90111
cmd("belowright split | resize " .. height .. " | terminal")
91112
end, { noremap = true, silent = true })
113+
114+
-- Clear highlights on search when pressing <Esc> in normal mode
115+
-- See `:help hlsearch`
116+
map('n', '<Esc>', '<cmd>nohlsearch<CR>')
117+
118+
-- Diagnostic keymaps
119+
map('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })

lua/options.lua

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,73 @@
1111
-- Author: Kien Nguyen-Tuan <kiennt2609@gmail.com>
1212
local cmd = vim.cmd
1313
-- Set options (global/buffer/windows-scoped)
14-
local opt = vim.opt
14+
local o = vim.opt
1515
-- Global variables
1616
local g = vim.g
1717
local indent = 4
1818

19+
-- Set <space> as the leader key
20+
-- See `:help mapleader`
21+
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
1922
g.mapleader = " "
23+
g.maplocalleader = " "
2024

2125
cmd [[
2226
filetype plugin indent on
2327
]]
2428

25-
opt.backspace = { "eol", "start", "indent" } -- allow backspacing over everything in insert mode
26-
opt.clipboard = "unnamedplus" -- allow neovim to access the system clipboard
27-
opt.fileencoding = "utf-8" -- the encoding written to a file
28-
opt.encoding = "utf-8" -- the encoding
29-
opt.matchpairs = { "(:)", "{:}", "[:]", "<:>" }
30-
opt.syntax = "enable"
29+
-- Sync clipboard between Neovim and the system.
30+
-- Schedule the setting after `UiEnter` because it can increase startup-time.
31+
-- Remove this option if you want your OS clipboard to remain independent.
32+
-- See `:help 'clipboard'`
33+
vim.schedule(function()
34+
vim.o.clipboard = 'unnamedplus'
35+
end)
36+
37+
-- Enable break indent
38+
o.breakindent = true
39+
40+
o.backspace = { "eol", "start", "indent" } -- allow backspacing over everything in insert mode
41+
o.fileencoding = "utf-8" -- the encoding written to a file
42+
o.encoding = "utf-8" -- the encoding
43+
o.matchpairs = { "(:)", "{:}", "[:]", "<:>" }
44+
o.syntax = "enable"
3145

3246
-- indention
33-
opt.autoindent = true -- auto indentation
34-
opt.expandtab = true -- convert tabs to spaces
35-
opt.shiftwidth = indent -- the number of spaces inserted for each indentation
36-
opt.smartindent = true -- make indenting smarter
37-
opt.softtabstop = indent -- when hitting <BS>, pretend like a tab is removed, even if spaces
38-
opt.tabstop = indent -- insert 2 spaces for a tab
39-
opt.shiftround = true -- use multiple of shiftwidth when indenting with "<" and ">"
47+
o.autoindent = true -- auto indentation
48+
o.expandtab = true -- convert tabs to spaces
49+
o.shiftwidth = indent -- the number of spaces inserted for each indentation
50+
o.smartindent = true -- make indenting smarter
51+
o.softtabstop = indent -- when hitting <BS>, pretend like a tab is removed, even if spaces
52+
o.tabstop = indent -- insert 2 spaces for a tab
53+
o.shiftround = true -- use multiple of shiftwidth when indenting with "<" and ">"
4054

4155
-- tabline
42-
opt.showtabline = 2 -- always show tabs
43-
opt.sessionoptions = "curdir,folds,globals,help,tabpages,terminal,winsize"
56+
o.showtabline = 2 -- always show tabs
57+
o.sessionoptions = "curdir,folds,globals,help,tabpages,terminal,winsize"
4458
-- search
45-
opt.hlsearch = true -- highlight all matches on previous search pattern
46-
opt.ignorecase = true -- ignore case in search patterns
47-
opt.smartcase = true -- smart case
48-
opt.wildignore = opt.wildignore + { "*/node_modules/*", "*/.git/*", "*/vendor/*" }
49-
opt.wildmenu = true -- make tab completion for files/buffers act like bash
59+
o.hlsearch = true -- highlight all matches on previous search pattern
60+
o.ignorecase = true -- ignore case in search patterns unless \C or one or more capital letters in the search term
61+
o.smartcase = true -- smart case
62+
o.wildignore = o.wildignore + { "*/node_modules/*", "*/.git/*", "*/vendor/*" }
63+
o.wildmenu = true -- make tab completion for files/buffers act like bash
64+
o.inccommand = 'split' -- review substitutions live, as you type
5065

5166
-- ui
52-
opt.cursorline = true -- highlight the current line
53-
opt.laststatus = 2 -- only the last window will always have a status line
54-
opt.lazyredraw = true -- don"t update the display while executing macros
55-
opt.list = true
67+
o.cursorline = true -- highlight the current line
68+
o.laststatus = 2 -- only the last window will always have a status line
69+
o.lazyredraw = true -- don"t update the display while executing macros
70+
-- Sets how neovim will display certain whitespace characters in the editor.
71+
-- See `:help 'list'`
72+
-- and `:help 'listchars'`
73+
--
74+
-- Notice listchars is set using `vim.opt` instead of `vim.o`.
75+
-- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables.
76+
-- See `:help lua-options`
77+
-- and `:help lua-options-guide`
78+
o.list = true
5679
-- You can also add "space" or "eol", but I feel it"s quite annoying
57-
opt.listchars = {
80+
o.listchars = {
5881
tab = "",
5982
trail = "·",
6083
extends = "»",
@@ -63,53 +86,59 @@ opt.listchars = {
6386
}
6487

6588
-- Hide cmd line
66-
opt.cmdheight = 0 -- more space in the neovim command line for displaying messages
67-
68-
opt.mouse = "a" -- allow the mouse to be used in neovim
69-
opt.number = true -- set numbered lines
70-
opt.scrolloff = 18 -- minimal number of screen lines to keep above and below the cursor
71-
opt.sidescrolloff = 3 -- minimal number of screen columns to keep to the left and right (horizontal) of the cursor if wrap is `false`
72-
opt.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time
73-
opt.splitbelow = true -- open new split below
74-
opt.splitright = true -- open new split to the right
75-
opt.wrap = true -- display a wrapped line
89+
o.cmdheight = 0 -- more space in the neovim command line for displaying messages
90+
91+
o.mouse = "a" -- allow the mouse to be used in neovim
92+
o.number = true -- set numbered lines
93+
-- opt.relativenumber = true -- set relative numbered lines, to help with jumping.
94+
o.scrolloff = 18 -- minimal number of screen lines to keep above and below the cursor
95+
o.sidescrolloff = 3 -- minimal number of screen columns to keep to the left and right (horizontal) of the cursor if wrap is `false`
96+
o.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time
97+
o.splitbelow = true -- open new split below
98+
o.splitright = true -- open new split to the right
99+
o.wrap = true -- display a wrapped line
100+
101+
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
102+
-- instead raise a dialog asking if you wish to save the current file(s)
103+
-- See `:help 'confirm'`
104+
o.confirm = true
76105

77106
-- backups
78-
opt.backup = false -- create a backup file
79-
opt.swapfile = false -- creates a swapfile
80-
opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
107+
o.backup = false -- create a backup file
108+
o.swapfile = false -- creates a swapfile
109+
o.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
81110

82111
-- autocomplete
83-
opt.completeopt = { "menu", "menuone", "noselect" } -- mostly just for cmp
84-
opt.shortmess = opt.shortmess + {
112+
o.completeopt = { "menu", "menuone", "noselect" } -- mostly just for cmp
113+
o.shortmess = o.shortmess + {
85114
c = true,
86115
} -- hide all the completion messages, e.g. "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found"
87116

88117
-- By the way, -- INSERT -- is unnecessary anymore because the mode information is displayed in the statusline.
89-
opt.showmode = false
118+
o.showmode = false
90119

91120
-- perfomance
92121
-- remember N lines in history
93-
opt.history = 100 -- keep 100 lines of history
94-
opt.redrawtime = 1500
95-
opt.timeoutlen = 250 -- time to wait for a mapped sequence to complete (in milliseconds)
96-
opt.ttimeoutlen = 10
97-
opt.updatetime = 100 -- signify default updatetime 4000ms is not good for async update
122+
o.history = 100 -- keep 100 lines of history
123+
o.redrawtime = 1500
124+
o.timeoutlen = 250 -- time to wait for a mapped sequence to complete (in milliseconds)
125+
o.ttimeoutlen = 10
126+
o.updatetime = 100 -- signify default updatetime 4000ms is not good for async update
98127

99128
-- theme
100-
opt.termguicolors = true -- enable 24-bit RGB colors
129+
o.termguicolors = true -- enable 24-bit RGB colors
101130

102131
-- persistent undo
103132
-- Don"t forget to create folder $HOME/.local/share/nvim/undo
104133
local undodir = vim.fn.stdpath "data" .. "/undo"
105-
opt.undofile = true -- enable persistent undo
106-
opt.undodir = undodir
107-
opt.undolevels = 1000
108-
opt.undoreload = 10000
134+
o.undofile = true -- enable persistent undo
135+
o.undodir = undodir
136+
o.undolevels = 1000
137+
o.undoreload = 10000
109138

110139
-- fold
111-
opt.foldmethod = "marker"
112-
opt.foldlevel = 99
140+
o.foldmethod = "marker"
141+
o.foldlevel = 99
113142

114143
-- Disable builtin plugins
115144
local disabled_built_ins = {

lua/plugins/configs/cmp.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require("nvim-autopairs").setup {
1616
ts_config = {
1717
lua = { "string" }, -- it will not add a pair on that treesitter node
1818
javascript = { "template_string" },
19-
java = false, -- Don't check treesitter on java
19+
java = false, -- Don't check treesitter on java
2020
},
2121

2222
-- Don't add pairs if it already has a close pair in the same line

lua/plugins/configs/gitsigns.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ return {
2727
},
2828
},
2929
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
30-
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
31-
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
30+
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
31+
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
3232
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
3333
watch_gitdir = {
3434
interval = 1000,

lua/plugins/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local builtin_plugins = {
2222
require("mini.files").setup(opts)
2323

2424
local show_dotfiles = true
25-
local filter_show = function(fs_entry) return true end
25+
local filter_show = function(_) return true end
2626
local filter_hide = function(fs_entry) return not vim.startswith(fs_entry.name, ".") end
2727

2828
local toggle_dotfiles = function()
@@ -226,7 +226,7 @@ local builtin_plugins = {
226226
{ "zbirenbaum/copilot.lua" },
227227
{ "nvim-lua/plenary.nvim", branch = "master" }, -- for curl, log and async functions
228228
},
229-
build = "make tiktoken", -- Only on MacOS or Linux
229+
build = "make tiktoken", -- Only on MacOS or Linux
230230
opts = {
231231
-- See Configuration section for options
232232
model = "claude-3.5-sonnet",
@@ -260,7 +260,7 @@ require("lazy").setup {
260260
spec = { builtin_plugins, custom_plugins },
261261
lockfile = vim.fn.stdpath "config" .. "/lazy-lock.json", -- lockfile generated after running update.
262262
defaults = {
263-
lazy = false, -- should plugins be lazy-loaded?
263+
lazy = false, -- should plugins be lazy-loaded?
264264
version = nil,
265265
-- version = "*", -- enable this to try installing the latest stable versions of plugins
266266
},

0 commit comments

Comments
 (0)