Skip to content

Commit

Permalink
Neovim: remap home to be smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce Kellogg committed Nov 25, 2024
1 parent cea63df commit 312deda
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions private_dot_config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ local function killWindow()
end


-- Helper function for a smarter <Home> key
--
-- This function compares the current cursor column
-- with the column of the first non-whitespace text.
-- If the cursor is to the right of the first non-
-- whitespace text, <Home> moves the cursor to the
-- location of the first non-whitespace text. If the
-- cursor is on or to the left of the first non-
-- whitespace text, <Home> moves the cursot to the
-- start of the line.
local function home()
local srcRow, srcCol = (table.unpack or unpack)(vim.api.nvim_win_get_cursor(0))
local txtCol = vim.api.nvim_get_current_line():find('%S') - 1
local dstRow = srcRow
local dstCol = srcCol > txtCol and txtCol or 0
vim.api.nvim_win_set_cursor(0, {dstRow,dstCol})
end


-- Key Map
--
-- First Arg: mode
Expand All @@ -210,6 +229,7 @@ mapkey({'n', 'i', 'v'}, '<M-Left>', nvim_tmux_navigation.NvimTmuxNavigateLeft)
mapkey({'n', 'i', 'v'}, '<M-Right>', nvim_tmux_navigation.NvimTmuxNavigateRight)
mapkey({'n', 'i', 'v'}, '<M-Up>', nvim_tmux_navigation.NvimTmuxNavigateUp)
mapkey({'n', 'i', 'v'}, '<M-Down>', nvim_tmux_navigation.NvimTmuxNavigateDown)
mapkey({'n', 'i', 'v'}, '<Home>', home)

-- Change how delete and cut works
--
Expand Down

0 comments on commit 312deda

Please sign in to comment.