diff --git a/README.md b/README.md index 3b21fd2..bfae2e1 100644 --- a/README.md +++ b/README.md @@ -391,18 +391,14 @@ set statusline=%!v:lua.statusline() " Also works in expression mappings lua << EOF function _G.check_back_space() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end + local col = vim.api.nvim_win_get_cursor(0)[2] + return (col == 0 or vim.api.nvim_get_current_line():sub(col, col):match('%s')) and true end EOF inoremap - \ pumvisible() ? '\' : - \ v:lua.check_back_space() ? '\' : + \ pumvisible() ? "\" : + \ v:lua.check_back_space() ? "\" : \ completion#trigger_completion() ``` diff --git a/doc/nvim-lua-guide.txt b/doc/nvim-lua-guide.txt index e21c77f..3c8db4d 100644 --- a/doc/nvim-lua-guide.txt +++ b/doc/nvim-lua-guide.txt @@ -414,18 +414,15 @@ types and vice versa. " Also works in expression mappings lua << EOF function _G.check_back_space() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end + local col = vim.api.nvim_win_get_cursor(0)[2] + return (col == 0 or vim.api.nvim_get_current_line():sub(col, + col):match('%s')) and true end EOF inoremap - \ pumvisible() ? '\' : - \ v:lua.check_back_space() ? '\' : + \ pumvisible() ? "\" : + \ v:lua.check_back_space() ? "\" : \ completion#trigger_completion() <